Update server_commands.py

This commit is contained in:
Elmon11 2020-11-21 13:52:12 +01:00 committed by GitHub
parent 386792945d
commit 8c08595cef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -51,9 +51,35 @@ class ServerCommands(commands.Cog):
@commands.command() @commands.command()
@is_staff() @is_staff()
async def start(self, ctx): async def start(self, ctx):
'Not currently working' 'Starts the server'
startEmbed = discord.Embed(description='start working out fatass') em = discord.Embed()
await ctx.send(embed=startEmbed) try:
attempt = hit_endpoint('start')
except Exception as e:
em.title='Command error'
em.colour = 0xFF0000
em.description='Something went wrong'
print(f'Error while starting server: {e}')
await ctx.send(embed=em)
else:
if 'error' in attempt.lower():
em.title='Command error'
em.colour = 0xFF0000
em.description=f'{attempt}'
await ctx.send(embed=em)
else:
em.title = 'Success'
em.colour = 0x00FF00
em.description = f'{attempt}'
await ctx.send(embed=em)
@commands.command()
async def uptime(self, ctx):
"Returns the uptime of the VPS"
em = discord.Embed()
em.title = 'VPS Uptime Information'
em.description = hit_endpoint('uptime')
await ctx.send(embed=em)
@commands.command() @commands.command()
@is_staff() @is_staff()
@ -61,16 +87,23 @@ class ServerCommands(commands.Cog):
'Stops the server' 'Stops the server'
em = discord.Embed() em = discord.Embed()
try: try:
self.bot.telnet_object.session.write(bytes('stop', 'ascii') + b"\r\n") attempt = hit_endpoint('stop')
except: except Exception as e:
em.title='Command error' em.title='Command error'
em.colour = 0xFF0000 em.colour = 0xFF0000
em.description='Something went wrong' em.description='Something went wrong'
print(f'Error while stopping server: {e}')
await ctx.send(embed=em)
else:
if 'error' in attempt.lower():
em.title='Command error'
em.colour = 0xFF0000
em.description=f'{attempt}'
await ctx.send(embed=em) await ctx.send(embed=em)
else: else:
em.title = 'Success' em.title = 'Success'
em.colour = 0x00FF00 em.colour = 0x00FF00
em.description = 'Server stopped.' em.description = f'{attempt}'
await ctx.send(embed=em) await ctx.send(embed=em)
@commands.command(aliases=['adminconsole', 'ac']) @commands.command(aliases=['adminconsole', 'ac'])
@ -108,16 +141,24 @@ class ServerCommands(commands.Cog):
'Kills the server' 'Kills the server'
em = discord.Embed() em = discord.Embed()
try: try:
self.bot.telnet_object.session.write(bytes('telnet.stop', 'ascii') + b"\r\n") attempt = hit_endpoint('kill')
except: except Exception as e:
em.title='Command error' em.title='Command error'
em.colour = 0xFF0000 em.colour = 0xFF0000
em.description='Something went wrong' em.description='Something went wrong'
print(f'Error while killing server: {e}')
await ctx.send(embed=em)
else:
if 'error' in attempt.lower():
em.title='Command error'
em.colour = 0xFF0000
em.description='{attempt}'
print(f'Error while killing server: {e}')
await ctx.send(embed=em) await ctx.send(embed=em)
else: else:
em.title = 'Success' em.title = 'Success'
em.colour = 0x00FF00 em.colour = 0x00FF00
em.description = 'Killed the server.' em.description = f'{attempt}'
await ctx.send(embed=em) await ctx.send(embed=em)
@ -128,10 +169,11 @@ class ServerCommands(commands.Cog):
em = discord.Embed() em = discord.Embed()
try: try:
self.bot.telnet_object.session.write(bytes('restart', 'ascii') + b"\r\n") self.bot.telnet_object.session.write(bytes('restart', 'ascii') + b"\r\n")
except: except Exception as e:
em.title='Command error' em.title='Command error'
em.colour = 0xFF0000 em.colour = 0xFF0000
em.description='Something went wrong' em.description='Something went wrong'
print(f'Error while restarting server: {e}')
await ctx.send(embed=em) await ctx.send(embed=em)
else: else:
em.title = 'Success' em.title = 'Success'
@ -143,7 +185,6 @@ class ServerCommands(commands.Cog):
@is_senior() @is_senior()
async def console(self, ctx,*, command): async def console(self, ctx,*, command):
'Send a command as console' 'Send a command as console'
'''await ctx.send(f'```:[{str(datetime.utcnow().replace(microsecond=0))[11:]} INFO]: {ctx.author.name} issued server command: /{command}```')'''
em = discord.Embed() em = discord.Embed()
try: try:
self.bot.telnet_object.session.write(bytes(command, 'ascii') + b"\r\n") self.bot.telnet_object.session.write(bytes(command, 'ascii') + b"\r\n")
@ -163,7 +204,7 @@ class ServerCommands(commands.Cog):
'Gets the current status of the Server' 'Gets the current status of the Server'
em = discord.Embed() em = discord.Embed()
try: try:
json = requests.get("http://play.totalfreedom.me:28966/list?json=true").json() json = requests.get("http://play.totalfreedom.me:28966/list?json=true", timeout=5).json()
except: except:
em.description = 'Server is offline' em.description = 'Server is offline'
em.colour = 0xFF0000 em.colour = 0xFF0000
@ -172,16 +213,13 @@ class ServerCommands(commands.Cog):
em.colour = 0x00FF00 em.colour = 0x00FF00
await ctx.send(embed=em) await ctx.send(embed=em)
@commands.command() @commands.command(name='list')
async def list(self, ctx): async def online(self, ctx):
'Gives a list of online players.' 'Gives a list of online players.'
em = discord.Embed() em = discord.Embed()
em.title = "Player List" em.title = "Player List"
try: try:
json = requests.get("http://play.totalfreedom.me:28966/list?json=true").json() json = requests.get("http://play.totalfreedom.me:28966/list?json=true", timeout=5).json()
except ConnectionError:
em.description = 'Server is offline'
else:
if json["online"] == 0: if json["online"] == 0:
em.description = "There are no online players" em.description = "There are no online players"
else: else:
@ -213,11 +251,13 @@ class ServerCommands(commands.Cog):
imposters = json["imposters"] imposters = json["imposters"]
if len(imposters) != 0: if len(imposters) != 0:
em = format_list_entry(em, imposters, "Imposters") em = format_list_entry(em, imposters, "Imposters")
except:
em.description = 'Server is offline'
await ctx.send(embed=em) await ctx.send(embed=em)
@commands.command() @commands.command()
async def ip(self, ctx): async def ip(self, ctx):
'Returns the server IP' 'Returns the server IP'
await ctx.send('play.totalfreedom.me') await ctx.send(embed=discord.Embed(description='play.totalfreedom.me',title='Server IP'))
#pass #discordSRV responds already. #pass #discordSRV responds already.
@commands.command() @commands.command()