mirror of
https://github.com/TotalFreedomMC/TotalFreedomBot.git
synced 2024-12-22 15:44:57 +00:00
Update server_commands.py
This commit is contained in:
parent
da81f4ad37
commit
b762622bd2
1 changed files with 42 additions and 38 deletions
|
@ -138,15 +138,16 @@ class ServerCommands(commands.Cog):
|
|||
for arg in args:
|
||||
command += f'{arg} '
|
||||
try:
|
||||
if args[0] in ['mute', 'stfu', 'gtfo', 'ban', 'unban', 'unmute', 'smite', 'noob', 'tban', 'tempban', 'warn', 'mv', 'kick', 'cc', 'say']:
|
||||
if args[0] in ['mute', 'stfu', 'gtfo', 'ban', 'unban', 'unmute', 'smite', 'noob', 'tban', 'tempban', 'warn',
|
||||
'mv', 'kick', 'cc', 'say']:
|
||||
self.write_telnet_session(server,
|
||||
bytes(command, 'ascii') + b"\r\n")
|
||||
bytes(command, 'ascii') + b"\r\n")
|
||||
elif args[0] == 'saconfig':
|
||||
if args[1] not in ['add', 'remove']:
|
||||
raise no_permission(['IS_SENIOR_ADMIN'])
|
||||
else:
|
||||
self.write_telnet_session(server,
|
||||
bytes(command, 'ascii') + b"\r\n")
|
||||
bytes(command, 'ascii') + b"\r\n")
|
||||
else:
|
||||
raise no_permission(['IS_SENIOR_ADMIN'])
|
||||
except Exception as e:
|
||||
|
@ -199,7 +200,7 @@ class ServerCommands(commands.Cog):
|
|||
server = 2
|
||||
try:
|
||||
self.write_telnet_session(server,
|
||||
bytes('restart', 'ascii') + b"\r\n")
|
||||
bytes('restart', 'ascii') + b"\r\n")
|
||||
except Exception as e:
|
||||
em.title = 'Command error'
|
||||
em.colour = 0xFF0000
|
||||
|
@ -222,7 +223,7 @@ class ServerCommands(commands.Cog):
|
|||
server = 2
|
||||
try:
|
||||
self.write_telnet_session(server,
|
||||
bytes(command, 'ascii') + b"\r\n")
|
||||
bytes(command, 'ascii') + b"\r\n")
|
||||
except Exception as e:
|
||||
em.title = 'Command error'
|
||||
em.colour = 0xFF0000
|
||||
|
@ -249,7 +250,7 @@ class ServerCommands(commands.Cog):
|
|||
em.colour = 0xFF0000
|
||||
await ctx.send(embed=em)
|
||||
|
||||
@commands.command(name='list', aliases=['l','who','lsit'])
|
||||
@commands.command(name='list', aliases=['l', 'who', 'lsit'])
|
||||
async def online(self, ctx):
|
||||
"""Gives a list of online players."""
|
||||
em = discord.Embed()
|
||||
|
@ -277,7 +278,8 @@ class ServerCommands(commands.Cog):
|
|||
rank_fixed[word] = rank_fixed[word].capitalize()
|
||||
entries.append(format_list_entry(em, json[rank], f'{" ".join(rank_fixed)}'))
|
||||
|
||||
order = ['Owners', 'Executives', 'Developers', 'Senior Admins', 'Admins', 'Master Builders', 'Operators', 'Imposters']
|
||||
order = ['Owners', 'Executives', 'Developers', 'Senior Admins', 'Admins', 'Master Builders',
|
||||
'Operators', 'Imposters']
|
||||
sorted = [entry for rank in order for entry in entries if entry.name == rank]
|
||||
|
||||
for x in sorted:
|
||||
|
@ -326,19 +328,19 @@ class ServerCommands(commands.Cog):
|
|||
server = 2
|
||||
if get_server_status(server):
|
||||
self.write_telnet_session(server,
|
||||
bytes('lag', 'ascii') + b"\r\n")
|
||||
bytes('lag', 'ascii') + b"\r\n")
|
||||
self.read_until_telnet(
|
||||
bytes('Uptime:', 'ascii'), server)
|
||||
bytes('Uptime:', 'ascii'), server)
|
||||
server_uptime = self.read_until_telnet(
|
||||
bytes('Current TPS =', 'ascii'), server)
|
||||
bytes('Current TPS =', 'ascii'), server)
|
||||
server_tps = self.read_until_telnet(
|
||||
bytes('Maximum memory: ', 'ascii'), server)
|
||||
bytes('Maximum memory: ', 'ascii'), server)
|
||||
maximum_memory = self.read_until_telnet(
|
||||
bytes('Allocated memory:', 'ascii'), server)
|
||||
bytes('Allocated memory:', 'ascii'), server)
|
||||
allocated_memory = self.read_until_telnet(
|
||||
bytes('Free memory:', 'ascii'), server)
|
||||
bytes('Free memory:', 'ascii'), server)
|
||||
free_memory = self.read_until_telnet(
|
||||
bytes('World "world":', 'ascii'), server)
|
||||
bytes('World "world":', 'ascii'), server)
|
||||
|
||||
server_uptime = server_uptime.strip(':Current TPS =')
|
||||
server_tps = server_tps.strip(':Maximum memory:')
|
||||
|
@ -346,10 +348,12 @@ class ServerCommands(commands.Cog):
|
|||
allocated_memory = allocated_memory.strip(':Free memory:')
|
||||
free_memory = free_memory.strip(':World "world":')
|
||||
|
||||
print(f'TPS: {server_tps} UPTIME: {server_uptime} MAX MEM: {maximum_memory} ALLCTD MEM: {allocated_memory} FREE MEM: {free_memory}')
|
||||
print(
|
||||
f'TPS: {server_tps} UPTIME: {server_uptime} MAX MEM: {maximum_memory} ALLCTD MEM: {allocated_memory} FREE MEM: {free_memory}')
|
||||
|
||||
try:
|
||||
server_uptime = re.match('([0-9]+ days? )?([0-9]+ hours )?([0-9]+ minutes )?([0-6]?[0-9] seconds)', server_uptime)[0]
|
||||
server_uptime = \
|
||||
re.match('([0-9]+ days? )?([0-9]+ hours )?([0-9]+ minutes )?([0-6]?[0-9] seconds)', server_uptime)[0]
|
||||
server_tps = re.match('[0-2][0-9].?[0-9]*', server_tps)[0]
|
||||
maximum_memory = re.match('[0-9]+,?[0-9]* MB', maximum_memory)[0]
|
||||
allocated_memory = re.match('[0-9]+,?[0-9]* MB', allocated_memory)[0]
|
||||
|
@ -358,11 +362,11 @@ class ServerCommands(commands.Cog):
|
|||
em.description = f'Something went wrong: {e}'
|
||||
em.colour = 0xFF0000
|
||||
else:
|
||||
em.add_field(name='TPS', value = server_tps, inline=False)
|
||||
em.add_field(name='Uptime', value = server_uptime, inline=False)
|
||||
em.add_field(name='Maximum Memory', value = maximum_memory, inline=False)
|
||||
em.add_field(name='Allocated Memory', value = allocated_memory, inline=False)
|
||||
em.add_field(name='Free Memory', value = free_memory, inline=False)
|
||||
em.add_field(name='TPS', value=server_tps, inline=False)
|
||||
em.add_field(name='Uptime', value=server_uptime, inline=False)
|
||||
em.add_field(name='Maximum Memory', value=maximum_memory, inline=False)
|
||||
em.add_field(name='Allocated Memory', value=allocated_memory, inline=False)
|
||||
em.add_field(name='Free Memory', value=free_memory, inline=False)
|
||||
else:
|
||||
em.description = 'Server is offline'
|
||||
await ctx.send(embed=em)
|
||||
|
|
Loading…
Reference in a new issue