1 from commandhandler import command_error |
|
2 import hgapi |
|
3 |
|
4 ModuleData = { |
|
5 'commands': |
|
6 [ |
|
7 { |
|
8 'name': 'addchan', |
|
9 'description': 'Adds a channel to config', |
|
10 'args': '<channel>', |
|
11 'level': 'admin', |
|
12 }, |
|
13 |
|
14 { |
|
15 'name': 'delchan', |
|
16 'description': 'Deletes a channel from config', |
|
17 'args': '<channel>', |
|
18 'level': 'admin', |
|
19 }, |
|
20 |
|
21 { |
|
22 'name': 'chanattr', |
|
23 'description': 'Get or set a channel-specific attribute', |
|
24 'args': '<channel> <key> [value...]', |
|
25 'level': 'admin', |
|
26 }, |
|
27 ] |
|
28 } |
|
29 |
|
30 def cmd_addchan (bot, args, **rest): |
|
31 for channel in bot.channels: |
|
32 if channel['name'].upper() == args['channel'].upper(): |
|
33 command_error ('I already know of %s!' % args['channel']) |
|
34 #done |
|
35 |
|
36 chan = {} |
|
37 chan['name'] = args['channel'] |
|
38 chan['logchannel'] = False |
|
39 bot.channels.append (chan) |
|
40 bot.write ('JOIN ' + chan['name']) |
|
41 bot.save_config() |
|
42 #enddef |
|
43 |
|
44 def cmd_delchan (bot, args, **rest): |
|
45 for channel in bot.channels: |
|
46 if channel['name'].upper() == args['channel'].upper(): |
|
47 break; |
|
48 else: |
|
49 command_error ('unknown channel ' + args['channel']) |
|
50 |
|
51 bot.channels.remove (channel) |
|
52 bot.write ('PART ' + args['channel']) |
|
53 bot.save_config() |
|
54 #enddef |
|
55 |
|
56 def bool_from_string (value): |
|
57 if value != 'true' and value != 'false': |
|
58 command_error ('expected true or false for value') |
|
59 |
|
60 return True if value == 'true' else False |
|
61 #enddef |
|
62 |
|
63 def cmd_chanattr (bot, args, replyto, **rest): |
|
64 for channel in bot.channels: |
|
65 if channel['name'] == args['channel']: |
|
66 break |
|
67 else: |
|
68 command_error ('I don\'t know of a channel named ' + args['channel']) |
|
69 |
|
70 key = args['key'] |
|
71 value = args['value'] |
|
72 |
|
73 if value == '': |
|
74 try: |
|
75 bot.privmsg (replyto, '%s = %s' % (key, channel[key])) |
|
76 except KeyError: |
|
77 bot.privmsg (replyto, 'attribute %s is not set' % key) |
|
78 return |
|
79 #fi |
|
80 |
|
81 if key == 'name': |
|
82 if replyto == channel['name']: |
|
83 replyto = value |
|
84 |
|
85 bot.write ('PART ' + channel['name']) |
|
86 channel['name'] = value |
|
87 bot.write ('JOIN ' + channel['name'] + ' ' + (channel['password'] if hasattr (channel, 'password') else '')) |
|
88 elif key == 'password': |
|
89 channel['password'] = value |
|
90 elif key == 'btannounce': |
|
91 channel['btannounce'] = bool_from_string (value) |
|
92 elif key == 'btprivate': |
|
93 channel['btprivate'] = bool_from_string (value) |
|
94 elif key == 'logchannel': |
|
95 channel['logchannel'] = bool_from_string (value) |
|
96 else: |
|
97 command_error ('unknown key ' + key) |
|
98 #fi |
|
99 |
|
100 bot.privmsg (replyto, '%s is now %s' % (key, channel[key])) |
|
101 bot.save_config() |
|
102 #enddef |
|