1
from gozerbot.tests import tests
2
from gozerbot.generic import getwho, rlog
3
from gozerbot.commands import cmnds
4
from gozerbot.examples import examples
5
from gozerbot.aliases import aliases
6
from gozerbot.callbacks import callbacks
7
from gozerbot.plughelp import plughelp
11
plughelp.add('kickban', 'channel ban list management')
17
def handle_367(bot, ievent):
18
rlog(0, '367', str(ievent))
19
channel = ievent.arguments[1].lower()
20
if not bot.name in bans or not channel in bans[bot.name]:
21
return # not requested by this plugin
22
bans[bot.name][channel].append(ievent.txt.split()[0])
24
def handle_mode(bot, ievent):
25
rlog(0, 'mode', str(ievent))
26
# [18 Jan 2008 13:41:29] (mode) cmnd=MODE prefix=maze!wijnand@2833335b.cc9dd561.com.hmsk postfix=#eth0-test +b *!*@je.moeder.ook arguments=[u'#eth0-test', u'+b', u'*!*@je.moeder.ook'] nick=maze user=wijnand userhost=wijnand@2833335b.cc9dd561.com.hmsk channel=#eth0-test txt= command= args=[] rest= speed=5 options={}
28
def get_bans(bot, channel):
29
# :ironforge.sorcery.net 367 basla #eth0 *!*@71174af5.e1d1a3cf.net.hmsk eth0!eth0@62.212.76.127 1200657224
30
# :ironforge.sorcery.net 367 basla #eth0 *!*@6ca5f0a3.14055a38.89.123.imsk eth0!eth0@62.212.76.127 1200238584
31
# :ironforge.sorcery.net 368 basla #eth0 :End of Channel Ban List
32
channel = channel.lower()
33
if not bot.name in bans:
35
bans[bot.name][channel] = []
36
queue368 = Queue.Queue()
37
bot.wait.register('368', channel, queue368)
38
bot.sendraw('MODE %s +b' % (channel, ))
39
# wait for End of Channel Ban List
41
res = queue368.get(1, timeout)
44
return bans[bot.name][channel]
47
return getwho(bot, bot.nick).split('@')[-1].lower()
49
def handle_ban_list(bot, ievent):
50
banslist = get_bans(bot, ievent.channel)
52
ievent.reply('the ban list for %s is empty' % ievent.channel)
54
ievent.reply('bans on %s: ' % ievent.channel, banslist, nr=True)
56
def handle_ban_remove(bot, ievent):
57
channel = ievent.channel.lower()
58
if len(ievent.args) != 1 or not ievent.args[0].isdigit():
59
ievent.missing('<banlist index>')
61
if not bot.name in bans or not channel in bans[bot.name]:
62
banslist = get_bans(bot, ievent.channel)
64
banslist = bans[bot.name][channel]
65
index = int(ievent.args[0])-1
66
if len(banslist) <= index:
67
ievent.reply('ban index out of range')
69
unban = banslist[index]
70
banslist.remove(unban)
71
bot.sendraw('MODE %s -b %s' % (channel, unban))
72
ievent.reply('unbanned %s' % (unban, ))
74
def handle_ban_add(bot, ievent):
76
ievent.missing('<nick>')
78
if ievent.args[0].lower() == bot.nick.lower():
79
ievent.reply('not going to ban myself')
81
userhost = getwho(bot, ievent.args[0])
83
host = userhost.split('@')[-1].lower()
84
if host == get_bothost(bot):
85
ievent.reply('not going to ban myself')
87
bot.sendraw('MODE %s +b *!*@%s' % (ievent.channel, host))
88
ievent.reply('banned %s' % (host, ))
90
ievent.reply('can not get userhost of %s' % ievent.args[0])
92
def handle_kickban_add(bot, ievent):
94
ievent.missing('<nick> [<reason>]')
96
if ievent.args[0].lower() == bot.nick.lower():
97
ievent.reply('not going to kickban myself')
99
userhost = getwho(bot, ievent.args[0])
100
reason = len(ievent.args) > 1 and ' '.join(ievent.args[1:]) or 'Permban requested, bye'
102
host = userhost.split('@')[-1].lower()
103
if host == get_bothost(bot):
104
ievent.reply('not going to kickban myself')
106
bot.sendraw('MODE %s +b *!*@%s' % (ievent.channel, host))
107
bot.sendraw('KICK %s %s :%s' % (ievent.channel, ievent.args[0], reason))
109
ievent.reply('can not get userhost of %s' % ievent.args[0])
111
callbacks.add('367', handle_367)
112
callbacks.add('MODE', handle_mode)
113
aliases.data['ban'] = 'ban-add'
114
aliases.data['bans'] = 'ban-list'
115
aliases.data['unban'] = 'ban-remove'
116
aliases.data['kb'] = 'ban-kickban'
117
aliases.data['kickban'] = 'ban-kickban'
118
cmnds.add('ban-add', handle_ban_add, 'OPER')
119
examples.add('ban-add', 'adds a host to the ban list', 'ban-add *!*@lamers.are.us')
120
tests.add('ban-add *!*@lamer', 'added')
121
cmnds.add('ban-list', handle_ban_list, 'OPER', threaded=True)
122
tests.add('ban-list', 'lamer')
123
cmnds.add('ban-remove', handle_ban_remove, 'OPER', threaded=True)
124
examples.add('ban-remove', 'removes a host from the ban list', 'ban-remove 1')
125
tests.add('ban-remove', '*!*@lamer')
126
cmnds.add('ban-kickban', handle_kickban_add, 'OPER')
127
examples.add('ban-kickban', 'kickbans the given nick', 'kickban Lam0r Get out of here')
128
tests.add('ban-kickban', 'ban-kickban exec')