mod_util.py

changeset 104
27294de7b0d3
parent 102
2bad379cd416
child 105
84bd617a2520
equal deleted inserted replaced
103:e4891ab34fb1 104:27294de7b0d3
1 import math 1 import math
2 import urllib2 2 import urllib2
3 import json 3 import json
4 from modulecore import command_error 4 from modulecore import command_error
5 import modulecore as ModuleCore
5 6
6 ModuleData = { 7 ModuleData = {
7 'commands': 8 'commands':
8 [ 9 [
9 { 10 {
15 16
16 { 17 {
17 'name': 'ud', 18 'name': 'ud',
18 'description': 'Looks up a term in urban dictionary', 19 'description': 'Looks up a term in urban dictionary',
19 'args': '<term...>', 20 'args': '<term...>',
21 'level': 'normal',
22 },
23
24 {
25 'name': 'commands',
26 'description': 'Lists commands available to the calling user',
27 'args': None,
28 'level': 'normal',
29 },
30
31 {
32 'name': 'help',
33 'description': 'Prints help about a given command',
34 'args': '<command>',
20 'level': 'normal', 35 'level': 'normal',
21 }, 36 },
22 ] 37 ]
23 } 38 }
24 39
69 up = data['list'][0]['thumbs_up'] 84 up = data['list'][0]['thumbs_up']
70 down = data['list'][0]['thumbs_down'] 85 down = data['list'][0]['thumbs_down']
71 bot.privmsg (replyto, "\002%s\002: %s\0033 %d\003 up,\0035 %d\003 down" % (word, definition, up, down)) 86 bot.privmsg (replyto, "\002%s\002: %s\0033 %d\003 up,\0035 %d\003 down" % (word, definition, up, down))
72 except Exception as e: 87 except Exception as e:
73 command_error ('Urban dictionary lookup failed: %s' % e) 88 command_error ('Urban dictionary lookup failed: %s' % e)
89
90 def cmd_commands (bot, replyto, ident, host, **rest):
91 commandlist = ModuleCore.get_available_commands (ident, host)
92 partitioned=[]
93
94 while len (commandlist) > 0:
95 partitioned.append (commandlist[0:15])
96 commandlist = commandlist[15:]
97
98 for part in partitioned:
99 bot.privmsg (replyto, 'Available commands: %s' % (", ".join (part)))
100
101 def cmd_help (bot, replyto, ident, host, args, **rest):
102 cmd = ModuleCore.get_command_by_name (args['command'])
103
104 if not cmd:
105 command_error ('unknown command \'%s\'' % args['command'])
106
107 if not ModuleCore.is_available (cmd, ident, host):
108 command_error ('you may not use %s' % cmd['name'])
109
110 bot.privmsg (replyto, '%s %s: %s' % (cmd['name'], cmd['args'], cmd['description']))

mercurial