diff -r cdafc1a0544e -r 08e9b1c1b324 mod_util.py --- a/mod_util.py Wed Dec 31 10:27:57 2014 -0500 +++ b/mod_util.py Wed Dec 31 11:40:46 2014 -0500 @@ -43,11 +43,22 @@ 'args': '', 'level': 'normal', }, + + { + 'name': 'more', + 'description': 'Prints subsequent command result pages', + 'args': None, + 'level': 'normal', + }, ] } -def cmd_convert (bot, args, replyto, **rest): - value = float (args['value']) +def cmd_convert (bot, args, reply, **rest): + try: + value = float (args['value']) + except Exception as e: + command_error (str (e)) + valuetype = args['valuetype'] if valuetype in ['radians', 'degrees']: @@ -58,8 +69,7 @@ radvalue = (value * math.pi) / 180. degvalue = value - bot.privmsg (replyto, '%s radians, %s degrees (%s)' % - (radvalue, degvalue, degvalue % 360.)) + reply ('%s radians, %s degrees (%s)' % (radvalue, degvalue, degvalue % 360.)) return if valuetype in ['celsius', 'fahrenheit']: @@ -70,13 +80,13 @@ celvalue = (value - 32) / 1.8 fahrvalue = value - bot.privmsg (replyto, '%s degrees celsius, %s degrees fahrenheit' % (celvalue, fahrvalue)) + reply ('%s degrees celsius, %s degrees fahrenheit' % (celvalue, fahrvalue)) return command_error ('unknown valuetype %s, expected one of: degrees, radians (angle conversion), ' + 'celsius, fahrenheit (temperature conversion)' % valuetype) -def cmd_ud (bot, args, replyto, **rest): +def cmd_ud (bot, args, reply, **rest): try: url = 'http://api.urbandictionary.com/v0/define?term=%s' % (args['term'].replace (' ', '%20')) response = urllib2.urlopen (url).read() @@ -92,11 +102,11 @@ definition = data['list'][0]['definition'].replace ('\r', ' ').replace ('\n', ' ').replace (' ', ' ') up = data['list'][0]['thumbs_up'] down = data['list'][0]['thumbs_down'] - bot.privmsg (replyto, "\002%s\002: %s\0033 %d\003 up,\0035 %d\003 down" % (word, definition, up, down)) + reply ("\002%s\002: %s\0033 %d\003 up,\0035 %d\003 down" % (word, definition, up, down)) except Exception as e: command_error ('Urban dictionary lookup failed: %s' % e) -def cmd_commands (bot, replyto, ident, host, **rest): +def cmd_commands (bot, reply, ident, host, **rest): commandlist = ModuleCore.get_available_commands (ident, host) partitioned=[] @@ -105,9 +115,9 @@ commandlist = commandlist[15:] for part in partitioned: - bot.privmsg (replyto, '\002Available commands\002: %s' % (", ".join (part))) + reply ('\002Available commands\002: %s' % (", ".join (part))) -def cmd_help (bot, replyto, ident, host, args, **rest): +def cmd_help (bot, reply, ident, host, args, **rest): cmd = ModuleCore.get_command_by_name (args['command']) if not cmd: @@ -116,7 +126,7 @@ if not ModuleCore.is_available (cmd, ident, host): command_error ('you may not use %s' % cmd['name']) - bot.privmsg (replyto, '%s %s: %s' % (cmd['name'], cmd['args'], cmd['description'])) + reply ('%s %s: %s' % (cmd['name'], cmd['args'], cmd['description'])) def mathsubstitute (expr, token, value): rex = re.compile (r'^(.*)\b' + token + r'\b(.*)$') @@ -128,7 +138,7 @@ return expr -def cmd_calc (bot, replyto, args, **rest): +def cmd_calc (bot, reply, args, **rest): expr = args['expression'] try: @@ -147,8 +157,11 @@ command_error ('math error') return - bot.privmsg (replyto, 'Result: %s' % result) + reply ('Result: %s' % result) except subprocess.CalledProcessError as e: command_error (e.output.split('\n')[0]) except OSError as e: command_error ('failed to execute calc: ' + e.strerror) + +def cmd_more (bot, replyto, **rest): + ModuleCore.print_responses (bot, replyto)