Fixing codacy issues

This commit is contained in:
Elmon11 2020-12-08 23:32:20 +01:00 committed by GitHub
parent a4fc6a449b
commit b6e7c53312
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,15 +12,6 @@ from unicode import *
class ServerCommands(commands.Cog): class ServerCommands(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
def get_server_status(self):
try:
requests.get(
"http://play.totalfreedom.me:28966/list?json=true", timeout=5).json()
except:
return False
else:
return True
@commands.command() @commands.command()
@is_liaison() @is_liaison()
@ -216,9 +207,9 @@ class ServerCommands(commands.Cog):
async def state(self, ctx): async def state(self, ctx):
'Gets the current status of the Server' 'Gets the current status of the Server'
em = discord.Embed() em = discord.Embed()
if self.get_server_status(): if get_server_status():
em.description = 'Server is online' em.description = 'Server is online'
em.colour = 0x00FF00 em.colour = 0x00FF00
else: else:
em.description = 'Server is offline' em.description = 'Server is offline'
em.colour = 0xFF0000 em.colour = 0xFF0000
@ -310,21 +301,21 @@ class ServerCommands(commands.Cog):
"""Lag information regarding the server""" """Lag information regarding the server"""
em = discord.Embed() em = discord.Embed()
em.title = 'Server lag information' em.title = 'Server lag information'
if self.get_server_status(): if get_server_status():
self.bot.telnet_object.session.write( self.bot.telnet_object.session.write(
bytes('lag', 'ascii') + b"\r\n") bytes('lag', 'ascii') + b"\r\n")
self.bot.telnet_object.session.read_until( self.bot.telnet_object.session.read_until(
bytes(f'Uptime:', 'ascii'), 2) bytes('Uptime:', 'ascii'), 2)
server_uptime = self.bot.telnet_object.session.read_until( server_uptime = self.bot.telnet_object.session.read_until(
bytes(f'Current TPS =', 'ascii'), 2).decode('utf-8') bytes('Current TPS =', 'ascii'), 2).decode('utf-8')
server_tps = self.bot.telnet_object.session.read_until( server_tps = self.bot.telnet_object.session.read_until(
bytes(f'Maximum memory: ', 'ascii'), 2).decode('utf-8') bytes('Maximum memory: ', 'ascii'), 2).decode('utf-8')
maximum_memory = self.bot.telnet_object.session.read_until( maximum_memory = self.bot.telnet_object.session.read_until(
bytes(f'Allocated memory:', 'ascii'), 2).decode('utf-8') bytes('Allocated memory:', 'ascii'), 2).decode('utf-8')
allocated_memory = self.bot.telnet_object.session.read_until( allocated_memory = self.bot.telnet_object.session.read_until(
bytes(f'Free memory:', 'ascii'), 2).decode('utf-8') bytes('Free memory:', 'ascii'), 2).decode('utf-8')
free_memory = self.bot.telnet_object.session.read_until( free_memory = self.bot.telnet_object.session.read_until(
bytes(f'World "world":', 'ascii'), 2).decode('utf-8') bytes('World "world":', 'ascii'), 2).decode('utf-8')
server_uptime = server_uptime.strip(':Current TPS =') server_uptime = server_uptime.strip(':Current TPS =')
server_tps = server_tps.strip(':Maximum memory:') server_tps = server_tps.strip(':Maximum memory:')
@ -332,8 +323,6 @@ class ServerCommands(commands.Cog):
allocated_memory = allocated_memory.strip(':Free memory:') allocated_memory = allocated_memory.strip(':Free memory:')
free_memory = free_memory.strip(':World "world":') free_memory = free_memory.strip(':World "world":')
time_sent = str(datetime.utcnow().replace(microsecond=0))[11:]
print(f'TPS: {server_tps}, UPTIME: {server_uptime}') print(f'TPS: {server_tps}, UPTIME: {server_uptime}')
try: try: