From c70e5da029dffd959fffe89178b9e73183b8e0de Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Thu, 4 Feb 2021 17:26:45 -0600 Subject: [PATCH 1/7] Update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 8078c6a..43e29e3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # "Botflop" -~~[Click here](https://discord.com/api/oauth2/authorize?client_id=787929894616825867&permissions=0&scope=bot) to invite Botflop to your server.~~ - -EDIT: Botflop is currently in 100 servers and cannot be added to additional servers until it becomes a verified bot. I applied on January 29 -- the day that Botflop reached 75 servers (the minimum to apply), but I have not heard back yet. If Discord sticks to their goal of 5 business days, it should be verified by February 4. +[Click here](https://discord.com/api/oauth2/authorize?client_id=787929894616825867&permissions=0&scope=bot) to invite Botflop to your server. # Current abilities ## Analyze timings reports From 63aa348fe04f3e9439efa630110eb700026b39ea Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Fri, 5 Feb 2021 21:42:41 -0600 Subject: [PATCH 2/7] Replace print with logging.info --- cogs/timings.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/cogs/timings.py b/cogs/timings.py index b1fa4f0..74271ac 100644 --- a/cogs/timings.py +++ b/cogs/timings.py @@ -3,6 +3,7 @@ from discord.ext import commands import requests import yaml import re +import logging TIMINGS_CHECK = None YAML_ERROR = None @@ -10,7 +11,7 @@ with open("cogs/timings_check.yml", 'r', encoding="utf8") as stream: try: TIMINGS_CHECK = yaml.safe_load(stream) except yaml.YAMLError as exc: - print(exc) + logging.info(exc) YAML_ERROR = exc VERSION_REGEX = re.compile(r"\d+\.\d+\.\d+") @@ -50,7 +51,7 @@ class Timings(commands.Cog): timings_url = timings_url.split("#")[0] if "?id=" not in timings_url: return - print(timings_url) + logging.info(timings_url) timings_host, timings_id = timings_url.split("?id=") timings_json = timings_host + "data.php?id=" + timings_id @@ -84,7 +85,7 @@ class Timings(commands.Cog): embed_var.add_field(**create_field(server)) break except KeyError as key: - print("Missing: " + str(key)) + logging.info("Missing: " + str(key)) try: timing_cost = int(request["timingsMaster"]["system"]["timingcost"]) @@ -92,7 +93,7 @@ class Timings(commands.Cog): embed_var.add_field(name="❌ Timingcost", value=f"Your timingcost is {timing_cost}. Your cpu is overloaded and/or slow. Find a [better host](https://www.birdflop.com).") except KeyError as key: - print("Missing: " + str(key)) + logging.info("Missing: " + str(key)) try: jvm_version = request["timingsMaster"]["system"]["jvmversion"] @@ -100,7 +101,7 @@ class Timings(commands.Cog): embed_var.add_field(name="❌ Java Version", value=f"You are using Java {jvm_version}. Update to [Java 11](https://adoptopenjdk.net/installation.html).") except KeyError as key: - print("Missing: " + str(key)) + logging.info("Missing: " + str(key)) try: flags = request["timingsMaster"]["system"]["flags"] @@ -172,7 +173,7 @@ class Timings(commands.Cog): embed_var.add_field(name="❌ Aikar's Flags", value="Use [Aikar's flags](https://aikar.co/2018/07/02/tuning-the-jvm-g1gc-garbage-collector-flags-for-minecraft/).") except KeyError as key: - print("Missing: " + str(key)) + logging.info("Missing: " + str(key)) try: cpu = int(request["timingsMaster"]["system"]["cpu"]) @@ -183,7 +184,7 @@ class Timings(commands.Cog): embed_var.add_field(name="❌ Threads", value=f"You have only {cpu} threads. Find a [better host](https://www.birdflop.com).") except KeyError as key: - print("Missing: " + str(key)) + logging.info("Missing: " + str(key)) try: handlers = request_raw["idmap"]["handlers"] @@ -194,7 +195,7 @@ class Timings(commands.Cog): embed_var.add_field(name=f"❌ {handler_name}", value=f"This datapack uses command functions which are laggy.") except KeyError as key: - print("Missing: " + str(key)) + logging.info("Missing: " + str(key)) plugins = request["timingsMaster"]["plugins"] if "plugins" in request["timingsMaster"] else None server_properties = request["timingsMaster"]["config"]["server.properties"] if "server.properties" in request["timingsMaster"]["config"] else None @@ -243,7 +244,7 @@ class Timings(commands.Cog): embed_var.add_field(name="❌ " + plugin, value="This plugin was made by Songoda. Songoda resources are poorly developed and often cause problems. You should find an alternative.") except KeyError as key: - print("Missing: " + str(key)) + logging.info("Missing: " + str(key)) try: using_tweaks = "ViewDistanceTweaks" in plugins @@ -263,7 +264,7 @@ class Timings(commands.Cog): f"And reduce view-distance from {tvd} in [spigot.yml](http://bit.ly/spiconf). Recommended: 4.") break except KeyError as key: - print("Missing: " + str(key)) + logging.info("Missing: " + str(key)) try: normal_ticks = request["timingsMaster"]["data"][0]["totalTicks"] @@ -285,10 +286,10 @@ class Timings(commands.Cog): color = int(red*256*256 + green*256) embed_var.color = color except KeyError as key: - print("Missing: " + str(key)) + logging.info("Missing: " + str(key)) except ValueError as value_error: - print(value_error) + logging.info(value_error) embed_var.add_field(name="❗ Value Error", value=value_error) @@ -331,12 +332,12 @@ def eval_field(embed_var, option, option_name, plugins, server_properties, bukki break except ValueError as value_error: add_to_field = False - print(value_error) + logging.info(value_error) embed_var.add_field(name="❗ Value Error", value=f'`{value_error}`\nexpression:\n`{expression}`\noption:\n`{option_name}`') except TypeError as type_error: add_to_field = False - print(type_error) + logging.info(type_error) embed_var.add_field(name="❗ Type Error", value=f'`{type_error}`\nexpression:\n`{expression}`\noption:\n`{option_name}`') for config_name in dict_of_vars: @@ -351,7 +352,7 @@ def eval_field(embed_var, option, option_name, plugins, server_properties, bukki break except KeyError as key: - print("Missing: " + str(key)) + logging.info("Missing: " + str(key)) def create_field(option): From a3540300e3b39a577ff95a4a288fe7143c767b91 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Fri, 5 Feb 2021 22:41:03 -0600 Subject: [PATCH 3/7] Make bot async so it doesn't break when the timings site is down --- cogs/timings.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cogs/timings.py b/cogs/timings.py index 74271ac..4a8dc19 100644 --- a/cogs/timings.py +++ b/cogs/timings.py @@ -1,6 +1,6 @@ import discord from discord.ext import commands -import requests +import aiohttp import yaml import re import logging @@ -57,8 +57,11 @@ class Timings(commands.Cog): timings_json = timings_host + "data.php?id=" + timings_id timings_url_raw = timings_url + "&raw=1" - request_raw = requests.get(timings_url_raw).json() - request = requests.get(timings_json).json() + async with aiohttp.ClientSession() as session: + async with session.get(timings_url_raw) as response: + request_raw = response.json() + async with session.get(timings_json) as response: + request = response.json() if request is None or request_raw is None: embed_var.add_field(name="❌ Invalid report", value="Create a new timings report.") From 7cef2964784079374aee7ce9fe3b494886ea4388 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Fri, 5 Feb 2021 22:42:02 -0600 Subject: [PATCH 4/7] Make bot async --- cogs/timings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/timings.py b/cogs/timings.py index 4a8dc19..73ca570 100644 --- a/cogs/timings.py +++ b/cogs/timings.py @@ -59,9 +59,9 @@ class Timings(commands.Cog): async with aiohttp.ClientSession() as session: async with session.get(timings_url_raw) as response: - request_raw = response.json() + await request_raw = response.json() async with session.get(timings_json) as response: - request = response.json() + await request = response.json() if request is None or request_raw is None: embed_var.add_field(name="❌ Invalid report", value="Create a new timings report.") From 7f04826e56a3622384d3ae1a1a77e70bf4dbe129 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Fri, 5 Feb 2021 22:42:59 -0600 Subject: [PATCH 5/7] Fix bugs for async bot --- cogs/timings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/timings.py b/cogs/timings.py index 73ca570..807dc02 100644 --- a/cogs/timings.py +++ b/cogs/timings.py @@ -59,9 +59,9 @@ class Timings(commands.Cog): async with aiohttp.ClientSession() as session: async with session.get(timings_url_raw) as response: - await request_raw = response.json() + request_raw = await response.json() async with session.get(timings_json) as response: - await request = response.json() + request = await response.json() if request is None or request_raw is None: embed_var.add_field(name="❌ Invalid report", value="Create a new timings report.") From aed4916999590f286819b60795429b5cb768e8b5 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Fri, 5 Feb 2021 22:45:49 -0600 Subject: [PATCH 6/7] Specify no content type for aiohttp reqs --- cogs/timings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/timings.py b/cogs/timings.py index 807dc02..5fe3bb3 100644 --- a/cogs/timings.py +++ b/cogs/timings.py @@ -59,9 +59,9 @@ class Timings(commands.Cog): async with aiohttp.ClientSession() as session: async with session.get(timings_url_raw) as response: - request_raw = await response.json() + request_raw = await response.json(content_type=None) async with session.get(timings_json) as response: - request = await response.json() + request = await response.json(content_type=None) if request is None or request_raw is None: embed_var.add_field(name="❌ Invalid report", value="Create a new timings report.") From d231adeb29caf0c3e286d0dd9ab74f6d3d79c926 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Fri, 5 Feb 2021 22:52:26 -0600 Subject: [PATCH 7/7] lower CPU thread warning from 3 to 2 --- cogs/timings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/timings.py b/cogs/timings.py index 5fe3bb3..8a88932 100644 --- a/cogs/timings.py +++ b/cogs/timings.py @@ -183,7 +183,7 @@ class Timings(commands.Cog): if cpu == 1: embed_var.add_field(name="❌ Threads", value=f"You have only {cpu} thread. Find a [better host](https://www.birdflop.com).") - if cpu == 2 or cpu == 3: + if cpu == 2: embed_var.add_field(name="❌ Threads", value=f"You have only {cpu} threads. Find a [better host](https://www.birdflop.com).") except KeyError as key: