Browse Source

Merge remote-tracking branch 'origin/master'

pull/16/head
DrBot7 3 years ago
parent
commit
7255f5dc63
  1. 4
      README.md
  2. 42
      cogs/timings.py

4
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

42
cogs/timings.py

@ -1,8 +1,9 @@
import discord
from discord.ext import commands
import requests
import aiohttp
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,14 +51,17 @@ 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
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 = await response.json(content_type=None)
async with session.get(timings_json) as response:
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.")
@ -84,7 +88,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 +96,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 +104,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,18 +176,18 @@ 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"])
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:
print("Missing: " + str(key))
logging.info("Missing: " + str(key))
try:
handlers = request_raw["idmap"]["handlers"]
@ -194,7 +198,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 +247,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 +267,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 +289,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 +335,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 +355,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):

Loading…
Cancel
Save