]> jfr.im git - z_archive/Ophion.git/blame - modules/autoload/chlevel.py
Initialize repo
[z_archive/Ophion.git] / modules / autoload / chlevel.py
CommitLineData
b069ba10
JR
1from classes import *
2from util import *
3
4name = 'channel modes'
5def init(cache):
6 cache.currmod = __name__
7 cache.hookcmd('CHANLEV', 1, chanlev, 0, helpchanlev)
8def deinit(cache, reloading=False):
9 cache.currmod = __name__
10 cache.unhookcmd('CHANLEV')
11
12def chanlev(nick, target, params, bot, cache):
13 pieces = params.split()
14 user = cache.users[nick]
15 chan = cache.chans[target]
16
17 if len(pieces) == 0:
18 bot.msg(nick, "-- ACCESS LIST FOR %s" % (target))
19 for authname, access in chan.alist.items():
20 bot.msg(nick, "%-15s %s" % (authname, access))
21 bot.msg(nick, "-- END OF ACCESS LIST")
22 elif len(pieces) == 1:
23 if pieces[0][0] == '#':
24 auth = pieces[0][1:]
25 bot.msg(nick, "Auth %s has level %s on %s" % (auth, chan.alist[auth], target))
26 elif pieces[0] in cache.users:
27 auth = cache.users[pieces[0]].auth
28 bot.msg(nick, "Nick %s has level %s on %s" % (pieces[0], chan.alist[auth], target))
29 else:
30 bot.msg(nick, "%s is unknown." % (pieces[0]))
31 elif len(pieces) == 2:
32 auth = user.auth
33 if auth in chan.alist and chan.alist[auth] >= 4:
34 level = chan.alist[auth]
35 if pieces[0][0] == '#':
36 targauth = pieces[0][1:]
37 elif pieces[0] in cache.users:
38 targauth = cache.users[pieces[0]].auth
39 else:
40 bot.msg(nick, "%s is unknown." % (pieces[0]))
41 return
42 targlev = toint(pieces[1])
43 if targlev is None or targlev > 5:
44 bot.msg(nick, "Invalid level %d." % (targlev))
45 return
46 if level != 5:
47 if targauth in chan.alist and chan.alist[targauth] >= level:
48 noaccess(bot, nick, True)
49 return
50 if targlev >= level:
51 noaccess(bot, nick, True)
52 return
53 if targlev != 0:
54 chan.alist[targauth] = targlev
55 curs = cache.dbc.cursor()
56 curs.execute("REPLACE INTO chusers(chid, authname, level) VALUES (%s, %s, %s)", (chan.id, targauth, targlev))
57 curs.close()
58 elif targauth in chan.alist:
59 del chan.alist[targauth]
60 curs = cache.dbc.cursor()
61 curs.execute("DELETE FROM chusers WHERE chid = %s AND authname = '%s'" % (chan.id, targauth))
62 curs.close()
63 bot.msg(nick, "Done.")
64 else:
65 noaccess(bot, nick, True)
66 else:
67 bot.msg(nick, "Invalid syntax. Usage: CHANLEV <#channel> [<nick|#auth> [<level>]]")
68
69def helpchanlev():
70 return ['CHANLEV <#channel> [<nick|#auth> [<level>]]', 'Change or view access.']