mod_util.py

changeset 152
1b734faab67a
parent 150
2fd1f6ee05f5
child 153
497b7290977d
equal deleted inserted replaced
151:e24793fae424 152:1b734faab67a
27 ''' 27 '''
28 28
29 from __future__ import print_function 29 from __future__ import print_function
30 import math 30 import math
31 import json 31 import json
32 import subprocess
33 import re 32 import re
34 from modulecore import command_error 33 from modulecore import command_error
35 import modulecore as ModuleCore 34 import modulecore as ModuleCore
36 import utility 35 import utility
37 import calc 36 import calc
208 reply ('Available functions for .calc: %s' % \ 207 reply ('Available functions for .calc: %s' % \
209 ', '.join (sorted ([name for name, data in calc.Functions.items()]))) 208 ', '.join (sorted ([name for name, data in calc.Functions.items()])))
210 209
211 def cmd_calc (bot, reply, args, **rest): 210 def cmd_calc (bot, reply, args, **rest):
212 reply (calc.Calculator().calc (args['expression'])) 211 reply (calc.Calculator().calc (args['expression']))
213 # expr = args['expression']
214 # try:
215 # Substitute some mathematical constants
216 # expr = mathsubstitute (expr, 'pi' , 3.14159265358979323846264338327950288419716939937510)
217 # expr = mathsubstitute (expr, 'e' , 2.71828182845904523536028747135266249775724709369995)
218 # expr = mathsubstitute (expr, 'phi', 1.6180339887498948482) # golden ratio
219
220 # result = subprocess.check_output (['calc', '--', expr], stderr=subprocess.STDOUT) \
221 # .replace ('\t', '') \
222 # .replace ('\n', '')
223
224 # errmatch = re.compile (r'^.*\bError\b.*$').match (result)
225
226 # if errmatch:
227 # command_error ('math error')
228 # return
229
230 # reply ('Result: %s' % result)
231 # except subprocess.CalledProcessError as e:
232 # command_error (e.output.split('\n')[0])
233 # except OSError as e:
234 # command_error ('failed to execute calc: ' + e.strerror)
235 212
236 def cmd_more (commandObject, **rest): 213 def cmd_more (commandObject, **rest):
237 ModuleCore.print_responses (commandObject) 214 ModuleCore.print_responses (commandObject)
238 215
239 def cmd_yes (**k): 216 def cmd_yes (**k):

mercurial