Mon, 10 Nov 2014 02:06:06 +0200
- modularization complete!!
from modulecore import command_error import hgapi ModuleData = { 'commands': [ { 'name': 'raw', 'description': 'Sends a raw message to the server', 'args': '<message...>', 'level': 'admin', }, { 'name': 'msg', 'description': 'Sends a message to someone', 'args': '<recipient> <message...>', 'level': 'admin', }, { 'name': 'restart', 'description': 'Restarts the bot', 'args': None, 'level': 'admin', }, { 'name': 'update', 'description': 'Checks for updates on the bot', 'args': None, 'level': 'admin' }, { 'name': 'die', 'description': 'Shuts the bot down', 'args': None, 'level': 'admin', }, ] } def cmd_raw (bot, args, **rest): bot.write (args['message']) def cmd_msg (bot, args, **rest): bot.privmsg (args['recipient'], args['message']) def cmd_restart (bot, **rest): bot.restart() def cmd_die (bot, **rest): quit() def cmd_update (bot, replyto, **rest): try: repo = hgapi.Repo ('.') r1 = repo.hg_id() repo.hg_pull() repo.hg_update('tip', True) r2 = repo.hg_id() if r1 != r2: bot.privmsg (replyto, 'Updated to %s, restarting...' % r2) bot.restart() else: bot.privmsg (replyto, 'Up to date at %s.' % r2) except hgapi.HgException as e: command_error ('Update failed: %s' % str (e))