cmd_admin.py

changeset 65
20bd76353eb5
parent 64
384167adad2b
child 66
74d8ca04ff01
equal deleted inserted replaced
64:384167adad2b 65:20bd76353eb5
1 from commandhandler import command_error
2 import hgapi
3
4 ModuleData = {
5 'commands':
6 [
7 {
8 'name': 'raw',
9 'description': 'Sends a raw message to the server',
10 'args': '<message...>',
11 'level': 'admin',
12 },
13
14 {
15 'name': 'msg',
16 'description': 'Sends a message to someone',
17 'args': '<recipient> <message...>',
18 'level': 'admin',
19 },
20
21 {
22 'name': 'restart',
23 'description': 'Restarts the bot',
24 'args': None,
25 'level': 'admin',
26 },
27
28 {
29 'name': 'update',
30 'description': 'Checks for updates on the bot',
31 'args': None,
32 'level': 'admin'
33 }
34 ]
35 }
36
37 def cmd_raw (bot, args, **rest):
38 bot.write (args['message'])
39
40 def cmd_msg (bot, args, **rest):
41 bot.privmsg (args['recipient'], args['message'])
42
43 def cmd_restart (bot, **rest):
44 bot.restart()
45
46 def cmd_update (bot, replyto, **rest):
47 try:
48 repo = hgapi.Repo ('.')
49 r1 = repo.hg_id()
50 repo.hg_pull()
51 repo.hg_update('tip', True)
52 r2 = repo.hg_id()
53 if r1 != r2:
54 bot.privmsg (replyto, 'Updated to %s, restarting...' % r2)
55 bot.restart()
56 else:
57 bot.privmsg (replyto, 'Up to date at %s.' % r2)
58 except hgapi.HgException as e:
59 command_error ('Update failed: %s' % str (e))

mercurial