Cleaned spammy output to IMC users from IRC and evennia channels, where channel names tended to be added

after one another several times. IMC is not seeing the IRC channel name anymore, output should be on the standard
simple name@MUD: msg format as far as IMC is concerned.
/Griatch
This commit is contained in:
Griatch 2009-09-05 07:24:04 +00:00
parent eebfa0d387
commit 5e8a047111
5 changed files with 52 additions and 20 deletions

View file

@ -402,7 +402,7 @@ def cmd_cemit(command):
else: else:
if "sendername" in command.command_switches: if "sendername" in command.command_switches:
if not comsys.plr_has_channel(command.session, cname_parsed, if not comsys.plr_has_channel(command.session, cname_parsed,
return_muted=False): return_muted=False):
source_object.emit_to("You must be on %s to do that." % (cname_parsed,)) source_object.emit_to("You must be on %s to do that." % (cname_parsed,))
return return
final_cmessage = "%s: %s" % (source_object.get_name(show_dbref=False), final_cmessage = "%s: %s" % (source_object.get_name(show_dbref=False),
@ -419,7 +419,7 @@ def cmd_cemit(command):
show_header=show_channel_header) show_header=show_channel_header)
#pipe to external channels (IRC, IMC) eventually mapped to this channel #pipe to external channels (IRC, IMC) eventually mapped to this channel
comsys.send_cexternal(cname_parsed, "[%s] %s" % (cname_parsed,final_cmessage)) comsys.send_cexternal(cname_parsed, cmessage, caller=source_object)
GLOBAL_CMD_TABLE.add_command("@cemit", cmd_cemit), GLOBAL_CMD_TABLE.add_command("@cemit", cmd_cemit),

View file

@ -257,20 +257,22 @@ def send_cmessage(channel, message, show_header=True, from_external=None):
# the channel. # the channel.
channel_obj = channel channel_obj = channel
final_message = message
if show_header == True: if show_header == True:
message = "%s %s" % (channel_obj.ansi_name, message) final_message = "%s %s" % (channel_obj.ansi_name, message)
for user in get_cwho_list(channel_obj.name, return_muted=False): for user in get_cwho_list(channel_obj.name, return_muted=False):
user.msg(message) user.msg(final_message)
chan_message = CommChannelMessage() chan_message = CommChannelMessage()
chan_message.channel = channel_obj chan_message.channel = channel_obj
chan_message.message = message chan_message.message = final_message
chan_message.save() chan_message.save()
#pipe to external protocols #pipe to external protocols
if from_external: if from_external:
send_cexternal(channel_obj.name, message, from_external) send_cexternal(channel_obj.name, message,
from_external=from_external)
def get_all_channels(): def get_all_channels():
""" """
@ -315,7 +317,7 @@ def cemit_mudinfo(message):
send_cmessage(settings.COMMCHAN_MUD_INFO, send_cmessage(settings.COMMCHAN_MUD_INFO,
'Info: %s' % message) 'Info: %s' % message)
def send_cexternal(cname, cmessage, from_external=None): def send_cexternal(cname, cmessage, caller=None, from_external=None):
""" """
This allows external protocols like IRC and IMC to send to a channel This allows external protocols like IRC and IMC to send to a channel
while also echoing to each other. This used by channel-emit functions while also echoing to each other. This used by channel-emit functions
@ -323,38 +325,60 @@ def send_cexternal(cname, cmessage, from_external=None):
cname - name of evennia channel sent to cname - name of evennia channel sent to
cmessage - message sent (should be pre-formatted already) cmessage - message sent (should be pre-formatted already)
caller - a player object sending the message (not present for IRC<->IMC comms)
from_external - which protocol sent the emit. from_external - which protocol sent the emit.
Currently supports 'IRC' and 'IMC2' or None Currently supports 'IRC' and 'IMC2' or None
(this avoids emits echoing back to themselves). If (this avoids emits echoing back to themselves). If
None, it is assumed the message comes from within Evennia None, it is assumed the message comes from within Evennia
and all mapped external channels will be notified. and all mapped external channels will be notified.
""" """
if settings.IMC2_ENABLED and from_external != "IMC2": if settings.IMC2_ENABLED and from_external != "IMC2":
#map an IRC emit to the IMC network #map a non-IMC emit to the IMC network
# Look for IMC2 channel maps. If one is found, send an ice-msg-b # Look for IMC2 channel maps. If one is found, send an ice-msg-b
# packet to the network. # packet to the network.
#handle lack of user, IMC-way. print "caller found: %s (%s). Msg: %s" % (caller,from_external,cmessage)
imccaller = caller
imccmessage = cmessage
if not caller:
if from_external in ['IRC']:
#try to guess the caller's name from the message
#always on form name@#channel: msg
imccaller, imccmessage = cmessage.split("@",1)
#throw away IRC channel name; IMC users need not know it
imccmessage = (imccmessage.split(":",1)[1]).strip()
print "caller: %s cmessage: %s" % (imccaller, imccmessage)
else:
imccaller = "*"
try: try:
from src.imc2.connection import IMC2_PROTOCOL_INSTANCE from src.imc2.connection import IMC2_PROTOCOL_INSTANCE
map = IMC2ChannelMapping.objects.get(channel__name=cname) map = IMC2ChannelMapping.objects.get(channel__name=cname)
packet = IMC2PacketIceMsgBroadcasted(map.imc2_server_name, packet = IMC2PacketIceMsgBroadcasted(map.imc2_server_name,
map.imc2_channel_name, map.imc2_channel_name,
"*", imccaller,
cmessage) imccmessage)
IMC2_PROTOCOL_INSTANCE.send_packet(packet) IMC2_PROTOCOL_INSTANCE.send_packet(packet)
except IMC2ChannelMapping.DoesNotExist: except IMC2ChannelMapping.DoesNotExist:
# No map found, do nothing. # No map found, do nothing.
pass pass
if settings.IRC_ENABLED and from_external != "IRC": if settings.IRC_ENABLED and from_external != "IRC":
# Map an IMC emit to IRC channels # Map a non-IRC emit to IRC channels
# Look for IRC channel maps. If found, echo cmessage to the # Look for IRC channel maps. If found, echo cmessage to the
# IRC channel. # IRC channel.
if caller:
#message comes from a local channel
caller = caller.get_name(show_dbref=False)
cmessage = "[%s] %s: %s" % (cname, caller, cmessage)
else:
#message from IMC2; name is part of cmessage
cmessage = "[%s] %s" % (cname, cmessage)
try: try:
#this fails with a DoesNotExist if the channel is not mapped. #this fails with a DoesNotExist if the channel is not mapped.
from src.irc.connection import IRC_CHANNELS from src.irc.connection import IRC_CHANNELS

View file

@ -24,7 +24,8 @@ def cemit_info(message):
Channel emits info to the appropriate info channel. By default, this Channel emits info to the appropriate info channel. By default, this
is MUDInfo. is MUDInfo.
""" """
comsys.send_cmessage(settings.COMMCHAN_IMC2_INFO, 'IMC: %s' % message,from_external="IMC2") comsys.send_cmessage(settings.COMMCHAN_IMC2_INFO, 'IMC: %s' % message,
from_external="IMC2")
class IMC2Protocol(StatefulTelnetProtocol): class IMC2Protocol(StatefulTelnetProtocol):
""" """

View file

@ -139,7 +139,10 @@ class IMC2Packet(object):
return '*' return '*'
elif str(self.sender).isdigit(): elif str(self.sender).isdigit():
return self.sender return self.sender
elif self.sender: elif type(self.sender) in [type(u""),type(str())]:
#this is used by e.g. IRC where no user object is present.
return self.sender.strip().replace(' ', '_')
elif self.sender:
# Player object. # Player object.
name = self.sender.get_name(fullname=False, show_dbref=False, name = self.sender.get_name(fullname=False, show_dbref=False,
show_flags=False, show_flags=False,

View file

@ -19,7 +19,7 @@ def cemit_info(message):
""" """
Send info to default info channel Send info to default info channel
""" """
comsys.send_cmessage(settings.COMMCHAN_IRC_INFO, 'IRC: %s' % message,from_external="IRC") comsys.send_cmessage(settings.COMMCHAN_IRC_INFO, 'IRC: %s' % message)
class IRC_Bot(irc.IRCClient): class IRC_Bot(irc.IRCClient):
@ -55,7 +55,10 @@ class IRC_Bot(irc.IRCClient):
user = user.split("!")[0] user = user.split("!")[0]
if user: if user:
user.strip() user.strip()
msg = "%s@%s: %s" % (user,irc_channel,msg) else:
user = "Unknown"
msg = "%s@%s: %s" % (user,irc_channel,msg.strip())
#logger.log_infomsg("<IRC: " + msg) #logger.log_infomsg("<IRC: " + msg)
for mapping in mappings: for mapping in mappings:
@ -71,6 +74,7 @@ class IRC_Bot(irc.IRCClient):
self.msg(self.factory.channel, msg) self.msg(self.factory.channel, msg)
#logger.log_infomsg(">IRC: " + msg) #logger.log_infomsg(">IRC: " + msg)
class IRC_BotFactory(protocol.ClientFactory): class IRC_BotFactory(protocol.ClientFactory):
protocol = IRC_Bot protocol = IRC_Bot
def __init__(self, channel, network, nickname): def __init__(self, channel, network, nickname):