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