From 70a99a590e55603bdd7425c0f51942dbd4e2a5da Mon Sep 17 00:00:00 2001 From: Mango0x45 Date: Sun, 3 Jan 2021 14:26:47 +0100 Subject: Add math command with BC --- cogs/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'cogs/utils.py') diff --git a/cogs/utils.py b/cogs/utils.py index 373b340..6ce4944 100755 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -2,6 +2,7 @@ import asyncio import datetime import functools import json +import subprocess from collections import namedtuple from datetime import timedelta # forgot to import this and ended up looking mentally unstable @@ -431,6 +432,15 @@ class Utils(commands.Cog): output = ", ".join([*commands]) await ctx.send(f"```List of custom commands:\n{output}```") + @commands.command(aliases=["calc"]) + async def math(self, ctx, eqn): + try: + result = subprocess.check_output(f"echo '{eqn}' | bc", shell=True) + await ctx.send(result.decode("utf-8").strip()) + except subprocess.CalledProcessError as err: + print(err) + await ctx.send("Something went wrong") + @commands.command() async def retime(self, ctx, start_sec, end_sec, frames=0, framerate=30): """Retimes a run using the start/end timestamps, leftover frames, and framerate""" -- cgit v1.2.3 From 595640b642c2b10d580a9dddc3c872e51a8cb6e1 Mon Sep 17 00:00:00 2001 From: Mango0x45 Date: Sun, 3 Jan 2021 14:30:37 +0100 Subject: This code isnt working atm --- cogs/utils.py | 106 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 53 insertions(+), 53 deletions(-) (limited to 'cogs/utils.py') diff --git a/cogs/utils.py b/cogs/utils.py index bbe43a3..266123f 100755 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -13,21 +13,21 @@ import discord from discord.ext import commands, tasks # from PIL.Image import core as Image # import image as Image -from PIL import Image, ImageFilter -from selenium import webdriver -from selenium.webdriver.chrome.options import Options - - -def set_viewport_size(driver, width, height): - window_size = driver.execute_script( - """ - return [window.outerWidth - window.innerWidth + arguments[0], - window.outerHeight - window.innerHeight + arguments[1]]; - """, - width, - height, - ) - driver.set_window_size(*window_size) +# from PIL import Image, ImageFilter +# from selenium import webdriver +# from selenium.webdriver.chrome.options import Options + + +# def set_viewport_size(driver, width, height): +# window_size = driver.execute_script( +# """ +# return [window.outerWidth - window.innerWidth + arguments[0], +# window.outerHeight - window.innerHeight + arguments[1]]; +# """, +# width, +# height, +# ) +# driver.set_window_size(*window_size) async def reportStuff(self, ctx, message): @@ -46,44 +46,44 @@ async def reportStuff(self, ctx, message): await ctx.author.send("Report has been submitted") -def save_leaderboard(): - DRIVER = "/usr/lib/chromium-browser/chromedriver" - chrome_options = Options() - chrome_options.add_argument("--disable-dev-shm-usage") - chrome_options.add_argument("--headless") - chrome_options.add_argument("--no-sandbox") - chrome_options.add_argument("--disable-gpu") - # chrome_options.binary_location = "" - driver = webdriver.Chrome(DRIVER, chrome_options=chrome_options) - set_viewport_size(driver, 1000, 1100) - driver.get("https://aninternettroll.github.io/mcbeVerifierLeaderboard/") - screenshot = driver.find_element_by_id("table").screenshot("leaderboard.png") - driver.quit() - # transparency time - img = Image.open("leaderboard.png") - img = img.convert("RGB") - pallette = Image.open("palette.png") - pallette = pallette.convert("P") - img = img.quantize(colors=256, method=3, kmeans=0, palette=pallette) - img = img.convert("RGBA") - datas = img.getdata() - - newData = [] - for item in datas: - if item[0] == 255 and item[1] == 255 and item[2] == 255: - newData.append((255, 255, 255, 0)) - else: - newData.append(item) - - img.putdata(newData) - """ - img = img.filter(ImageFilter.SHARPEN) - img = img.filter(ImageFilter.SHARPEN) - img = img.filter(ImageFilter.SHARPEN) - """ - # height, width = img.size - # img = img.resize((height*10,width*10), resample=Image.BOX) - img.save("leaderboard.png", "PNG") +# def save_leaderboard(): +# DRIVER = "/usr/lib/chromium-browser/chromedriver" +# chrome_options = Options() +# chrome_options.add_argument("--disable-dev-shm-usage") +# chrome_options.add_argument("--headless") +# chrome_options.add_argument("--no-sandbox") +# chrome_options.add_argument("--disable-gpu") +# # chrome_options.binary_location = "" +# driver = webdriver.Chrome(DRIVER, chrome_options=chrome_options) +# set_viewport_size(driver, 1000, 1100) +# driver.get("https://aninternettroll.github.io/mcbeVerifierLeaderboard/") +# screenshot = driver.find_element_by_id("table").screenshot("leaderboard.png") +# driver.quit() +# # transparency time +# img = Image.open("leaderboard.png") +# img = img.convert("RGB") +# pallette = Image.open("palette.png") +# pallette = pallette.convert("P") +# img = img.quantize(colors=256, method=3, kmeans=0, palette=pallette) +# img = img.convert("RGBA") +# datas = img.getdata() +# +# newData = [] +# for item in datas: +# if item[0] == 255 and item[1] == 255 and item[2] == 255: +# newData.append((255, 255, 255, 0)) +# else: +# newData.append(item) +# +# img.putdata(newData) +# """ +# img = img.filter(ImageFilter.SHARPEN) +# img = img.filter(ImageFilter.SHARPEN) +# img = img.filter(ImageFilter.SHARPEN) +# """ +# # height, width = img.size +# # img = img.resize((height*10,width*10), resample=Image.BOX) +# img.save("leaderboard.png", "PNG") class Utils(commands.Cog): -- cgit v1.2.3 From d224135b021e225b776fa5ef263ce6da2805d254 Mon Sep 17 00:00:00 2001 From: Mango0x45 Date: Sun, 3 Jan 2021 14:39:21 +0100 Subject: Remove BC linebreaks --- cogs/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'cogs/utils.py') diff --git a/cogs/utils.py b/cogs/utils.py index 266123f..3acc8fc 100755 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -11,6 +11,7 @@ from random import choice, randint import discord from discord.ext import commands, tasks + # from PIL.Image import core as Image # import image as Image # from PIL import Image, ImageFilter @@ -67,14 +68,14 @@ async def reportStuff(self, ctx, message): # img = img.quantize(colors=256, method=3, kmeans=0, palette=pallette) # img = img.convert("RGBA") # datas = img.getdata() -# +# # newData = [] # for item in datas: # if item[0] == 255 and item[1] == 255 and item[2] == 255: # newData.append((255, 255, 255, 0)) # else: # newData.append(item) -# +# # img.putdata(newData) # """ # img = img.filter(ImageFilter.SHARPEN) @@ -441,7 +442,7 @@ class Utils(commands.Cog): async def math(self, ctx, eqn): try: result = subprocess.check_output(f"echo '{eqn}' | bc", shell=True) - await ctx.send(result.decode("utf-8").strip()) + await ctx.send(result.decode("utf-8").replace("\\\n", "").strip()) except subprocess.CalledProcessError as err: print(err) await ctx.send("Something went wrong") -- cgit v1.2.3 From 24d974befc8307138384c27d604c8b220201d83a Mon Sep 17 00:00:00 2001 From: Mango0x45 Date: Sun, 3 Jan 2021 15:50:31 +0100 Subject: Spaces work pls --- cogs/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cogs/utils.py') diff --git a/cogs/utils.py b/cogs/utils.py index 3acc8fc..ee40900 100755 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -439,7 +439,7 @@ 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): try: result = subprocess.check_output(f"echo '{eqn}' | bc", shell=True) await ctx.send(result.decode("utf-8").replace("\\\n", "").strip()) -- cgit v1.2.3 From 010fd353d4c57bad9c6f47cac881d725a006423e Mon Sep 17 00:00:00 2001 From: Mango0x45 Date: Sun, 3 Jan 2021 16:34:23 +0100 Subject: Try to make math work with BC functions --- bc_funcs/trig.bc | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ cogs/utils.py | 12 +++++-- 2 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 bc_funcs/trig.bc (limited to 'cogs/utils.py') diff --git a/bc_funcs/trig.bc b/bc_funcs/trig.bc new file mode 100644 index 0000000..01b7839 --- /dev/null +++ b/bc_funcs/trig.bc @@ -0,0 +1,98 @@ +define sin(x) { + auto b, s, r, a, q, i + + if (x < 0) + return (-sin(-x)) + + b = ibase + ibase = A + s = scale + scale = 1.1 * s + 2 + a = atan(1) + scale = 0 + q = (x / a + 2) / 4 + x -= 4 * q * a + + if (q % 2) + x = -x + + scale = s + 2 + r = a = x + q = -x * x + + for (i = 3; a; i += 2) { + a *= q / (i * (i - 1)) + r += a + } + + scale = s + ibase = b + return (r / 1) +} + +define cos(x){ + auto b, s + b = ibase + ibase = A + s = scale + scale *= 1.2 + x = sin(2 * atan(1) + x) + scale = s + ibase = b + + return (x / 1) +} + +define atan(x){ + auto b, s, r, n, a, m, t, f, i, u + b = ibase + ibase = A + n = 1 + + if (x < 0) { + n = -1 + x = -x + } + + if (scale < 65) { + if (x == 1) { + r = .7853981633974483096156608458198757210492923498437764552437361480/n + ibase = b + return (r) + } + + if (x == .2) { + r = .1973955598498807583700497651947902934475851037878521015176889402/n + ibase = b + return (r) + } + } + + s = scale + + if (x > .2) { + scale += 5 + a = atan(.2) + } + + scale = s + 3 + + while (x > .2) { + m++ + x = (x - .2) / (1 + .2 * x) + } + + r = u = x + f = -x * x + t = 1 + + for(i = 3; t; i += 2) { + u *= f + t = u / i + r += t + } + + scale = s + ibase = b + return ((m * a + r) / n) +} \ No newline at end of file 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) -- cgit v1.2.3 From e0abd677283eef8289fbd8b0fe599f869b7e2c1d Mon Sep 17 00:00:00 2001 From: Mango0x45 Date: Sun, 3 Jan 2021 16:35:41 +0100 Subject: I'm bad with folders --- cogs/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cogs/utils.py') diff --git a/cogs/utils.py b/cogs/utils.py index 9f7ba66..b3389d3 100755 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -5,6 +5,7 @@ import json import subprocess from collections import namedtuple from datetime import timedelta + # forgot to import this and ended up looking mentally unstable # troll literally pointed out atleast 4 things I did wrong in 3 lines of code from random import choice, randint @@ -448,7 +449,7 @@ class Utils(commands.Cog): eqn = eqn.replace("|", "abs(", pipes // 2).replace("|", ")", pipes // 2) result = subprocess.check_output( - f"echo '{eqn}' | bc -f */{bc_funcs}", shell=True + f"echo '{eqn}' | bc -f {bc_funcs}/*", shell=True ) await ctx.send(result.decode("utf-8").replace("\\\n", "").strip()) except subprocess.CalledProcessError as err: -- cgit v1.2.3 From 08cc3db7e6110865e1eef4f2ee1ace13f6d0cd2a Mon Sep 17 00:00:00 2001 From: Mango0x45 Date: Sun, 3 Jan 2021 16:50:08 +0100 Subject: test --- cogs/utils.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'cogs/utils.py') diff --git a/cogs/utils.py b/cogs/utils.py index b3389d3..c409e0c 100755 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -5,7 +5,6 @@ import json import subprocess from collections import namedtuple from datetime import timedelta - # forgot to import this and ended up looking mentally unstable # troll literally pointed out atleast 4 things I did wrong in 3 lines of code from random import choice, randint @@ -441,15 +440,15 @@ class Utils(commands.Cog): @commands.command(aliases=["calc"]) async def math(self, ctx, *, eqn: str): - bc_funcs = r"/home/thomas/Steve-Bot/bc_funcs" - + test = subprocess.check_output("pwd", shell=True) + ctx.send(test) try: # 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 + f"echo '{eqn}' | bc -f bc_funcs/*", shell=True ) await ctx.send(result.decode("utf-8").replace("\\\n", "").strip()) except subprocess.CalledProcessError as err: -- cgit v1.2.3 From 1a984db7df3536d3fbb8674732f1f7976f342f1a Mon Sep 17 00:00:00 2001 From: Mango0x45 Date: Sun, 3 Jan 2021 17:05:02 +0100 Subject: Hopefully this fixes stuff --- cogs/utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'cogs/utils.py') diff --git a/cogs/utils.py b/cogs/utils.py index c409e0c..7f48b78 100755 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -440,15 +440,13 @@ class Utils(commands.Cog): @commands.command(aliases=["calc"]) async def math(self, ctx, *, eqn: str): - test = subprocess.check_output("pwd", shell=True) - ctx.send(test) try: # 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 + f"echo 'scale = 10; {eqn}' | bc bc_funcs/*", shell=True ) await ctx.send(result.decode("utf-8").replace("\\\n", "").strip()) except subprocess.CalledProcessError as err: -- cgit v1.2.3 From debe83ad9d540927f92783a8032caf99fe4c5443 Mon Sep 17 00:00:00 2001 From: Mango0x45 Date: Sun, 3 Jan 2021 19:27:40 +0100 Subject: Gonna readd this when I learn how to make a jail --- cogs/utils.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'cogs/utils.py') diff --git a/cogs/utils.py b/cogs/utils.py index 7f48b78..30a2c19 100755 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -438,20 +438,20 @@ class Utils(commands.Cog): output = ", ".join([*commands]) await ctx.send(f"```List of custom commands:\n{output}```") - @commands.command(aliases=["calc"]) - async def math(self, ctx, *, eqn: str): - try: - # Allow for proper absolute value notation - pipes = eqn.count("|") - eqn = eqn.replace("|", "abs(", pipes // 2).replace("|", ")", pipes // 2) - - result = subprocess.check_output( - f"echo 'scale = 10; {eqn}' | bc bc_funcs/*", shell=True - ) - await ctx.send(result.decode("utf-8").replace("\\\n", "").strip()) - except subprocess.CalledProcessError as err: - print(err) - await ctx.send("Something went wrong") +# @commands.command(aliases=["calc"]) +# async def math(self, ctx, *, eqn: str): +# try: +# # Allow for proper absolute value notation +# pipes = eqn.count("|") +# eqn = eqn.replace("|", "abs(", pipes // 2).replace("|", ")", pipes // 2) +# +# result = subprocess.check_output( +# f"echo 'scale = 10; {eqn}' | bc bc_funcs/*", shell=True +# ) +# await ctx.send(result.decode("utf-8").replace("\\\n", "").strip()) +# except subprocess.CalledProcessError as err: +# print(err) +# await ctx.send("Something went wrong") @commands.command() async def retime(self, ctx, start_sec, end_sec, frames=0, framerate=30): -- cgit v1.2.3