diff options
author | PanFritz <redstonenoobpan@gmail.com> | 2015-01-13 13:12:00 +0100 |
---|---|---|
committer | PanFritz <redstonenoobpan@gmail.com> | 2015-01-13 13:12:00 +0100 |
commit | 197ef515b9c218d9c630d44cd6687b0235fc3db3 (patch) | |
tree | 74c68c12871f9283ca33684b9eeb48d9c81bed84 /calc.py | |
parent | 89c5c3e64606276013cfd4c272fbf688a895ed40 (diff) |
Reverted changes
Diffstat (limited to 'calc.py')
-rw-r--r-- | calc.py | 19 |
1 files changed, 8 insertions, 11 deletions
@@ -1,7 +1,7 @@ from helpers import * calc_users = open_json_file("calc", []) -math_operators = ["+", "-", "*", "/", "&", "|", ">", "<", "~", "%"] +math_operators = ["+", "-", "*", "/", "&", "|"] ignore_operators = ["**", "&&", "||"] # ** may be too intensive, the others cause syntax errors calc_perm = "utils.calc" @@ -12,7 +12,6 @@ def calc(text): returns (expression, result) or None """ expression = "" - d_expression = "" should_calc = False for char in text: if char.isdigit() or (should_calc and char in [".", " "]): @@ -21,19 +20,17 @@ def calc(text): # calculation must include at least 1 operator should_calc = True expression += char - elif char.isalpha(): + elif should_calc and char.isalpha(): # don't include any more text in the calculation - if should_calc: - d_expression = expression - expression = "" - if should_calc and not any(op in d_expression for op in ignore_operators): + break + if should_calc and not any(op in expression for op in ignore_operators): try: - result = str(eval(d_expression)) # pylint: disable = W0123 + result = str(eval(expression)) # pylint: disable = W0123 except: # pylint: disable = W0702 # we can run into all kinds of errors here # most probably SyntaxError return None - return (d_expression, result) + return (expression, result) return None @@ -43,8 +40,8 @@ def on_calc_chat(event): message = event.getMessage() if not event.isCancelled() and uid(sender) in calc_users and sender.hasPermission(calc_perm): output = calc(message) - if type(output)in [int, float, long, complex]: - msg(sender, "&2=== Calc: &e" + output[0] + " &2= &c" + str(output[1]).replace("420", "blazeit")) + if output: + msg(sender, "&2=== Calc: &e" + output[0] + " &2= &c" + output[1]) @hook.command("calc", description="Toggles chat calculations") |