This repository has been archived by the owner on Apr 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.py
108 lines (82 loc) · 3.47 KB
/
plugin.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from time import time
import supybot.utils as utils
from supybot.commands import *
import supybot.plugins as plugins
import supybot.ircutils as ircutils
import supybot.callbacks as callbacks
import supybot.ircmsgs as ircmsgs
import supybot.schedule as schedule
class GuiltByAssociation(callbacks.Plugin):
"""
This plugin automatically kickbans users who join the channel if they are
joined to other channels which are considered hostile. In order to use this
plugin, supybot.plugins.GuiltByAssociation.enable must be True.
supybot.plugins.GuiltByAssociation.chans is a comma-separated list of
channels to consider hostile.
"""
_whois = {}
_chans = []
def __init__(self, irc):
self.__parent = super(GuiltByAssociation, self)
self.__parent.__init__(irc)
def doJoin(self, irc, msg):
channel = msg.args[0]
if not self.registryValue('enable', channel):
return
self._chans = [chan.lower() for chan in
self.registryValue('chans', channel).split(',')]
if not ircutils.strEqual(msg.nick, irc.nick):
nick = ircutils.toLower(msg.nick)
irc_ = callbacks.SimpleProxy(irc, msg)
irc_.queueMsg(ircmsgs.whois(nick, nick))
self._whois[(irc, nick)] = (irc, msg, {})
# shamelessly lifted from the Network plugin
def do311(self, irc, msg):
nick = ircutils.toLower(msg.args[1])
if (irc, nick) not in self._whois:
return
else:
self._whois[(irc, nick)][-1][msg.command] = msg
# These are all sent by a WHOIS response.
do301 = do311
do312 = do311
do317 = do311
do319 = do311
do320 = do311
def do318(self, irc, msg):
nick = msg.args[1]
loweredNick = ircutils.toLower(nick)
if (irc, loweredNick) not in self._whois:
return
(replyIrc, replyMsg, d) = self._whois[(irc, loweredNick)]
sourcechan = replyMsg.args[0]
hostmask = '@'.join(d['311'].args[2:4])
user = d['311'].args[-1]
delay = self.registryValue('expire')
if not self.registryValue('enable', sourcechan):
return
def unban():
irc.queueMsg(ircmsgs.unban(sourcechan, '*!{hostmask}'
.format(hostmask=hostmask)))
if '319' in d:
channels = d['319'].args[-1].split()
for channel in channels:
stripped_chan = channel.lstrip('@%+~!')
# UnrealIRCd uses & for user modes and disallows it as a
# channel-prefix, flying in the face of the RFC. Have to
# handle this specially when processing WHOIS response.
testchan = stripped_chan.lstrip('&')
if testchan != stripped_chan and irc.isChannel(testchan):
stripped_chan = testchan
stripped_chan = stripped_chan.lower()
if stripped_chan in self._chans:
# user is in a hostile channel; kick ban
schedule.addEvent(unban, time() + delay)
irc_ = callbacks.SimpleProxy(irc, msg)
irc_.queueMsg(
ircmsgs.ban(sourcechan,
'*!{hostmask}'.format(hostmask=hostmask)))
irc_.queueMsg(ircmsgs.kick(sourcechan, nick))
break
del self._whois[(irc, loweredNick)]
Class = GuiltByAssociation