summaryrefslogtreecommitdiff
path: root/fot.py
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-05-25 20:07:55 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-05-25 20:07:55 +0200
commit2066a309d2672f6b071da87c2fb156a2af15c5d3 (patch)
tree8b353d5d6bdae666ddb0ed5407c6030bcef9c4d7 /fot.py
parentb97e85feef6b4dad4add23d17e37fd5ee976e1e3 (diff)
parentf9e9af49233ba05a87f6c00c387134394443bfb3 (diff)
Merge branch 'master' into ipv6
Conflicts: fot.py
Diffstat (limited to 'fot.py')
-rwxr-xr-xfot.py36
1 files changed, 21 insertions, 15 deletions
diff --git a/fot.py b/fot.py
index 75cdfaf..021061a 100755
--- a/fot.py
+++ b/fot.py
@@ -57,9 +57,6 @@ class Bot(irc.IRCClient):
bots.append(self)
self.modules = {}
- def __del__(self):
- bots.remove(self)
-
def __repr__(self):
return '<Bot %s@%s>' % (self.nickname, self.factory.server)
@@ -97,6 +94,9 @@ class Bot(irc.IRCClient):
self.modules = {}
irc.IRCClient.connectionLost(self, reason)
+ def reconnect(self):
+ self.quit('reconnecting')
+
class BotFactory(protocol.ReconnectingClientFactory):
protocol = Bot
@@ -113,24 +113,26 @@ class BotFactory(protocol.ReconnectingClientFactory):
print 'Connecting to', connector.host
def clientConnectionFailed(self, connector, reason):
- print 'Connection failed:', reason
+ print 'Connection failed:', reason.getErrorMessage()
protocol.ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
def clientConnectionLost(self, connector, reason):
- print 'Connection lost:', reason
+ print 'Connection lost:', reason.getErrorMessage()
protocol.ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
-print 'Starting per-network instances...'
-for server in (server for server in config.sections() if server.startswith('server/')):
- if not config.has_option(server,'host') or not config.has_option(server, 'port') or not config.has_option(server, 'channels') or config.has_option(server, 'disabled'):
- continue
+def start_server(server):
+ if not config.has_option(server,'host') or not config.has_option(server, 'port') \
+ or not config.has_option(server, 'channels') or config.has_option(server, 'disabled'):
+ return
+
channels = []
- ms = [(m, config.get(server, m)) for m in modules.keys() if config.has_option(server, m)]
- for c in config.get(server, 'channels').split(' '):
- ch = [x[0] for x in ms if c in x[1]]
- channels.append('%s (%s)' % (c, ' '.join(ch)))
- print '%s: %s' % (server, ' '.join(channels))
- #del channels, ms, c, ch, x
+ 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')
+
factory = BotFactory(server, config.get(server, 'nickname'))
if config.has_option(server, 'host6'):
bind6 = (config.get(server, 'bind6'), 0) if config.has_option(server, 'bind6') else None
@@ -138,6 +140,10 @@ for server in (server for server in config.sections() if server.startswith('serv
else:
reactor.connectTCP(config.get(server, 'host'), config.getint(server, 'port'), factory)
+print 'Starting per-network instances...'
+for server in (server for server in config.sections() if server.startswith('server/')):
+ start_server(server)
+
loginfactory = login.getManholeFactory(globals(), os.path.expanduser('~/.fot.users'))
reactor.listenTCP(3333, loginfactory)