summaryrefslogtreecommitdiff
path: root/fot.py
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-05-27 00:01:56 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-05-27 00:01:56 +0200
commit68a2cf8f94f2d57c51e91d74629a43fc837903ea (patch)
tree851331ffb070adfc7613f372b3f5e86b3a8b8acf /fot.py
parentdec939c32f5f4de366a8f72eaa85fbc827996041 (diff)
Changed module loading and handling.
Diffstat (limited to 'fot.py')
-rwxr-xr-xfot.py54
1 files changed, 40 insertions, 14 deletions
diff --git a/fot.py b/fot.py
index 1c1ef43..52c252b 100755
--- a/fot.py
+++ b/fot.py
@@ -5,7 +5,7 @@ from twisted.internet import reactor, protocol
from twisted.python import log
from twisted.protocols.basic import LineReceiver
-import os
+import os, re
from ConfigParser import ConfigParser
@@ -24,8 +24,11 @@ modules = {}
def load_modules():
print 'Loading modules...'
- for m in config.options('modules'):
- if config.getboolean('modules', m):
+ for s in config.sections():
+ if not s.startswith('module/'):
+ continue
+ m = s[7:]
+ if not config.has_option(s, 'load') or config.getboolean(s, 'load'):
try:
if modules.has_key(m):
reload(modules[m])
@@ -58,6 +61,7 @@ class Bot(irc.IRCClient):
self.modules = {}
self.keywords = {}
self.msg_callbacks = []
+ self.module_channels = None
def __repr__(self):
return '<Bot %s@%s>' % (self.nickname, self.factory.server)
@@ -77,9 +81,28 @@ class Bot(irc.IRCClient):
if hasattr(m, 'stop'):
m.stop()
self.modules = {}
+
+ server = self.factory.server.split('/', 1)[1]
+ channel_list = config.get(self.factory.server, 'channels').split()
+ self.module_channels = dict([(x, []) for x in channel_list])
for m in modules.keys():
- if config.has_option(self.factory.server, m) and config.get(self.factory.server, m).strip():
- self.modules[m] = modules[m].Module(self)
+ if config.has_option('module/' + m, 'filter'):
+ mod_re = re.compile(config.get('module/' + m, 'filter'))
+ else:
+ mod_re = None
+
+ mod = None # the module instance
+
+ for channel in channel_list:
+ if not mod_re or mod_re.match('%s/%s' % (server, x)) != None:
+ if not mod:
+ mod = modules[m].Module(self)
+ self.module_channels[channel].append(mod)
+
+ if mod:
+ self.modules[m] = mod
+ #if config.has_option(self.factory.server, m) and config.get(self.factory.server, m).strip():
+ #self.modules[m] = modules[m].Module(self)
def connectionMade(self):
self.apply_modules()
@@ -91,8 +114,14 @@ class Bot(irc.IRCClient):
self.join(chan)
def privmsg(self, nick, channel, msg):
+ priv = channel == self.nickname
+ # filter out server stuff
+ if not priv and not '!' in nick:
+ return
+
for mod in self.msg_callbacks:
- mod.privmsg(nick, channel, msg)
+ if priv or mod in self.module_channels[channel]:
+ mod.privmsg(nick, channel, msg)
msg = msg.split(None, 1)
if not len(msg):
@@ -101,8 +130,11 @@ class Bot(irc.IRCClient):
kw, msg = msg[0], ''
else:
kw, msg = msg
+
if kw in self.keywords:
- self.keywords[kw].keyword(nick, channel, kw, msg)
+ mod = self.keywords[kw]
+ if priv or mod in self.module_channels[channel]:
+ mod.keyword(nick, channel, kw, msg)
def kickedFrom(self, channel, kicker, message):
self.join(channel)
@@ -145,13 +177,7 @@ def start_server(server):
or not config.has_option(server, 'channels') or config.has_option(server, 'disabled'):
return
- channels = []
- server_modules = [(m, config.get(server, m).split()) for m in modules.keys() if config.has_option(server, m)]
- for channel in config.get(server, 'channels').split():
- channel_modules = [x[0] for x in server_modules if channel in x[1]]
- channels.append('%s (%s)' % (channel, ' '.join(channel_modules) if len(channel_modules) else 'No modules'))
-
- print '%s: %s' % (server, ' '.join(channels) if len(channels) else 'No channels')
+ print '%s' % server
factory = BotFactory(server, config.get(server, 'nickname'))
reactor.connectTCP(config.get(server, 'host'), config.getint(server, 'port'), factory)