Browse Source

Timings - reformat and typo

master
DrBot7 4 years ago
parent
commit
4d0dd67612
  1. 53
      cogs/timings.py
  2. 2
      cogs/timings_check.yml

53
cogs/timings.py

@ -22,12 +22,6 @@ class Timings(commands.Cog):
# Use @commands.Cog.listener() instead of event and use @commands.command() for commands
# TODO: Add descriptions or hyperlink from the following links
# http://bit.ly/spiconf
# http://bit.ly/paperconf
# http://bit.ly/purpurc
async def analyze_timings(self, message):
words = message.content.replace("\n", " ").split(" ")
timings_url = ""
@ -86,7 +80,8 @@ class Timings(commands.Cog):
timing_cost = int(request["timingsMaster"]["system"]["timingcost"])
if timing_cost > 300:
embed_var.add_field(name="❌ Timingcost",
value="Your timingcost is " + str(timing_cost) + ". Find a [better host](https://www.birdflop.com).")
value="Your timingcost is " + str(
timing_cost) + ". Find a [better host](https://www.birdflop.com).")
except KeyError as key:
print("Missing: " + str(key))
unchecked += 1
@ -155,20 +150,28 @@ class Timings(commands.Cog):
cpu = int(request["timingsMaster"]["system"]["cpu"])
if cpu == 1:
embed_var.add_field(name="❌ Threads",
value="You have only " + str(cpu) + " thread. Find a [better host](https://www.birdflop.com).")
value="You have only " + str(
cpu) + " thread. Find a [better host](https://www.birdflop.com).")
if cpu == 2:
embed_var.add_field(name="❌ Threads",
value="You have only " + str(cpu) + " threads. Find a [better host](https://www.birdflop.com).")
value="You have only " + str(
cpu) + " threads. Find a [better host](https://www.birdflop.com).")
except KeyError as key:
print("Missing: " + str(key))
unchecked += 1
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
bukkit = request["timingsMaster"]["config"]["bukkit"] if "bukkit" in request["timingsMaster"]["config"] else None
spigot = request["timingsMaster"]["config"]["spigot"] if "spigot" in request["timingsMaster"]["config"] else None
paper = request["timingsMaster"]["config"]["paper"] if "paper" in request["timingsMaster"]["config"] else None
purpur = request["timingsMaster"]["config"]["purpur"] if "purpur" in request["timingsMaster"]["config"] else None
server_properties = request["timingsMaster"]["config"]["server.properties"] if "server.properties" in \
request["timingsMaster"][
"config"] else None
bukkit = request["timingsMaster"]["config"]["bukkit"] if "bukkit" in request["timingsMaster"][
"config"] else None
spigot = request["timingsMaster"]["config"]["spigot"] if "spigot" in request["timingsMaster"][
"config"] else None
paper = request["timingsMaster"]["config"]["paper"] if "paper" in request["timingsMaster"][
"config"] else None
purpur = request["timingsMaster"]["config"]["purpur"] if "purpur" in request["timingsMaster"][
"config"] else None
if not YAML_ERROR:
if "plugins" in TIMINGS_CHECK:
for server_name in TIMINGS_CHECK["plugins"]:
@ -181,7 +184,8 @@ class Timings(commands.Cog):
stored_plugin["name"] = plugin_name
embed_var.add_field(**create_field(stored_plugin))
else:
eval_field(embed_var, stored_plugin, plugin_name, unchecked, plugins, server_properties, bukkit, spigot, paper, purpur)
eval_field(embed_var, stored_plugin, plugin_name, unchecked, plugins,
server_properties, bukkit, spigot, paper, purpur)
if "songoda" in request["timingsMaster"]["plugins"][plugin]["authors"].casefold():
if plugin == "EpicHeads":
embed_var.add_field(name="❌ EpicHeads",
@ -198,7 +202,8 @@ class Timings(commands.Cog):
config = TIMINGS_CHECK["config"][config_name]
for option_name in config:
option = config[option_name]
eval_field(embed_var, option, option_name, unchecked, plugins, server_properties, bukkit, spigot, paper, purpur)
eval_field(embed_var, option, option_name, unchecked, plugins, server_properties, bukkit,
spigot, paper, purpur)
else:
embed_var.add_field(name="Error loading YAML file",
value=YAML_ERROR)
@ -214,7 +219,9 @@ class Timings(commands.Cog):
using_ntvd = False
if not using_ntvd:
embed_var.add_field(name="❌ no-tick-view-distance",
value="Set in [paper.yml](http://bit.ly/paperconf). Recommended: " + str(tvd) + ". And reduce view-distance from default (" + str(tvd) + ") in [spigot.yml](http://bit.ly/spiconf). Recommended: 3.")
value="Set in [paper.yml](http://bit.ly/paperconf). Recommended: " + str(
tvd) + ". And reduce view-distance from default (" + str(
tvd) + ") in [spigot.yml](http://bit.ly/spiconf). Recommended: 3.")
except KeyError as key:
print("Missing: " + str(key))
unchecked = unchecked + 1
@ -232,12 +239,15 @@ class Timings(commands.Cog):
issue_count = len(embed_var.fields)
if issue_count >= 25:
embed_var.insert_field_at(index=24, name="Plus " + str(issue_count - 24) + " more recommendations", value="Create a new timings report after resolving some of the above issues to see more.")
embed_var.insert_field_at(index=24, name="Plus " + str(issue_count - 24) + " more recommendations",
value="Create a new timings report after resolving some of the above issues to see more.")
if unchecked > 0:
embed_var.description = "||" + str(unchecked) + " missing configuration optimizations.||"
await message.reply(embed=embed_var)
def eval_field(embed_var, option, option_name, unchecked, plugins=None, server_properties=None, bukkit=None, spigot=None, paper=None, purpur=None):
def eval_field(embed_var, option, option_name, unchecked, plugins=None, server_properties=None, bukkit=None,
spigot=None, paper=None, purpur=None):
try:
for option_data in option:
add_to_field = True
@ -253,13 +263,15 @@ def eval_field(embed_var, option, option_name, unchecked, plugins=None, server_p
break
if add_to_field:
""" f strings don't like newlines so we replace the newlines with placeholder text before we eval """
option_data["value"] = eval('f"""' + option_data["value"].replace("\n", "\\|n\\") + '"""').replace("\\|n\\", "\n")
option_data["value"] = eval('f"""' + option_data["value"].replace("\n", "\\|n\\") + '"""').replace(
"\\|n\\", "\n")
embed_var.add_field(**create_field({**{"name": option_name}, **option_data}))
break
except KeyError as key:
print("Missing: " + str(key))
unchecked += 1
def create_field(option):
field = {"name": option["name"],
"value": option["value"]}
@ -271,5 +283,6 @@ def create_field(option):
field["inline"] = option["inline"]
return field
def setup(bot):
bot.add_cog(Timings(bot))

2
cogs/timings_check.yml

@ -400,7 +400,7 @@ config:
- int(paper["world-settings"]["default"]["creative-arrow-despawn-rate"]) == -1
prefix: "❌ "
value: "Set a value in [paper.yml](http://bit.ly/paperconf).\nRecommended: 60"
non-player-arrow-despawn-rate:
prevent-moving-into-unloaded-chunks:
- expressions:
- paper["world-settings"]["default"]["prevent-moving-into-unloaded-chunks"] == "false"
prefix: "❌ "

Loading…
Cancel
Save