summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rwxr-xr-xfot.py36
2 files changed, 22 insertions, 15 deletions
diff --git a/.gitignore b/.gitignore
index 0d20b64..c9b568f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
*.pyc
+*.swp
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)