/
adminchannel.py
387 lines (360 loc) · 10.6 KB
/
adminchannel.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#!/usr/bin/env python
"""
admin.py - jenni Admin Module
Copyright 2010-2015, Michael Yanovich (yanovich.net), Alek Rollyson, Josh Begleiter (jbegleiter.com)
Licensed under the Eiffel Forum License 2.
More info:
* jenni: https://github.com/myano/jenni/
* Phenny: http://inamidst.com/phenny/
Beefed up by Alek Rollyson, Josh Begleiter.
* Added functions for op, deop, voice, devoice
* Uses NickServ ACC to verify that a nick is identified with services, as well
as m5's admin list as a double verification system. Should eliminate the possibility
of nick spoofing. May only work with freenode, hasn't been tested on other networks.
"""
import re
auth_list = []
admins = []
def voice(jenni, input):
"""
Command to voice users in a room. If no nick is given,
jenni will voice the nick who sent the command
"""
if not input.admin:
return jenni.say('You must be an admin to perform this operation')
inputs = None
try:
inputs = input.group(2).split(' ')
except:
return jenni.say('Invalid input: .voice ##example or .voice ##example nick')
channel = None
try:
channel = inputs[0]
if not channel.startswith('#'): raise Exception
except:
return jenni.say('You must provide a valid channel')
nick = None
try:
nick = inputs[1]
except:
pass
if not nick:
nick = input.nick
jenni.write(['MODE', channel, "+v", nick])
voice.commands = ['voice']
voice.priority = 'low'
voice.example = '.voice ##example or .voice ##example nick'
def devoice(jenni, input):
"""
Command to devoice users in a room. If no nick is given,
jenni will devoice the nick who sent the command
"""
if not input.admin:
return jenni.say('You must be an admin to perform this operation')
inputs = None
try:
inputs = input.group(2).split(' ')
except:
return jenni.say('Invalid input: .devoice ##example or .devoice ##example nick')
channel = None
try:
channel = inputs[0]
if not channel.startswith('#'): raise Exception
except:
return jenni.say('You must provide a valid channel')
nick = None
try:
nick = inputs[1]
except:
pass
if not nick:
nick = input.nick
jenni.write(['MODE', channel, "-v", nick])
devoice.commands = ['devoice']
devoice.priority = 'low'
devoice.example = '.devoice ##example or .devoice ##example nick'
def op(jenni, input):
"""
Command to op users in a room. If no nick is given,
jenni will op the nick who sent the command
"""
if not input.admin:
return jenni.say('You must be an admin to perform this operation')
inputs = None
try:
inputs = input.group(2).split(' ')
except:
return jenni.say('Invalid input: .op ##example or .op ##example nick')
channel = None
try:
channel = inputs[0]
if not channel.startswith('#'): raise Exception
except:
return jenni.say('You must provide a valid channel')
nick = None
try:
nick = inputs[1]
except:
pass
if not nick:
nick = input.nick
jenni.write(['MODE', channel, "+o", nick])
op.commands = ['op']
op.priority = 'low'
op.example = '.op ##example or .op ##example nick'
def deop(jenni, input):
"""
Command to deop users in a room. If no nick is given,
jenni will deop the nick who sent the command
"""
if not input.admin:
return jenni.say('You must be an admin to perform this operation')
inputs = None
try:
inputs = input.group(2).split(' ')
except:
return jenni.say('Invalid input: .deop ##example or .deop ##example nick')
channel = None
try:
channel = inputs[0]
if not channel.startswith('#'): raise Exception
except:
return jenni.say('You must provide a valid channel')
nick = None
try:
nick = inputs[1]
except:
pass
if not nick:
nick = input.nick
jenni.write(['MODE', channel, "-o", nick])
deop.commands = ['deop']
deop.priority = 'low'
deop.example = '.deop ##example or .deop ##example nick'
def auth_request(jenni, input):
"""
This will scan every message in a room for nicks in jenni's
admin list. If one is found, it will send an ACC request
to NickServ. May only work with Freenode.
"""
admins = jenni.config.admins
pattern = '(' + '|'.join([re.escape(x) for x in admins]) + ')'
matches = re.findall(pattern, input)
for x in matches:
jenni.msg('NickServ', 'ACC ' + x)
auth_request.rule = r'.*'
auth_request.priority = 'high'
def auth_verify(jenni, input):
"""
This will wait for notices from NickServ and scan for ACC
responses. This verifies with NickServ that nicks in the room
are identified with NickServ so that they cannot be spoofed.
May only work with freenode.
"""
global auth_list
nick = input.group(1)
level = input.group(3)
if input.nick != 'NickServ':
return
elif level == '3':
if nick in auth_list:
return
else:
auth_list.append(nick)
else:
if nick not in auth_list:
return
else:
auth_list.remove(nick)
auth_verify.event = 'NOTICE'
auth_verify.rule = r'(\S+) (ACC) ([0-3])'
auth_verify.priority = 'high'
def auth_check(jenni, nick, target=None):
"""
Checks if nick is on the auth list and returns true if so
"""
global auth_list
if target == jenni.config.nick:
return 0
elif nick in auth_list:
return 1
def deauth(nick):
"""
Remove people from the deauth list.
"""
global auth_list
if nick in auth_list:
a = auth_list.index(nick)
del(auth_list[a])
def deauth_quit(jenni, input):
deauth(input.nick)
deauth_quit.event = 'QUIT'
deauth_quit.rule = '.*'
def deauth_part(jenni, input):
deauth(input.nick)
deauth_part.event = 'PART'
deauth_part.rule = '.*'
def deauth_nick(jenni, input):
deauth(input.nick)
deauth_nick.event = 'NICK'
deauth_nick.rule = '.*'
def kick(jenni, input):
if not input.admin: return
text = input.group().split()
argc = len(text)
if argc < 2: return
opt = text[1]
nick = opt
channel = input.sender
reasonidx = 2
if opt.startswith('#'):
if argc < 3: return
nick = text[2]
channel = opt
reasonidx = 3
reason = ' '.join(text[reasonidx:])
if nick != jenni.config.nick:
jenni.write(['KICK', channel, nick, reason])
kick.commands = ['kick']
kick.priority = 'high'
def configureHostMask (mask):
if mask == '*!*@*': return mask
if re.match('^[^.@!/]+$', mask) is not None: return '%s!*@*' % mask
if re.match('^[^@!]+$', mask) is not None: return '*!*@%s' % mask
m = re.match('^([^!@]+)@$', mask)
if m is not None: return '*!%s@*' % m.group(1)
m = re.match('^([^!@]+)@([^@!]+)$', mask)
if m is not None: return '*!%s@%s' % (m.group(1), m.group(2))
m = re.match('^([^!@]+)!(^[!@]+)@?$', mask)
if m is not None: return '%s!%s@*' % (m.group(1), m.group(2))
return ''
def ban (jenni, input):
"""
This give admins the ability to ban a user.
The bot must be a Channel Operator for this command to work.
"""
if not input.admin: return
text = input.group().split()
argc = len(text)
if argc < 2: return
opt = text[1]
banmask = opt
channel = input.sender
if opt.startswith('#'):
if argc < 3: return
channel = opt
banmask = text[2]
banmask = configureHostMask(banmask)
if banmask == '': return
jenni.write(['MODE', channel, '+b', banmask])
ban.commands = ['ban']
ban.priority = 'high'
def unban (jenni, input):
"""
This give admins the ability to unban a user.
The bot must be a Channel Operator for this command to work.
"""
if not input.admin: return
text = input.group().split()
argc = len(text)
if argc < 2: return
opt = text[1]
banmask = opt
channel = input.sender
if opt.startswith('#'):
if argc < 3: return
channel = opt
banmask = text[2]
banmask = configureHostMask(banmask)
if banmask == '': return
jenni.write(['MODE', channel, '-b', banmask])
unban.commands = ['unban']
unban.priority = 'high'
def quiet (jenni, input):
"""
This gives admins the ability to quiet a user.
The bot must be a Channel Operator for this command to work
"""
if not input.admin: return
text = input.group().split()
argc = len(text)
if argc < 2: return
opt = text[1]
quietmask = opt
channel = input.sender
if opt.startswith('#'):
if argc < 3: return
quietmask = text[2]
channel = opt
quietmask = configureHostMask(quietmask)
if quietmask == '': return
jenni.write(['MODE', channel, '+q', quietmask])
quiet.commands = ['quiet']
quiet.priority = 'high'
def unquiet (jenni, input):
"""
This gives admins the ability to unquiet a user.
The bot must be a Channel Operator for this command to work
"""
if not input.admin: return
text = input.group().split()
argc = len(text)
if argc < 2: return
opt = text[1]
quietmask = opt
channel = input.sender
if opt.startswith('#'):
if argc < 3: return
quietmask = text[2]
channel = opt
quietmask = configureHostMask(quietmask)
if quietmask == '': return
jenni.write(['MODE', opt, '-q', quietmask])
unquiet.commands = ['unquiet']
unquiet.priority = 'high'
def kickban (jenni, input):
"""
This gives admins the ability to kickban a user.
The bot must be a Channel Operator for this command to work
.kickban [#chan] user1 user!*@* get out of here
"""
if not input.admin: return
text = input.group().split()
argc = len(text)
if argc < 4: return
opt = text[1]
nick = opt
mask = text[2]
reasonidx = 3
if opt.startswith('#'):
if argc < 5: return
channel = opt
nick = text[2]
mask = text[3]
reasonidx = 4
reason = ' '.join(text[reasonidx:])
mask = configureHostMask(mask)
if mask == '': return
jenni.write(['MODE', channel, '+b', mask])
jenni.write(['KICK', channel, nick, ' :', reason])
kickban.commands = ['kickban', 'kb']
kickban.priority = 'high'
def topic(jenni, input):
"""
This gives admins the ability to change the topic.
Note: One does *NOT* have to be an OP, one just has to be on the list of
admins.
"""
if not input.admin:
return
text = input.group().split()
topic = ' '.join(text[1:])
if topic == '':
return
channel = input.sender
jenni.write(['PRIVMSG', 'ChanServ'], 'TOPIC %s %s' % (input.sender, topic))
return
topic.commands = ['topic']
topic.priority = 'low'
if __name__ == '__main__':
print __doc__.strip()