-
Notifications
You must be signed in to change notification settings - Fork 2
/
twisted_bot.py
46 lines (33 loc) · 1.12 KB
/
twisted_bot.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
from twisted.words.protocols import irc
from twisted.internet import protocol
class Bot(irc.IRCClient):
def __init__(self):
self.identity = "bot"
@property
def nickname(self):
return self.factory.nickname
@property
def first_name(self):
return self.factory.first_name
@property
def last_name(self):
return self.factory.last_name
def signedOn(self):
self.join(self.factory.channel)
print "Signed on as %s." % self.nickname
def joined(self, channel):
print "Joined %s." % channel
def privmsg(self, user, channel, msg):
print msg
class BotFactory(protocol.ClientFactory):
protocol = Bot
def __init__(self, channel, nickname):
self.channel = channel
self.nickname = nickname + "_Bot"
self.first_name = nickname
self.last_name = "Bot"
def clientConnectionLost(self, connector, reason):
print "Lost connection (%s), reconnecting." % (reason,)
connector.connect()
def clientConnectionFailed(self, connector, reason):
print "Could not connect: %s" % (reason,)