Dump excess timings to https://mclo.gs/ #1

Merged
elliot merged 1 commits from William278/TimingsBot:log-extra-problems into master 3 years ago
  1. 25
      cogs/timings.py

25
cogs/timings.py

@ -4,6 +4,7 @@ import aiohttp
import yaml
import re
import logging
import requests
TIMINGS_CHECK = None
YAML_ERROR = None
@ -16,6 +17,7 @@ with open("cogs/timings_check.yml", 'r', encoding="utf8") as stream:
VERSION_REGEX = re.compile(r"\d+\.\d+\.\d+")
class Timings(commands.Cog):
def __init__(self, bot):
self.bot = bot
@ -198,7 +200,7 @@ class Timings(commands.Cog):
embed_var.add_field(name="❌ Too Few Threads",
value=f"You have only {cpu} thread. Even if you're virtualizing a bigger CPU, this is not enough to handle a larger playerbase.")
if cpu == 2:
embed_var.add_field(name="⚠ Few Threads",
embed_var.add_field(name="⚠ Few Threads",
value=f"You have only {cpu} threads. This is on the border of the minimum, but if you have a hefty CPU, it can work well.")
except KeyError as key:
logging.info("Missing: " + str(key))
@ -296,7 +298,6 @@ class Timings(commands.Cog):
except KeyError as key:
logging.info("Missing: " + str(key))
try:
normal_ticks = request["timingsMaster"]["data"][0]["totalTicks"]
worst_tps = 20
@ -337,16 +338,32 @@ class Timings(commands.Cog):
field_at_index = 24
if issue_count >= 25:
embed_var.insert_field_at(index=24, name=f"Plus {issue_count - 24} more recommendations",
value="Create a new timings report after resolving some of the above issues to see more.")
value=f"[Click here to view]({paste_excess_problems(embed_var)})")
while len(embed_var) > 6000:
embed_var.insert_field_at(index=field_at_index,
name=f"Plus {issue_count - field_at_index} more recommendations",
value="Create a new timings report after resolving some of the above issues to see more.")
value=f"[Click here to view]({paste_excess_problems(embed_var)})")
del embed_var._fields[(field_at_index + 1):]
field_at_index -= 1
await message.reply(embed=embed_var)
def paste_excess_problems(embed_var):
url = "https://api.mclo.gs/1/log"
paste_content = {"content": stringify_embed_contents(embed_var)}
response = requests.post(url, paste_content)
return response.json()["url"]
def stringify_embed_contents(embed_var):
embed_string = ""
for embed in embed_var.fields:
embed_string += embed.name + ":\n"
embed_string += embed.value + "\n\n"
return embed_string
def eval_field(embed_var, option, option_name, plugins, server_properties, bukkit, spigot, paper, tuinity, purpur):
dict_of_vars = {"plugins": plugins, "server_properties": server_properties, "bukkit": bukkit, "spigot": spigot,
"paper": paper, "tuinity": tuinity, "purpur": purpur}

Loading…
Cancel
Save