-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbanHelper.py
126 lines (97 loc) · 3.78 KB
/
banHelper.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import hexchat
__module_name__ = "Banhelper"
__module_author__ = "TingPing"
__module_version__ = "5"
__module_description__ = "Simplifies banning and quieting"
wasop = False
def is_op():
for user in hexchat.get_list('users'):
if user.nick == hexchat.get_info('nick'):
if user.prefix == '@':
return True
else:
return False
def do_op(deop=False):
global wasop
chan = hexchat.get_info('channel')
if not deop:
if not is_op():
wasop = False
hexchat.command('cs op {}'.format(chan))
else:
wasop = True
else:
if not wasop:
hexchat.command('cs deop {}'.format(chan))
def do_command(cmd):
if is_op():
hexchat.command(cmd + "\r\n")
do_op(deop=True)
return False
return True
def get_mask(nick):
invalid_chars = ('*', '?', '!', '@', '$')
if any(char in nick for char in invalid_chars):
return nick # It's already a mask.
for user in hexchat.get_list('users'):
if hexchat.nickcmp(user.nick, nick) == 0:
if user.account:
return '$a:{}'.format(user.account)
elif user.host:
host = user.host.split('@')[1]
return '*!*@{}'.format(host)
else:
hexchat.command('whois {}'.format(nick))
print('BH: User info not found, enable irc_who_join or try again.')
return None
def ban_cb(word, word_eol, userdata):
if len(word) > 1:
mask = get_mask(word[1])
command = ""
if mask:
do_op()
if word[0] == 'ban':
command = 'mode +b {}'.format(mask)
elif word[0] == 'kickban':
nick = word[1]
chan = hexchat.get_info('channel')
message = ""
if len(word_eol) > 2:
message = word_eol[2]
command = 'mode +b {}\r\nKICK {} {} :{}'.format(mask, chan, nick, message)
elif word[0] == 'kick':
nick = word[1]
chan = hexchat.get_info('channel')
message = ""
if len(word_eol) > 2:
message = word_eol[2]
command = 'quote KICK {} {} :{}'.format(chan, nick, message)
elif word[0] == 'remove':
nick = word[1]
chan = hexchat.get_info('channel')
message = ""
if len(word_eol) > 2:
message = word_eol[2]
command = 'quote REMOVE {} {} :{}'.format(chan, nick, message)
elif word[0] == 'quiet':
command = 'mode +q {}'.format(mask)
elif word[0] == 'unban':
command = 'mode -b {}'.format(mask)
elif word[0] == 'unquiet':
command = 'mode -q {}'.format(mask)
if command:
hexchat.hook_timer(100, do_command, command)
return hexchat.EAT_HEXCHAT
else:
return hexchat.EAT_NONE
def unload_cb(userdata):
print(__module_name__ + ' version ' + __module_version__ + ' unloaded.')
hexchat.hook_command('kickban', ban_cb)
hexchat.hook_command('kick', ban_cb)
hexchat.hook_command('remove', ban_cb)
hexchat.hook_command('ban', ban_cb)
hexchat.hook_command('quiet', ban_cb)
hexchat.hook_command('unban', ban_cb)
hexchat.hook_command('unquiet', ban_cb)
hexchat.hook_unload(unload_cb)
print(__module_name__ + ' version ' + __module_version__ + ' loaded.')