summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xfot.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/fot.py b/fot.py
index c468c19..8412e8c 100755
--- a/fot.py
+++ b/fot.py
@@ -4,7 +4,6 @@ from twisted.words.protocols import irc
from twisted.internet import reactor, protocol
from twisted.python import log
from twisted.protocols.basic import LineReceiver
-from twisted.manhole.telnet import Shell
import os
@@ -33,6 +32,7 @@ def load_modules():
else:
modules[m] = __import__('modules.' + m, globals(), locals(), ['Module'])
mod = modules[m]
+ mod.config = config
print '%s by %s' % (mod.info['title'], mod.info['author'])
del mod
except:
@@ -55,6 +55,7 @@ def refresh_modules():
class Bot(irc.IRCClient):
def __init__(self):
bots.append(self)
+ self.modules = {}
def __del__(self):
bots.remove(self)
@@ -63,6 +64,10 @@ class Bot(irc.IRCClient):
return '<Bot %s@%s>' % (self.nickname, self.factory.server)
def apply_modules(self):
+ # Call stop() for each module if neccessary (can't rely on __del__ here)
+ for m in self.modules.itervalues():
+ if hasattr(m, 'stop'):
+ m.stop()
self.modules = {}
for m in modules.keys():
if config.has_option(self.factory.server, m) and config.get(self.factory.server, m).strip():
@@ -85,23 +90,34 @@ class Bot(irc.IRCClient):
def kickedFrom(self, channel, kicker, message):
self.join(channel)
+ def connectionLost(self, reason):
+ for m in self.modules.itervalues():
+ if hasattr(m, 'stop'):
+ m.stop()
+ self.modules = {}
+ irc.IRCClient.connectionLost(self, reason)
+
class BotFactory(protocol.ReconnectingClientFactory):
protocol = Bot
def __init__(self, server, nickname):
self.server = server
self.nickname = nickname
+ self.maxDelay = 120
def buildProtocol(self, addr):
self.resetDelay()
return protocol.ReconnectingClientFactory.buildProtocol(self, addr)
+ def startedConnecting(self, connector):
+ print 'Connecting to', connector.host
+
def clientConnectionFailed(self, connector, reason):
- print 'Connection failed: ', reason
+ print 'Connection failed:', reason
protocol.ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
def clientConnectionLost(self, connector, reason):
- print 'Connection lost: ', reason
+ print 'Connection lost:', reason
protocol.ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
print 'Starting per-network instances...'