--- a/cmd_config.py Wed Nov 05 01:38:08 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -from commandhandler import command_error -import hgapi - -ModuleData = { - 'commands': - [ - { - 'name': 'addchan', - 'description': 'Adds a channel to config', - 'args': '<channel>', - 'level': 'admin', - }, - - { - 'name': 'delchan', - 'description': 'Deletes a channel from config', - 'args': '<channel>', - 'level': 'admin', - }, - - { - 'name': 'chanattr', - 'description': 'Get or set a channel-specific attribute', - 'args': '<channel> <key> [value...]', - 'level': 'admin', - }, - ] -} - -def cmd_addchan (bot, args, **rest): - for channel in bot.channels: - if channel['name'].upper() == args['channel'].upper(): - command_error ('I already know of %s!' % args['channel']) - #done - - chan = {} - chan['name'] = args['channel'] - chan['logchannel'] = False - bot.channels.append (chan) - bot.write ('JOIN ' + chan['name']) - bot.save_config() -#enddef - -def cmd_delchan (bot, args, **rest): - for channel in bot.channels: - if channel['name'].upper() == args['channel'].upper(): - break; - else: - command_error ('unknown channel ' + args['channel']) - - bot.channels.remove (channel) - bot.write ('PART ' + args['channel']) - bot.save_config() -#enddef - -def bool_from_string (value): - if value != 'true' and value != 'false': - command_error ('expected true or false for value') - - return True if value == 'true' else False -#enddef - -def cmd_chanattr (bot, args, replyto, **rest): - for channel in bot.channels: - if channel['name'] == args['channel']: - break - else: - command_error ('I don\'t know of a channel named ' + args['channel']) - - key = args['key'] - value = args['value'] - - if value == '': - try: - bot.privmsg (replyto, '%s = %s' % (key, channel[key])) - except KeyError: - bot.privmsg (replyto, 'attribute %s is not set' % key) - return - #fi - - if key == 'name': - if replyto == channel['name']: - replyto = value - - bot.write ('PART ' + channel['name']) - channel['name'] = value - bot.write ('JOIN ' + channel['name'] + ' ' + (channel['password'] if hasattr (channel, 'password') else '')) - elif key == 'password': - channel['password'] = value - elif key == 'btannounce': - channel['btannounce'] = bool_from_string (value) - elif key == 'btprivate': - channel['btprivate'] = bool_from_string (value) - elif key == 'logchannel': - channel['logchannel'] = bool_from_string (value) - else: - command_error ('unknown key ' + key) - #fi - - bot.privmsg (replyto, '%s is now %s' % (key, channel[key])) - bot.save_config() -#enddef \ No newline at end of file