-
Notifications
You must be signed in to change notification settings - Fork 6
/
op.py
53 lines (47 loc) · 1.28 KB
/
op.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
# vim:set ts=8 sts=8 sw=8 tw=80 noet cc=80:
class Operators(object):
def __init__(self, storage, config):
self.storage = storage
try:
self.ops = storage['op']
except:
self.ops = [ op.strip() for op in config.split(",") ]
for nick in config.split(","):
if not self.is_op(nick.strip()):
self.ops += [ nick.strip() ]
def op(self, nick):
if not nick in self.ops:
self.ops += [ nick ]
self.storage['op'] = self.ops
def deop(self, nick):
if not nick in self.ops:
return
index = self.ops.index(nick)
del self.ops[index]
self.storage['op'] = self.ops
def is_op(self, nick):
return nick in self.ops
def show_handler(self, *args, **keywords):
send_message = keywords['send_message']
if len(args) == 0:
send_message('ops: %s' % ", ".join(self.ops))
def config_handler(self, undo, *args, **keywords):
send_message = keywords['send_message']
if len(args) == 0:
print("args: %s" % args)
return
nick = " ".join(args)
if nick == keywords['nick']:
return
if undo:
if self.is_op(nick):
self.deop(nick)
send_message('deoped "%s"' % nick)
else:
send_message('"%s" is not an op' % nick)
else:
if self.is_op(nick):
send_message('"%s" is already an op' % nick)
else:
self.op(nick)
send_message('oped "%s"' % nick)