mirror of
https://github.com/evennia/evennia.git
synced 2026-04-03 06:27:17 +02:00
Registering IRC as an Evennia Service, can now be controlled with @service/start/stop.
At the moment this only works with the initial IRC channel (the one set in preferences), those channels you add later with @ircjoin does not add as Services; when setting it up they add just fine, but the bot does not connect - I don't know why (code is commented out in src/commands/irc.py). /Griatch
This commit is contained in:
parent
cb7ee081f5
commit
c5c8505582
4 changed files with 40 additions and 16 deletions
|
|
@ -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",))
|
||||
|
|
|
|||
|
|
@ -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/<start|stop|list> [service]")
|
||||
source_object.emit_to("Usage: @servive/<start|stop|list> [service]")
|
||||
return
|
||||
switch = switches[0].strip()
|
||||
sname = source_object.get_name(show_dbref=False)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue