@ -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 } ` \n expression: \n ` { expression } ` \n option: \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 } ` \n expression: \n ` { expression } ` \n option: \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 ) :