-
Notifications
You must be signed in to change notification settings - Fork 0
/
LockBot.py
54 lines (41 loc) · 1.62 KB
/
LockBot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from twisted.words.protocols import irc
from twisted.internet import protocol
from LockBotBrain import LockBotBrain
import Logger
class LockBot(irc.IRCClient):
def __init__(self):
self.brain = None
self.logger = Logger.Logger()
def _get_nickname(self):
return self.factory.nickname
nickname = property(_get_nickname)
def _get_password(self):
return self.factory.password
password = property(_get_password)
def _get_dbdir(self):
return self.factory.dbdir
dbdir = property(_get_dbdir)
def signedOn(self):
self.logger.info("Signed on as %s." % (self.nickname))
self.brain = LockBotBrain(self.nickname, self.dbdir)
self.join(self.factory.channel)
def joined(self, channel):
self.logger.info("Joined %s." % (channel))
def privmsg(self, user, channel, msg):
self.logger.debug("received: %s" % msg)
responses = self.brain.processPrivMsg(user, channel, msg)
for channel, message in responses:
self.msg(channel, message)
class LockBotFactory(protocol.ClientFactory):
protocol = LockBot
def __init__(self, channel, nickname, dbdir, password=None):
self.channel = channel
self.nickname = nickname
self.password = password
self.dbdir = dbdir
self.logger = Logger.Logger()
def clientConnectionLost(self, connector, reason):
self.logger.critical("Lost connection (%s), reconnecting." % (reason,))
connector.connect()
def clientConnectionFailed(self, connector, reason):
self.logger.critical("Could not connect: %s" % (reason,))