Added the command/irc.py directory that was not committed properly.

Added some more helper commands and changed a bit under the hood on those
previously committed for mapping irc/imc channels to each other.

There seems to be an issue with IMC2 users seeing an echo back to themselves when talking. Investigating.
/Griatch
This commit is contained in:
Griatch 2009-08-28 18:13:07 +00:00
parent 5f58c4384b
commit 72e55f417a
3 changed files with 314 additions and 212 deletions

View file

@ -122,7 +122,7 @@ GLOBAL_CMD_TABLE.add_command("imcstatus", cmd_imcstatus)
def cmd_IMC2chan(command): def cmd_IMC2chan(command):
""" """
@imc2chan IMCchannel channel @imc2chan IMCServer:IMCchannel channel
Links an IMC channel to an existing Links an IMC channel to an existing
evennia channel. You can link as many existing evennia channel. You can link as many existing
@ -130,7 +130,8 @@ def cmd_IMC2chan(command):
IMC channel this way. Running the command with an IMC channel this way. Running the command with an
existing mapping will re-map the channels. existing mapping will re-map the channels.
Use 'imcchanlist' to get a list of IMC channels. Use 'imcchanlist' to get a list of IMC channels and servers.
Note that both are case sensitive.
""" """
source_object = command.source_object source_object = command.source_object
if not settings.IMC2_ENABLED: if not settings.IMC2_ENABLED:
@ -139,16 +140,22 @@ def cmd_IMC2chan(command):
return return
args = command.command_argument args = command.command_argument
if not args or len(args.split()) != 2 : if not args or len(args.split()) != 2 :
source_object.emit_to("Usage: @imc2chan IMCchannel channel") source_object.emit_to("Usage: @imc2chan IMCServer:IMCchannel channel")
return
#identify the server-channel pair
imcdata, channel = args.split()
if not ":" in imcdata:
source_object.emit_to("You need to supply an IMC Server:Channel pair.")
return return
imc_channel, channel = args.split()
imclist = IMC2_CHANLIST.get_channel_list() imclist = IMC2_CHANLIST.get_channel_list()
if imc_channel not in [c.localname for c in imclist]: imc_channels = filter(lambda c: c.name == imcdata, imclist)
source_object.emit_to("IMC channel '%s' not found." % imc_channel) if not imc_channels:
source_object.emit_to("IMC server and channel '%s' not found." % imcdata)
return return
else: else:
imc_channel = filter(lambda c: c.localname==imc_channel,imclist) imc_server_name, imc_channel_name = imcdata.split(":")
if imc_channel: imc_channel = imc_channel[0]
#find evennia channel
try: try:
chanobj = comsys.get_cobj_from_name(channel) chanobj = comsys.get_cobj_from_name(channel)
except CommChannel.DoesNotExist: except CommChannel.DoesNotExist:
@ -164,10 +171,8 @@ def cmd_IMC2chan(command):
else: else:
mapping = IMC2ChannelMapping() mapping = IMC2ChannelMapping()
server,name = imc_channel.name.split(":") mapping.imc2_server_name = imc_server_name
mapping.imc2_channel_name = imc_channel_name
mapping.imc2_server_name = server.strip() #settings.IMC2_SERVER_ADDRESS
mapping.imc2_channel_name = name.strip() #imc_channel.name
mapping.channel = chanobj mapping.channel = chanobj
mapping.save() mapping.save()
outstring += "Mapping set: %s." % mapping outstring += "Mapping set: %s." % mapping

97
src/commands/irc.py Normal file
View file

@ -0,0 +1,97 @@
"""
IRC-related functions
"""
from django.conf import settings
from src.irc.connection import IRC_CHANNELS
from src.irc.connection import connect_to_IRC
from src.irc.models import IRCChannelMapping
from src import comsys
from src.cmdtable import GLOBAL_CMD_TABLE
def cmd_IRC2chan(command):
"""
@irc2chan IRCchannel channel
Links an IRC channel (including #) to an existing
evennia channel. You can link as many existing
evennia channels as you like to the
IRC channel this way. Running the command with an
existing mapping will re-map the channels.
"""
source_object = command.source_object
if not settings.IRC_ENABLED:
s = """IRC is not enabled. You need to activate it in game/settings.py."""
source_object.emit_to(s)
return
args = command.command_argument
if not args or len(args.split()) != 2 :
source_object.emit_to("Usage: @irc2chan IRCchannel channel")
return
irc_channel, channel = args.split()
if irc_channel not in [o.factory.channel for o in IRC_CHANNELS]:
source_object.emit_to("IRC channel '%s' not found." % irc_channel)
return
try:
chanobj = comsys.get_cobj_from_name(channel)
except CommChannel.DoesNotExist:
source_object.emit_to("Local channel '%s' not found (use real name, not alias)." % channel)
return
#create the mapping.
outstring = ""
mapping = IRCChannelMapping.objects.filter(channel__name=channel)
if mapping:
mapping = mapping[0]
outstring = "Replacing %s. New " % mapping
else:
mapping = IRCChannelMapping()
mapping.irc_server_name = settings.IRC_NETWORK
mapping.irc_channel_name = irc_channel
mapping.channel = chanobj
mapping.save()
outstring += "Mapping set: %s." % mapping
source_object.emit_to(outstring)
GLOBAL_CMD_TABLE.add_command("@irc2chan",cmd_IRC2chan,auto_help=True,staff_help=True,
priv_tuple=("objects.add_commchannel",))
def cmd_IRCjoin(command):
"""
@ircjoin IRCchannel
Attempts to connect a bot to a new IRC channel (don't forget that
IRC channels begin with a #).
The bot uses the connection details defined in the main settings.
Observe that channels added using this command does not survive a reboot.
"""
source_object = command.source_object
arg = command.command_argument
if not arg:
source_object.emit_to("Usage: @ircjoin irc_channel")
return
channel = arg.strip()
if channel[0] != "#": channel = "#%s" % channel
connect_to_IRC(settings.IRC_NETWORK,
settings.IRC_PORT,
channel,settings.IRC_NICKNAME)
GLOBAL_CMD_TABLE.add_command("@ircjoin",cmd_IRCjoin,auto_help=True,
staff_help=True,
priv_tuple=("objects.add_commchannel",))
def cmd_IRCchanlist(command):
"""
ircchanlist
Lists all externally available IRC channels.
"""
source_object = command.source_object
s = "Available IRC channels:"
for c in IRC_CHANNELS:
s += "\n %s \t(nick '%s') on %s" % (c.factory.channel,c.factory.nickname,c.factory.network,)
source_object.emit_to(s)
GLOBAL_CMD_TABLE.add_command("ircchanlist", cmd_IRCchanlist, auto_help=True)

View file

@ -24,7 +24,7 @@ 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) comsys.send_cmessage(settings.COMMCHAN_IMC2_INFO, 'IMC: %s' % message,from_external="IMC2")
class IMC2Protocol(StatefulTelnetProtocol): class IMC2Protocol(StatefulTelnetProtocol):
""" """