diff -r f899af683bbe -r aeb0d0788869 mod_util.py --- a/mod_util.py Sat Apr 11 21:02:54 2015 +0300 +++ b/mod_util.py Sun Apr 19 19:45:42 2015 +0300 @@ -6,6 +6,7 @@ from modulecore import command_error import modulecore as ModuleCore import utility +import calc ModuleData = { 'commands': @@ -46,6 +47,13 @@ }, { + 'name': 'calcfunctions', + 'description': 'Lists the functions supported by .calc', + 'args': None, + 'level': 'normal', + }, + + { 'name': 'more', 'description': 'Prints subsequent command result pages', 'args': None, @@ -160,30 +168,34 @@ return expr -def cmd_calc (bot, reply, args, **rest): - expr = args['expression'] +def cmd_calcfunctions (bot, reply, **rest): + reply ('Available functions for .calc: %s' % \ + ', '.join (sorted ([name for name, data in calc.Functions.iteritems()]))) - try: +def cmd_calc (bot, reply, args, **rest): + reply (calc.calc (args['expression'])) + # expr = args['expression'] + # try: # Substitute some mathematical constants - expr = mathsubstitute (expr, 'pi' , 3.14159265358979323846264338327950288419716939937510) - expr = mathsubstitute (expr, 'e' , 2.71828182845904523536028747135266249775724709369995) - expr = mathsubstitute (expr, 'phi', 1.6180339887498948482) # golden ratio + # expr = mathsubstitute (expr, 'pi' , 3.14159265358979323846264338327950288419716939937510) + # expr = mathsubstitute (expr, 'e' , 2.71828182845904523536028747135266249775724709369995) + # expr = mathsubstitute (expr, 'phi', 1.6180339887498948482) # golden ratio - result = subprocess.check_output (['calc', '--', expr], stderr=subprocess.STDOUT) \ - .replace ('\t', '') \ - .replace ('\n', '') + # result = subprocess.check_output (['calc', '--', expr], stderr=subprocess.STDOUT) \ + # .replace ('\t', '') \ + # .replace ('\n', '') - errmatch = re.compile (r'^.*\bError\b.*$').match (result) + # errmatch = re.compile (r'^.*\bError\b.*$').match (result) - if errmatch: - command_error ('math error') - return + # if errmatch: + # command_error ('math error') + # return - 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) + # 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 (commandObject, **rest): ModuleCore.print_responses (commandObject)