]>
Commit | Line | Data |
---|---|---|
b069ba10 JR |
1 | from classes import * |
2 | from util import * | |
3 | ||
4 | name = 'auth' | |
5 | def init(cache): | |
6 | cache.currmod = __name__ | |
7 | cache.hookcmd('AUTH', 0, auth, 0, helpauth, isadmin=True) | |
8 | cache.hookcmd('WHOIS', 1, whois, 1, helpwhois, isadmin=True) | |
9 | cache.hookcmd('WHOAMI', 0, whoami, 0, helpwhoami, isadmin=True) | |
10 | cache.hooknum('354', rep_who) | |
11 | cache.hooknum('353', rep_names) | |
12 | def deinit(cache, reloading=False): | |
13 | cache.currmod = __name__ | |
14 | cache.unhookcmd('AUTH') | |
15 | cache.unhookcmd('WHOIS') | |
16 | cache.unhookcmd('WHOAMI') | |
17 | cache.unhooknum('354', rep_who) | |
18 | cache.unhooknum('353', rep_names) | |
19 | ||
20 | def auth(nick, target, params, bot, cache): | |
21 | bot.raw("WHO %s n%%hna" % (nick)) | |
22 | bot.msg(nick, "Looking up your auth...") | |
23 | ||
24 | def whois(nick, target, params, bot, cache): | |
25 | lookup = params.split()[0] | |
26 | if lookup[0] == '*': | |
27 | if cache.users[nick].access >= 1: | |
28 | lookup = lookup[1:] | |
29 | bid = toint(lookup) | |
30 | bot2 = None | |
31 | if bid is None: | |
32 | if lookup in cache.botsByNick: | |
33 | bot2 = cache.botsByNick[lookup] | |
34 | else: | |
35 | if bid in bot2s: | |
36 | bot2 = bot2s[bid] | |
37 | if bot2 is not None: | |
38 | bot.msg(nick, "Bot #%d ..." % (bot2.id)) | |
39 | ||
40 | if bot2.nick: bot.msg(nick, "- nick: %s" % (bot2.nick)) | |
41 | else: bot.msg(nick, "- doesn't know it's nick") | |
42 | ||
43 | if bot2.online: bot.msg(nick, "- is online") | |
44 | else: bot.msg(nick, "- is offline") | |
45 | ||
46 | if bot2.mainbot: bot.msg(nick, "- is the mainbot") | |
47 | else: bot.msg(nick, "- is not the mainbot") | |
48 | ||
49 | if len(bot2.rawqueue) != 0: bot.msg(nick, "- has %d lines in queue" % (len(bot2.rawqueue))) | |
50 | else: bot.msg(nick, "- has an empty queue") | |
51 | ||
52 | if len(bot2.chans) != 0: bot.msg(nick, "- in %s" % (' '.join([chan.name for chan in bot2.chans.values()]))) | |
53 | else: bot.msg(nick, "- is in no channels.") | |
54 | ||
55 | bot.msg(nick, "End info for bot #%d" % (bot2.id)) | |
56 | else: | |
57 | bot.msg(nick, "No such bot %s" % (lookup)) | |
58 | elif lookup[0] != '#': | |
59 | if lookup in cache.users: | |
60 | auth = cache.users[lookup].auth | |
61 | access = cache.users[lookup].access | |
62 | bot.msg(nick, "%s is #%s (access: %d)" % (lookup, auth, access)) | |
63 | else: | |
64 | bot.msg(nick, "%s is not a known user." % (lookup)) | |
65 | return | |
66 | else: | |
67 | auth = lookup[1:] | |
68 | curs = cache.dbc.cursor() | |
69 | curs.execute("SELECT level FROM admins WHERE username = %s", (auth,)) | |
70 | row = curs.fetchone() | |
71 | if row is not None: | |
72 | bot.msg(nick, "%s (access: %d)" % (lookup, row['level'])) | |
73 | else: | |
74 | bot.msg(nick, "%s is unknown." % (lookup)) | |
75 | ||
76 | def whoami(nick, target, params, bot, cache): | |
77 | if nick in cache.users and cache.users[nick].access != -1: | |
78 | bot.msg(nick, "You are %s (#%s access: %d)" % (nick, cache.users[nick].auth, cache.users[nick].access)) | |
79 | ||
80 | curs = cache.dbc.cursor() | |
81 | curs.execute("SELECT chans.chname AS ch, chusers.level AS level FROM chans, chusers WHERE chans.id = chusers.chid AND chusers.authname = %s", (cache.users[nick].auth,)) | |
82 | rows = curs.fetchall() | |
83 | if len(rows) != 0: | |
84 | bot.msg(nick, "-- CHANNELS:") | |
85 | for row in rows: | |
86 | bot.msg(nick, "%s - level %d" % (row['ch'], row['level'])) | |
87 | bot.msg(nick, "-- END OF CHANNELS") | |
88 | else: | |
89 | bot.msg(nick, "You are %s (unknown auth)" % (nick)) | |
90 | ||
91 | def rep_who(line, bot): # :<server.tld> 354 <self> <host> <nick> <auth> | |
92 | pieces = line.split() | |
93 | host = pieces[3] | |
94 | nick = pieces[4] | |
95 | auth = pieces[5] | |
96 | if nick not in cache.users: | |
97 | cache.users[nick] = User(nick) | |
98 | user = cache.users[nick] | |
99 | user.host = host | |
100 | cache.users[nick].authed(auth) | |
101 | ||
102 | def rep_names(line, bot): # :<server.tld> 353 <self> = <#chan> :jrunyon @Ophion +BiohZn @Q +DimeCadmium | |
103 | pieces = line.split() | |
104 | chan = pieces[4] | |
105 | nicksidx = line.find(':', 1) | |
106 | nicks = line[nicksidx+1:].split() | |
107 | for nick in nicks: | |
108 | mode = nick[0] | |
109 | if mode == '@' or mode == '+': | |
110 | chlevel = mode | |
111 | nick = nick[1:] | |
112 | else: | |
113 | chlevel = None | |
114 | if nick != bot.nick: bot.joined(chan, nick, chlevel) | |
115 | ||
116 | ||
117 | def helpauth(): return ['AUTH', 'Requests the bot to look up your account.'] | |
118 | def helpwhois(): return ['WHOIS <nick|#auth>', 'Shows info about an account with the bot.'] | |
119 | def helpwhoami(): return ['WHOAMI', 'Shows info about your account with the bot.'] |