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:
parent
929786638d
commit
5a3d901b5c
4 changed files with 33 additions and 20 deletions
|
|
@ -74,10 +74,10 @@ Your names of various default comm channels for emitting
|
||||||
debug- or informative messages.
|
debug- or informative messages.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
COMMCHAN_IMC2_INFO = 'MUDInfo'
|
|
||||||
COMMCHAN_MUD_INFO = 'MUDInfo'
|
COMMCHAN_MUD_INFO = 'MUDInfo'
|
||||||
COMMCHAN_MUD_CONNECTIONS = 'MUDConnections'
|
COMMCHAN_MUD_CONNECTIONS = 'MUDConnections'
|
||||||
|
COMMCHAN_IMC2_INFO = 'MUDInfo'
|
||||||
|
COMMCHAN_IRC_INFO = 'MUDInfo'
|
||||||
|
|
||||||
"""
|
"""
|
||||||
IMC Configuration
|
IMC Configuration
|
||||||
|
|
|
||||||
|
|
@ -71,10 +71,14 @@ def create_channels():
|
||||||
description="Public Discussion")
|
description="Public Discussion")
|
||||||
chan_pub.is_joined_by_default = True
|
chan_pub.is_joined_by_default = True
|
||||||
chan_pub.save()
|
chan_pub.save()
|
||||||
comsys.create_channel(settings.COMMCHAN_MUD_INFO, god_user_obj,
|
chan_info = comsys.create_channel(settings.COMMCHAN_MUD_INFO, god_user_obj,
|
||||||
description="Informative messages")
|
description="Informative messages")
|
||||||
comsys.create_channel(settings.COMMCHAN_MUD_CONNECTIONS, god_user_obj,
|
chan_conn = comsys.create_channel(settings.COMMCHAN_MUD_CONNECTIONS, god_user_obj,
|
||||||
description="Connection log")
|
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():
|
def create_config_values():
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ more Evennia channels.
|
||||||
from twisted.words.protocols import irc
|
from twisted.words.protocols import irc
|
||||||
from twisted.internet import protocol
|
from twisted.internet import protocol
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
|
from django.conf import settings
|
||||||
from src.irc.models import IRCChannelMapping
|
from src.irc.models import IRCChannelMapping
|
||||||
from src import comsys
|
from src import comsys
|
||||||
from src import logger
|
from src import logger
|
||||||
|
|
@ -14,6 +15,12 @@ from src import logger
|
||||||
#store all irc channels
|
#store all irc channels
|
||||||
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):
|
class IRC_Bot(irc.IRCClient):
|
||||||
|
|
||||||
def _get_nickname(self):
|
def _get_nickname(self):
|
||||||
|
|
@ -29,16 +36,16 @@ class IRC_Bot(irc.IRCClient):
|
||||||
# add this protocol instance to the global list so we
|
# add this protocol instance to the global list so we
|
||||||
# can access it later to send data.
|
# can access it later to send data.
|
||||||
IRC_CHANNELS.append(self)
|
IRC_CHANNELS.append(self)
|
||||||
|
cemit_info("Client connecting to %s.'" % (self.factory.channel))
|
||||||
logger.log_infomsg("IRC: Client connecting to %s.'" % (self.factory.channel))
|
|
||||||
|
|
||||||
def joined(self, 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):
|
def privmsg(self, user, irc_channel, msg):
|
||||||
"Someone has written something in channel. Echo it to the evennia channel"
|
"Someone has written something in channel. Echo it to the evennia channel"
|
||||||
|
|
||||||
print "got msg: %s" % msg
|
|
||||||
try:
|
try:
|
||||||
#find irc->evennia channel mappings
|
#find irc->evennia channel mappings
|
||||||
mappings = IRCChannelMapping.objects.filter(irc_channel_name=irc_channel)
|
mappings = IRCChannelMapping.objects.filter(irc_channel_name=irc_channel)
|
||||||
|
|
@ -49,12 +56,12 @@ class IRC_Bot(irc.IRCClient):
|
||||||
if user:
|
if user:
|
||||||
user.strip()
|
user.strip()
|
||||||
msg = "%s@%s: %s" % (user,irc_channel,msg)
|
msg = "%s@%s: %s" % (user,irc_channel,msg)
|
||||||
|
#logger.log_infomsg("<IRC: " + msg)
|
||||||
logger.log_infomsg("<IRC: " + msg)
|
|
||||||
|
|
||||||
for mapping in mappings:
|
for mapping in mappings:
|
||||||
if mapping.channel:
|
if mapping.channel:
|
||||||
comsys.send_cmessage(mapping.channel, msg, from_external="IRC")
|
comsys.send_cmessage(mapping.channel, msg, from_external="IRC")
|
||||||
|
|
||||||
except IRCChannelMapping.DoesNotExist:
|
except IRCChannelMapping.DoesNotExist:
|
||||||
#no mappings found. Ignore.
|
#no mappings found. Ignore.
|
||||||
pass
|
pass
|
||||||
|
|
@ -62,7 +69,7 @@ class IRC_Bot(irc.IRCClient):
|
||||||
def send_msg(self,msg):
|
def send_msg(self,msg):
|
||||||
"Called by evennia when sending something to mapped IRC channel"
|
"Called by evennia when sending something to mapped IRC channel"
|
||||||
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
|
||||||
|
|
@ -71,10 +78,12 @@ class IRC_BotFactory(protocol.ClientFactory):
|
||||||
self.channel = channel
|
self.channel = channel
|
||||||
self.nickname = nickname
|
self.nickname = nickname
|
||||||
def clientConnectionLost(self, connector, reason):
|
def clientConnectionLost(self, connector, reason):
|
||||||
logger.log_errmsg("IRC: Lost connection (%s), reconnecting." % reason)
|
cemit_info("Lost connection (%s), reconnecting." % reason)
|
||||||
connector.connect()
|
connector.connect()
|
||||||
def clientConnectionFailed(self, connector, reason):
|
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 ):
|
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."
|
"Create the bot instance and connect to the IRC network and channel."
|
||||||
|
|
|
||||||
|
|
@ -90,8 +90,8 @@ class EvenniaService(service.Service):
|
||||||
for cmd_mod in cmd_modules:
|
for cmd_mod in cmd_modules:
|
||||||
try:
|
try:
|
||||||
__import__(cmd_mod)
|
__import__(cmd_mod)
|
||||||
except ImportError:
|
except ImportError, e:
|
||||||
logger.log_errmsg("ERROR: Unable to load command module: %s" % cmd_mod)
|
logger.log_errmsg("ERROR: Unable to load command module: %s (%s)" % (cmd_mod, e))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue