Added #1 to default channels. Had IRC log to a default channel. Added some more feedback upon module import failures.

This commit is contained in:
Griatch 2009-08-29 10:36:00 +00:00
parent 929786638d
commit 5a3d901b5c
4 changed files with 33 additions and 20 deletions

View file

@ -74,10 +74,10 @@ Your names of various default comm channels for emitting
debug- or informative messages.
"""
COMMCHAN_IMC2_INFO = 'MUDInfo'
COMMCHAN_MUD_INFO = 'MUDInfo'
COMMCHAN_MUD_CONNECTIONS = 'MUDConnections'
COMMCHAN_IMC2_INFO = 'MUDInfo'
COMMCHAN_IRC_INFO = 'MUDInfo'
"""
IMC Configuration

View file

@ -71,10 +71,14 @@ def create_channels():
description="Public Discussion")
chan_pub.is_joined_by_default = True
chan_pub.save()
comsys.create_channel(settings.COMMCHAN_MUD_INFO, god_user_obj,
description="Informative messages")
comsys.create_channel(settings.COMMCHAN_MUD_CONNECTIONS, god_user_obj,
description="Connection log")
chan_info = comsys.create_channel(settings.COMMCHAN_MUD_INFO, god_user_obj,
description="Informative messages")
chan_conn = comsys.create_channel(settings.COMMCHAN_MUD_CONNECTIONS, god_user_obj,
description="Connection log")
#add god user to default channels.
comsys.plr_add_channel(god_user_obj, "pub", chan_pub)
comsys.plr_add_channel(god_user_obj, "info", chan_info)
comsys.plr_add_channel(god_user_obj, "conn", chan_conn)
def create_config_values():
"""

View file

@ -7,6 +7,7 @@ more Evennia channels.
from twisted.words.protocols import irc
from twisted.internet import protocol
from twisted.internet import reactor
from django.conf import settings
from src.irc.models import IRCChannelMapping
from src import comsys
from src import logger
@ -14,6 +15,12 @@ from src import logger
#store all irc channels
IRC_CHANNELS = []
def cemit_info(message):
"""
Send info to default info channel
"""
comsys.send_cmessage(settings.COMMCHAN_IRC_INFO, 'IRC: %s' % message,from_external="IRC")
class IRC_Bot(irc.IRCClient):
def _get_nickname(self):
@ -28,17 +35,17 @@ class IRC_Bot(irc.IRCClient):
# This is the first point the protocol is instantiated.
# add this protocol instance to the global list so we
# can access it later to send data.
IRC_CHANNELS.append(self)
logger.log_infomsg("IRC: Client connecting to %s.'" % (self.factory.channel))
IRC_CHANNELS.append(self)
cemit_info("Client connecting to %s.'" % (self.factory.channel))
def joined(self, channel):
logger.log_infomsg("Joined %s/%s as '%s'." % (self.factory.network,channel,self.factory.nickname))
msg = "Joined %s/%s as '%s'." % (self.factory.network,channel,self.factory.nickname)
cemit_info(msg)
logger.log_infomsg(msg)
def privmsg(self, user, irc_channel, msg):
"Someone has written something in channel. Echo it to the evennia channel"
print "got msg: %s" % msg
try:
#find irc->evennia channel mappings
mappings = IRCChannelMapping.objects.filter(irc_channel_name=irc_channel)
@ -49,12 +56,12 @@ class IRC_Bot(irc.IRCClient):
if user:
user.strip()
msg = "%s@%s: %s" % (user,irc_channel,msg)
logger.log_infomsg("<IRC: " + msg)
#logger.log_infomsg("<IRC: " + msg)
for mapping in mappings:
if mapping.channel:
comsys.send_cmessage(mapping.channel, msg, from_external="IRC")
except IRCChannelMapping.DoesNotExist:
#no mappings found. Ignore.
pass
@ -62,7 +69,7 @@ class IRC_Bot(irc.IRCClient):
def send_msg(self,msg):
"Called by evennia when sending something to mapped IRC channel"
self.msg(self.factory.channel, msg)
logger.log_infomsg(">IRC: " + msg)
#logger.log_infomsg(">IRC: " + msg)
class IRC_BotFactory(protocol.ClientFactory):
protocol = IRC_Bot
@ -71,11 +78,13 @@ class IRC_BotFactory(protocol.ClientFactory):
self.channel = channel
self.nickname = nickname
def clientConnectionLost(self, connector, reason):
logger.log_errmsg("IRC: Lost connection (%s), reconnecting." % reason)
cemit_info("Lost connection (%s), reconnecting." % reason)
connector.connect()
def clientConnectionFailed(self, connector, reason):
logger.log_errmsg("IRC: Could not connect: %s" % reason)
msg = "Could not connect: %s" % reason
cemit_info(msg)
logger.log_errmsg(msg)
def connect_to_IRC(irc_network,irc_port,irc_channel,irc_bot_nick ):
"Create the bot instance and connect to the IRC network and channel."
connect = reactor.connectTCP(irc_network, irc_port,

View file

@ -90,8 +90,8 @@ class EvenniaService(service.Service):
for cmd_mod in cmd_modules:
try:
__import__(cmd_mod)
except ImportError:
logger.log_errmsg("ERROR: Unable to load command module: %s" % cmd_mod)
except ImportError, e:
logger.log_errmsg("ERROR: Unable to load command module: %s (%s)" % (cmd_mod, e))
continue
"""