Browse Source

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

pull/1/head
William 3 years ago
parent
commit
45a8bb4183
  1. 31
      cogs/timings.py

31
cogs/timings.py

@ -4,6 +4,7 @@ import aiohttp
import yaml import yaml
import re import re
import logging import logging
import requests
TIMINGS_CHECK = None TIMINGS_CHECK = None
YAML_ERROR = 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+") VERSION_REGEX = re.compile(r"\d+\.\d+\.\d+")
class Timings(commands.Cog): class Timings(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
@ -71,10 +73,10 @@ class Timings(commands.Cog):
if version.count('.') == 1: if version.count('.') == 1:
version = version[:-1] version = version[:-1]
version = version + ".0)" version = version + ".0)"
if "Gem" in version or "Stellar" in version or "iSpigot" in version: if "Gem" in version or "Stellar" in version or "iSpigot" in version:
embed_var.add_field(name="⚠️ Publicly Sold Custom Jar", value=f'You are using `{version}`. Publicly sold custom jars have been known to have major instability issues, often leading to crashes. Many have skirted the copyright law in the past, and have been implement plugin features for extremely large prices (x10-x20 market value). This does not necessarily mean they are bad, but please be careful.') embed_var.add_field(name="⚠️ Publicly Sold Custom Jar", value=f'You are using `{version}`. Publicly sold custom jars have been known to have major instability issues, often leading to crashes. Many have skirted the copyright law in the past, and have been implement plugin features for extremely large prices (x10-x20 market value). This does not necessarily mean they are bad, but please be careful.')
if "version" in TIMINGS_CHECK and version: if "version" in TIMINGS_CHECK and version:
version_result = VERSION_REGEX.search(version) version_result = VERSION_REGEX.search(version)
version_result = version_result.group() if version_result else None version_result = version_result.group() if version_result else None
@ -198,7 +200,7 @@ class Timings(commands.Cog):
embed_var.add_field(name="❌ Too Few Threads", 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.") 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: 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.") 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: except KeyError as key:
logging.info("Missing: " + str(key)) logging.info("Missing: " + str(key))
@ -296,7 +298,6 @@ class Timings(commands.Cog):
except KeyError as key: except KeyError as key:
logging.info("Missing: " + str(key)) logging.info("Missing: " + str(key))
try: try:
normal_ticks = request["timingsMaster"]["data"][0]["totalTicks"] normal_ticks = request["timingsMaster"]["data"][0]["totalTicks"]
worst_tps = 20 worst_tps = 20
@ -317,7 +318,7 @@ class Timings(commands.Cog):
else: else:
red = int(255 * (-0.1 * worst_tps + 2)) red = int(255 * (-0.1 * worst_tps + 2))
green = 255 green = 255
color = int(red*256*256 + green*256)
color = int(red * 256 * 256 + green * 256)
embed_var.color = color embed_var.color = color
except KeyError as key: except KeyError as key:
logging.info("Missing: " + str(key)) logging.info("Missing: " + str(key))
@ -337,16 +338,32 @@ class Timings(commands.Cog):
field_at_index = 24 field_at_index = 24
if issue_count >= 25: if issue_count >= 25:
embed_var.insert_field_at(index=24, name=f"Plus {issue_count - 24} more recommendations", 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: while len(embed_var) > 6000:
embed_var.insert_field_at(index=field_at_index, embed_var.insert_field_at(index=field_at_index,
name=f"Plus {issue_count - field_at_index} more recommendations", 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):] del embed_var._fields[(field_at_index + 1):]
field_at_index -= 1 field_at_index -= 1
await message.reply(embed=embed_var) 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): 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, dict_of_vars = {"plugins": plugins, "server_properties": server_properties, "bukkit": bukkit, "spigot": spigot,
"paper": paper, "tuinity": tuinity, "purpur": purpur} "paper": paper, "tuinity": tuinity, "purpur": purpur}

Loading…
Cancel
Save