diff --git a/src/commands/irc.py b/src/commands/irc.py index 191b63c5c9..99a63459f0 100644 --- a/src/commands/irc.py +++ b/src/commands/irc.py @@ -1,10 +1,9 @@ """ IRC-related commands """ - +from twisted.application import internet 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 @@ -69,17 +68,37 @@ def cmd_IRCjoin(command): 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") + source_object.emit_to("Usage: @ircjoin #irc_channel") return channel = arg.strip() if channel[0] != "#": channel = "#%s" % channel - + + if not settings.IRC_ENABLED: + source_object.emit_to("IRC services are not active. You need to turn them on in preferences.") + return + + #direct creation of bot (do not add to services) + from src.irc.connection import connect_to_IRC connect_to_IRC(settings.IRC_NETWORK, settings.IRC_PORT, - channel,settings.IRC_NICKNAME) + channel, settings.IRC_NICKNAME) + +# ---below should be checked so as to add subequent IRC bots to Services. +# it adds just fine, but the bot does not connect. /Griatch +# from src.irc.connection import IRC_BotFactory +# from src.server import mud_service +# irc = internet.TCPClient(settings.IRC_NETWORK, +# settings.IRC_PORT, +# IRC_BotFactory(channel, +# settings.IRC_NETWORK, +# settings.IRC_NICKNAME)) +# irc.setName("%s:%s" % ("IRC",channel)) +# irc.setServiceParent(mud_service.service_collection) + GLOBAL_CMD_TABLE.add_command("@ircjoin",cmd_IRCjoin,auto_help=True, staff_help=True, priv_tuple=("objects.add_commchannel",)) diff --git a/src/commands/privileged.py b/src/commands/privileged.py index f9243d4c51..b828ee1eb9 100644 --- a/src/commands/privileged.py +++ b/src/commands/privileged.py @@ -177,7 +177,7 @@ def cmd_service(command): source_object = command.source_object switches = command.command_switches if not switches or switches[0] not in ["list","start","stop"]: - source_object.emit_to("Usage @servive/ [service]") + source_object.emit_to("Usage: @servive/ [service]") return switch = switches[0].strip() sname = source_object.get_name(show_dbref=False) diff --git a/src/irc/connection.py b/src/irc/connection.py index 32c97d73aa..98325a2358 100644 --- a/src/irc/connection.py +++ b/src/irc/connection.py @@ -77,9 +77,13 @@ class IRC_BotFactory(protocol.ClientFactory): self.network = network self.channel = channel self.nickname = nickname - def clientConnectionLost(self, connector, reason): - cemit_info("Lost connection (%s), reconnecting." % reason) - connector.connect() + def clientConnectionLost(self, connector, reason): + from twisted.internet.error import ConnectionDone + if type(reason.type) == type(ConnectionDone): + cemit_info("Connection closed.") + else: + cemit_info("Lost connection (%s), reconnecting." % reason) + connector.connect() def clientConnectionFailed(self, connector, reason): msg = "Could not connect: %s" % reason cemit_info(msg) diff --git a/src/server.py b/src/server.py index 2695afe858..6f264bb807 100755 --- a/src/server.py +++ b/src/server.py @@ -159,13 +159,14 @@ class EvenniaService(service.Service): imc2_events.add_events() if settings.IRC_ENABLED: - #Connect to the IRC network. - from src.irc.connection import connect_to_IRC - connect_to_IRC(settings.IRC_NETWORK, - settings.IRC_PORT, - settings.IRC_CHANNEL, - settings.IRC_NICKNAME) - + from src.irc.connection import IRC_BotFactory + irc = internet.TCPClient(settings.IRC_NETWORK, + settings.IRC_PORT, + IRC_BotFactory(settings.IRC_CHANNEL, + settings.IRC_NETWORK, + settings.IRC_NICKNAME)) + irc.setName("%s:%s" % ("IRC",settings.IRC_CHANNEL)) + irc.setServiceParent(self.service_collection) application = service.Application('Evennia') mud_service = EvenniaService()