-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSignBotQueue.py
68 lines (54 loc) · 1.74 KB
/
SignBotQueue.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# SDC in the place to B
"""
4/18/2014 SDC
new version uses Queue!
"""
import SignQueue
from twisted.words.protocols import irc
from twisted.internet import protocol
from twisted.internet import reactor
import sys
import re
import time
class SignBot(irc.IRCClient):
def _get_nickname(self):
return self.factory.nickname
nickname = property(_get_nickname)
def signedOn(self):
self.join(self.factory.channel, self.factory.password)
print "Signed on as %s." % (self.nickname,)
def joined(self, channel):
print "Joined %s." % (channel,)
def privmsg(self, user, channel, msg):
if msg.startswith('!s '):
print msg.split(' ')[1]
self.factory.writeMessage(' '.join(msg.split(' ')[1:]))
return
elif not user:
return
elif self.nickname in msg:
msg = re.compile(self.nickname + "[:,]* ?", re.I).sub('', msg)
prefix = "%s: " % (user.split('!', 1)[0], )
else:
prefix = ''
class SignBotFactory(protocol.ClientFactory):
protocol = SignBot
def __init__(self, channel, nickname, password=''):
self.channel = channel
self.nickname = nickname
self.password = password
self.signQueue = SignQueue.SignQueue()
def writeMessage(self,message):
self.signQueue.addMessage(message,life_time = 120, immediate = 1)
def clientConnectionLost(self, connector, reason):
print "Lost connection (%s), reconnecting." % (reason,)
connector.connect()
def clientConnectionFailed(self, connector, reason):
print "Could not connect: %s" % (reason,)
if __name__ == "__main__":
nickname = 'SignBot'
channel = 'blabs-bots'
password = ''
reactor.connectTCP('irc.bloominglabs.org', 6667, SignBotFactory('#' + channel, nickname, password))
reactor.run()