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
=== modified file 'Bantracker/plugin.py'
--- Bantracker/plugin.py 2012-09-08 02:20:59 +0000
+++ Bantracker/plugin.py 2012-10-02 13:07:21 +0000
@@ -248,6 +248,10 @@
248 global queue248 global queue
249 queue.dequeue(parent, irc)249 queue.dequeue(parent, irc)
250250
251def supported(irc, mode):
252 chanmodes = irc.state.supported.get('chanmodes', '')
253 return mode in chanmodes.split(',')[0]
254
251class MsgQueue(object):255class MsgQueue(object):
252 def __init__(self):256 def __init__(self):
253 self.msgcache = []257 self.msgcache = []
@@ -536,6 +540,7 @@
536 else:540 else:
537 self.db = None541 self.db = None
538 self.get_bans(irc)542 self.get_bans(irc)
543 self.get_bans(irc, mode='q')
539 self.get_nicks(irc)544 self.get_nicks(irc)
540545
541 # init review stuff546 # init review stuff
@@ -569,14 +574,25 @@
569 self.hosts[host] = []574 self.hosts[host] = []
570 self.hosts[host].append(nick)575 self.hosts[host].append(nick)
571576
572 def get_bans(self, irc):577 def get_bans(self, irc, channel=None, mode='b'):
573 global queue578 global queue
574 for channel in irc.state.channels.keys():579
580 if not supported(irc, mode):
581 return
582
583 def fetch(channel):
575 if not self.registryValue('enabled', channel):584 if not self.registryValue('enabled', channel):
576 continue585 return
586
577 if channel not in self.bans:587 if channel not in self.bans:
578 self.bans[channel] = []588 self.bans[channel] = []
579 queue.queue(ircmsgs.mode(channel, 'b'))589 queue.queue(ircmsgs.mode(channel, mode))
590
591 if not channel:
592 for channel in irc.state.channels.keys():
593 fetch(channel)
594 else:
595 fetch(channel)
580596
581 def sendWhois(self, irc, nick, do_reply=False, *args):597 def sendWhois(self, irc, nick, do_reply=False, *args):
582 nick = nick.lower()598 nick = nick.lower()
@@ -623,14 +639,21 @@
623 kwargs = {'from_reply': True, 'reply': None}639 kwargs = {'from_reply': True, 'reply': None}
624 f(*args, **kwargs)640 f(*args, **kwargs)
625641
626 def do367(self, irc, msg):642 def do367(self, irc, msg, quiet=False):
627 """Got ban"""643 """Got ban"""
628 channel = msg.args[1]644 channel = msg.args[1]
629 try:645 try:
630 bans = self.bans[channel]646 bans = self.bans[channel]
631 except KeyError:647 except KeyError:
632 bans = self.bans[channel] = []648 bans = self.bans[channel] = []
633 ban = Ban(msg.args)649 if quiet:
650 # args = (nick, channel, mode, mask, who, when)
651 args = list(msg.args)
652 del args[2] # drop the 'q' bit
653 args[2] = '%' + args[2]
654 ban = Ban(args)
655 else:
656 ban = Ban(msg.args)
634 if ban not in bans:657 if ban not in bans:
635 bans.append(ban)658 bans.append(ban)
636659
@@ -643,6 +666,16 @@
643 except KeyError:666 except KeyError:
644 pass667 pass
645668
669 def do728(self, irc, msg):
670 """Got quiet"""
671 if supported(irc, 'q'):
672 self.do367(irc, msg, quiet=True)
673
674 # End of channel quiet list.
675 def do729(self, irc, msg):
676 if supported(irc, 'q'):
677 self.do368(irc, msg)
678
646 def nick_to_host(self, irc=None, target='', with_nick=True, reply_now=True):679 def nick_to_host(self, irc=None, target='', with_nick=True, reply_now=True):
647 target = target.lower()680 target = target.lower()
648 if ircutils.isUserHostmask(target):681 if ircutils.isUserHostmask(target):
@@ -1082,7 +1115,8 @@
1082 del self.opped[channel]1115 del self.opped[channel]
1083 if channel in self.bans:1116 if channel in self.bans:
1084 del self.bans[channel]1117 del self.bans[channel]
1085 queue.queue(ircmsgs.mode(channel, 'b'))1118 self.get_bans(irc, channel)
1119 self.get_bans(irc, channel, 'q')
1086 nick = msg.nick.lower() or msg.prefix.lower().split('!', 1)[0]1120 nick = msg.nick.lower() or msg.prefix.lower().split('!', 1)[0]
1087 self.nicks[nick] = msg.prefix.lower()1121 self.nicks[nick] = msg.prefix.lower()
10881122
10891123
=== modified file 'Bantracker/test.py'
--- Bantracker/test.py 2012-09-08 02:20:59 +0000
+++ Bantracker/test.py 2012-10-02 13:07:21 +0000
@@ -638,4 +638,33 @@
638 finally:638 finally:
639 pluginConf.autoremove.notify.channels.set('')639 pluginConf.autoremove.notify.channels.set('')
640640
641 def testQuietList(self):
642 self.irc.feedMsg(ircmsgs.IrcMsg(
643 ':server.net 005 test CHANMODES=eIbq,k,flj,CFLMPQcgimnprstz :are supported'))
644 self.irc.feedMsg(ircmsgs.IrcMsg(
645 ':server.net 728 test #channel q troll!*@* op!user@home.com 123456789'))
646 self.irc.feedMsg(ircmsgs.IrcMsg(
647 ':server.net 729 test #channel q :End of Channel Quiet List'))
648 L = self.getCallback().bans.get('#channel')
649 self.assertTrue(L != None)
650 self.assertEqual('%troll!*@*', L[0].mask)
651
652 def testQuietListNotSupported(self):
653 self.irc.feedMsg(ircmsgs.IrcMsg(
654 ':server.net 005 test CHANMODES=eIb,k,flj,CFLMPQcgimnprstz :are supported'))
655 self.irc.feedMsg(ircmsgs.IrcMsg(
656 ':server.net 728 test #channel q troll!*@* op!user@home.com 123456789'))
657 self.irc.feedMsg(ircmsgs.IrcMsg(
658 ':server.net 729 test #channel q :End of Channel Quiet List'))
659 L = self.getCallback().bans.get('#channel')
660 self.assertTrue(L == None)
661
662 def testBanList(self):
663 self.irc.feedMsg(ircmsgs.IrcMsg(
664 ':server.net 367 test #channel troll!*@* op!user@home.com 123456789'))
665 self.irc.feedMsg(ircmsgs.IrcMsg(
666 ':server.net 368 test #channel :End of Channel Ban List'))
667 obj = self.getCallback().bans['#channel'][0]
668 self.assertEqual('troll!*@*', obj.mask)
669
641670

Subscribers

People subscribed via source and target branches