Merge lp:~m4v/ubuntu-bots/fetch-quiets into lp:ubuntu-bots

Proposed by m4v
Status: Merged
Approved by: Terence Simpson
Approved revision: 301
Merged at revision: 302
Proposed branch: lp:~m4v/ubuntu-bots/fetch-quiets
Merge into: lp:ubuntu-bots
Diff against target: 140 lines (+70/-7)
2 files modified
Bantracker/plugin.py (+41/-7)
Bantracker/test.py (+29/-0)
To merge this branch: bzr merge lp:~m4v/ubuntu-bots/fetch-quiets
Reviewer Review Type Date Requested Status
Terence Simpson Approve
Review via email: mp+127481@code.launchpad.net

Description of the change

sync quiets

To post a comment you must log in.
Revision history for this message
Terence Simpson (tsimpson) wrote :

all good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Bantracker/plugin.py'
2--- Bantracker/plugin.py 2012-09-08 02:20:59 +0000
3+++ Bantracker/plugin.py 2012-10-02 13:07:21 +0000
4@@ -248,6 +248,10 @@
5 global queue
6 queue.dequeue(parent, irc)
7
8+def supported(irc, mode):
9+ chanmodes = irc.state.supported.get('chanmodes', '')
10+ return mode in chanmodes.split(',')[0]
11+
12 class MsgQueue(object):
13 def __init__(self):
14 self.msgcache = []
15@@ -536,6 +540,7 @@
16 else:
17 self.db = None
18 self.get_bans(irc)
19+ self.get_bans(irc, mode='q')
20 self.get_nicks(irc)
21
22 # init review stuff
23@@ -569,14 +574,25 @@
24 self.hosts[host] = []
25 self.hosts[host].append(nick)
26
27- def get_bans(self, irc):
28+ def get_bans(self, irc, channel=None, mode='b'):
29 global queue
30- for channel in irc.state.channels.keys():
31+
32+ if not supported(irc, mode):
33+ return
34+
35+ def fetch(channel):
36 if not self.registryValue('enabled', channel):
37- continue
38+ return
39+
40 if channel not in self.bans:
41 self.bans[channel] = []
42- queue.queue(ircmsgs.mode(channel, 'b'))
43+ queue.queue(ircmsgs.mode(channel, mode))
44+
45+ if not channel:
46+ for channel in irc.state.channels.keys():
47+ fetch(channel)
48+ else:
49+ fetch(channel)
50
51 def sendWhois(self, irc, nick, do_reply=False, *args):
52 nick = nick.lower()
53@@ -623,14 +639,21 @@
54 kwargs = {'from_reply': True, 'reply': None}
55 f(*args, **kwargs)
56
57- def do367(self, irc, msg):
58+ def do367(self, irc, msg, quiet=False):
59 """Got ban"""
60 channel = msg.args[1]
61 try:
62 bans = self.bans[channel]
63 except KeyError:
64 bans = self.bans[channel] = []
65- ban = Ban(msg.args)
66+ if quiet:
67+ # args = (nick, channel, mode, mask, who, when)
68+ args = list(msg.args)
69+ del args[2] # drop the 'q' bit
70+ args[2] = '%' + args[2]
71+ ban = Ban(args)
72+ else:
73+ ban = Ban(msg.args)
74 if ban not in bans:
75 bans.append(ban)
76
77@@ -643,6 +666,16 @@
78 except KeyError:
79 pass
80
81+ def do728(self, irc, msg):
82+ """Got quiet"""
83+ if supported(irc, 'q'):
84+ self.do367(irc, msg, quiet=True)
85+
86+ # End of channel quiet list.
87+ def do729(self, irc, msg):
88+ if supported(irc, 'q'):
89+ self.do368(irc, msg)
90+
91 def nick_to_host(self, irc=None, target='', with_nick=True, reply_now=True):
92 target = target.lower()
93 if ircutils.isUserHostmask(target):
94@@ -1082,7 +1115,8 @@
95 del self.opped[channel]
96 if channel in self.bans:
97 del self.bans[channel]
98- queue.queue(ircmsgs.mode(channel, 'b'))
99+ self.get_bans(irc, channel)
100+ self.get_bans(irc, channel, 'q')
101 nick = msg.nick.lower() or msg.prefix.lower().split('!', 1)[0]
102 self.nicks[nick] = msg.prefix.lower()
103
104
105=== modified file 'Bantracker/test.py'
106--- Bantracker/test.py 2012-09-08 02:20:59 +0000
107+++ Bantracker/test.py 2012-10-02 13:07:21 +0000
108@@ -638,4 +638,33 @@
109 finally:
110 pluginConf.autoremove.notify.channels.set('')
111
112+ def testQuietList(self):
113+ self.irc.feedMsg(ircmsgs.IrcMsg(
114+ ':server.net 005 test CHANMODES=eIbq,k,flj,CFLMPQcgimnprstz :are supported'))
115+ self.irc.feedMsg(ircmsgs.IrcMsg(
116+ ':server.net 728 test #channel q troll!*@* op!user@home.com 123456789'))
117+ self.irc.feedMsg(ircmsgs.IrcMsg(
118+ ':server.net 729 test #channel q :End of Channel Quiet List'))
119+ L = self.getCallback().bans.get('#channel')
120+ self.assertTrue(L != None)
121+ self.assertEqual('%troll!*@*', L[0].mask)
122+
123+ def testQuietListNotSupported(self):
124+ self.irc.feedMsg(ircmsgs.IrcMsg(
125+ ':server.net 005 test CHANMODES=eIb,k,flj,CFLMPQcgimnprstz :are supported'))
126+ self.irc.feedMsg(ircmsgs.IrcMsg(
127+ ':server.net 728 test #channel q troll!*@* op!user@home.com 123456789'))
128+ self.irc.feedMsg(ircmsgs.IrcMsg(
129+ ':server.net 729 test #channel q :End of Channel Quiet List'))
130+ L = self.getCallback().bans.get('#channel')
131+ self.assertTrue(L == None)
132+
133+ def testBanList(self):
134+ self.irc.feedMsg(ircmsgs.IrcMsg(
135+ ':server.net 367 test #channel troll!*@* op!user@home.com 123456789'))
136+ self.irc.feedMsg(ircmsgs.IrcMsg(
137+ ':server.net 368 test #channel :End of Channel Ban List'))
138+ obj = self.getCallback().bans['#channel'][0]
139+ self.assertEqual('troll!*@*', obj.mask)
140+
141

Subscribers

People subscribed via source and target branches