This repository has been archived by the owner on Dec 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit_bot.py
64 lines (47 loc) · 1.74 KB
/
commit_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from twisted.words.protocols import irc
from twisted.internet import reactor
from twisted.spread import pb
import config
# XXX Plugins or something, jeez stupid.
import commit, ticket, alert, message
class Notifications(pb.Root, commit.RepositoryChangeListener, ticket.TicketChangeListener, alert.MuninAlertListener, message.MessageListener):
def __init__(self, proto):
self.proto = proto
class CommitBot(irc.IRCClient, commit.RepositoryChange, ticket.TicketChange, ticket.TicketReview, alert.MuninAlert, message.Message):
lineRate = config.LINE_RATE
notificationPort = None
def __init__(self, nickname, password):
self.nickname = nickname
self.password = password
def connectionLost(self, reason):
if self.notificationPort is not None:
self.notificationPort.stopListening()
for cls in self.__class__.__bases__[1:]:
try:
f = cls.connectionLost
except AttributeError:
pass
else:
f(self, reason)
def signedOn(self):
self.factory.resetDelay()
sf = pb.PBServerFactory(Notifications(self))
self.notificationPort = reactor.listenTCP(
config.BOT_PORT, sf)
for cls in self.__class__.__bases__[1:]:
try:
f = cls.signedOn
except AttributeError:
pass
else:
f(self)
def noticed(self, user, channel, message):
pass
def privmsg(self, user, channel, message):
for cls in self.__class__.__bases__[1:]:
try:
f = cls.privmsg
except AttributeError:
pass
else:
f(self, user, channel, message)