From 62664c9248a89a185527cd2ec26e55b52dabeb80 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 25 May 2010 19:44:13 +0200 Subject: Cleaned up initial connect code. --- fot.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/fot.py b/fot.py index 8412e8c..ff0b798 100755 --- a/fot.py +++ b/fot.py @@ -120,20 +120,26 @@ class BotFactory(protocol.ReconnectingClientFactory): print 'Connection lost:', reason 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')) 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) -- cgit v1.2.3 From 1138ebbee86f92ad9acf9a11d55da4120170641b Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 25 May 2010 19:57:25 +0200 Subject: Remove useless __del__ in Bot. --- fot.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/fot.py b/fot.py index ff0b798..2fedee6 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 '' % (self.nickname, self.factory.server) -- cgit v1.2.3 From 712570847b88fe754c3fd4cb9e42bf3b354c3fe4 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 25 May 2010 19:58:18 +0200 Subject: Print sane error messages in BotFactory's failed and lost handlers. --- fot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fot.py b/fot.py index 2fedee6..6ed05c0 100755 --- a/fot.py +++ b/fot.py @@ -110,11 +110,11 @@ 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) def start_server(server): -- cgit v1.2.3 From 29fe803bfde71a5da12c79441e1aec39769cebc0 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 25 May 2010 19:58:49 +0200 Subject: Add a reconnect method to Bot. --- fot.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fot.py b/fot.py index 6ed05c0..cd7b1ed 100755 --- a/fot.py +++ b/fot.py @@ -94,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 -- cgit v1.2.3 From f9e9af49233ba05a87f6c00c387134394443bfb3 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 25 May 2010 19:59:10 +0200 Subject: Added *.swp to .gitignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0d20b64..c9b568f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.pyc +*.swp -- cgit v1.2.3