mirror of
https://github.com/TotalFreedomMC/TotalFreedomBot.git
synced 2024-12-22 23:54:58 +00:00
Future proofing tf!list command to work iterably, DRY code
This commit is contained in:
parent
5eab00de0e
commit
b8d1862678
1 changed files with 12 additions and 29 deletions
|
@ -1,6 +1,6 @@
|
||||||
import discord
|
import discord
|
||||||
import requests
|
import requests
|
||||||
|
import re
|
||||||
from checks import *
|
from checks import *
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
@ -185,6 +185,7 @@ 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")
|
||||||
|
@ -223,34 +224,16 @@ class ServerCommands(commands.Cog):
|
||||||
if json["online"] == 0:
|
if json["online"] == 0:
|
||||||
em.description = "There are no online players"
|
em.description = "There are no online players"
|
||||||
else:
|
else:
|
||||||
em.description = "There are {} / {} online players".format(json["online"], json["max"])
|
em.description = f"There are {json['online']} / {json['max']} online players"
|
||||||
owners = json["owners"]
|
ranks = list(json.keys())
|
||||||
if len(owners) != 0:
|
ranks.reverse()
|
||||||
em = format_list_entry(em, owners, "Server Owners")
|
for rank in ranks:
|
||||||
executives = json["executives"]
|
if rank not in ['max', 'online'] and json[rank]:
|
||||||
if len(executives) != 0:
|
rank = rank.split('_')
|
||||||
em = format_list_entry(em, executives, "Executives")
|
for word in range(len(rank)):
|
||||||
developers = json["developers"]
|
rank[word] = rank[word].capitalize()
|
||||||
if len(developers) != 0:
|
em = format_list_entry(em, json[rank], f'{" ".join(rank)}')
|
||||||
em = format_list_entry(em, developers, "Developers")
|
|
||||||
senior_admins = json["senioradmins"]
|
|
||||||
if len(senior_admins) != 0:
|
|
||||||
em = format_list_entry(em, senior_admins, "Senior Admins")
|
|
||||||
admins = json["admins"]
|
|
||||||
if len(admins) != 0:
|
|
||||||
em = format_list_entry(em, admins, "Admins")
|
|
||||||
#trialadmins = json["trialadmins"]
|
|
||||||
#if len(trialadmins) != 0:
|
|
||||||
#em = format_list_entry(em, trialmods, "Trial Mods")
|
|
||||||
masterbuilders = json["masterbuilders"]
|
|
||||||
if len(masterbuilders) != 0:
|
|
||||||
em = format_list_entry(em, masterbuilders, "Master Builders")
|
|
||||||
operators = json["operators"]
|
|
||||||
if len(operators) != 0:
|
|
||||||
em = format_list_entry(em, operators, "Operators")
|
|
||||||
imposters = json["imposters"]
|
|
||||||
if len(imposters) != 0:
|
|
||||||
em = format_list_entry(em, imposters, "Imposters")
|
|
||||||
except:
|
except:
|
||||||
em.description = 'Server is offline'
|
em.description = 'Server is offline'
|
||||||
await ctx.send(embed=em)
|
await ctx.send(embed=em)
|
||||||
|
|
Loading…
Reference in a new issue