diff -r 384167adad2b -r 20bd76353eb5 mod_admin.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_admin.py Sun Nov 09 19:13:08 2014 +0200 @@ -0,0 +1,59 @@ +from modulecore import command_error +import hgapi + +ModuleData = { + 'commands': + [ + { + 'name': 'raw', + 'description': 'Sends a raw message to the server', + 'args': '', + 'level': 'admin', + }, + + { + 'name': 'msg', + 'description': 'Sends a message to someone', + 'args': ' ', + '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' + } + ] +} + +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_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))