aboutsummaryrefslogtreecommitdiff
path: root/cogs
diff options
context:
space:
mode:
authorMango0x45 <thomasvoss@live.com>2021-01-03 15:34:23 +0000
committerMango0x45 <thomasvoss@live.com>2021-01-03 15:34:23 +0000
commit010fd353d4c57bad9c6f47cac881d725a006423e (patch)
tree669b630c2f4b5f83237c80ff58c86e54b03420ee /cogs
parent24d974befc8307138384c27d604c8b220201d83a (diff)
downloadsteve-bot-010fd353d4c57bad9c6f47cac881d725a006423e.tar
steve-bot-010fd353d4c57bad9c6f47cac881d725a006423e.tar.gz
steve-bot-010fd353d4c57bad9c6f47cac881d725a006423e.tar.bz2
steve-bot-010fd353d4c57bad9c6f47cac881d725a006423e.tar.lz
steve-bot-010fd353d4c57bad9c6f47cac881d725a006423e.tar.xz
steve-bot-010fd353d4c57bad9c6f47cac881d725a006423e.tar.zst
steve-bot-010fd353d4c57bad9c6f47cac881d725a006423e.zip
Try to make math work with BC functions
Diffstat (limited to 'cogs')
-rwxr-xr-xcogs/utils.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/cogs/utils.py b/cogs/utils.py
index ee40900..9f7ba66 100755
--- a/cogs/utils.py
+++ b/cogs/utils.py
@@ -439,9 +439,17 @@ class Utils(commands.Cog):
await ctx.send(f"```List of custom commands:\n{output}```")
@commands.command(aliases=["calc"])
- async def math(self, ctx, *, eqn):
+ async def math(self, ctx, *, eqn: str):
+ bc_funcs = r"/home/thomas/Steve-Bot/bc_funcs"
+
try:
- result = subprocess.check_output(f"echo '{eqn}' | bc", shell=True)
+ # Allow for proper absolute value notation
+ pipes = eqn.count("|")
+ eqn = eqn.replace("|", "abs(", pipes // 2).replace("|", ")", pipes // 2)
+
+ result = subprocess.check_output(
+ f"echo '{eqn}' | bc -f */{bc_funcs}", shell=True
+ )
await ctx.send(result.decode("utf-8").replace("\\\n", "").strip())
except subprocess.CalledProcessError as err:
print(err)