You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
2.6 KiB
54 lines
2.6 KiB
import discord
|
|
|
|
class Extension:
|
|
def __init__(self, core):
|
|
@core.tree.command(name = "servers", description = "Показать статистику с серверов")
|
|
@discord.app_commands.describe(server = "ид сервера в формате srv1")
|
|
async def get_servers(
|
|
interaction: discord.Interaction,
|
|
server: str = ""
|
|
):
|
|
await interaction.response.defer(thinking=True)
|
|
steam64 = await core.GetSteam64OfDiscord(interaction.user)
|
|
embed = discord.Embed()
|
|
|
|
if server:
|
|
if not server in core.stats.get("servers", {}).keys():
|
|
return await interaction.followup.send(f"Сервер с таким индификатором не существует, введи существующий из предложенных:\n{' '.join(core.stats.get('servers', {}).keys())}", ephemeral=False)
|
|
embed.add_field(name=core.stats['servers'][server]['name'], value=str_server(core.stats['servers'][server]), inline=False)
|
|
else:
|
|
servers = [server for server in core.stats["servers"].values() if server['status'] == True and server['player_count'] > 0]
|
|
if servers:
|
|
embed.add_field(name = "Где сейчас играют", value = f'{core.stats["statistic"]["player_now"]} карликов', inline=True)
|
|
for server in servers:
|
|
embed.add_field(name = server["name"], value=str_server(server), inline=False)
|
|
|
|
servers = [server for server in core.stats["servers"].values() if server['status'] == True and server['player_count'] == 0]
|
|
if servers:
|
|
embed.add_field(name = "Пустующие сервера", value = f"{len(servers)} штук", inline=True)
|
|
for server in servers:
|
|
embed.add_field(name = server["name"], value=str_server(server), inline=False)
|
|
|
|
#не забудь потом сделать лямбды дурачек
|
|
servers = [server for server in core.stats["servers"].values() if server['status'] == False]
|
|
if servers:
|
|
embed.add_field(name = "Неработающие сервера", value = "пук", inline=True)
|
|
for server in servers:
|
|
embed.add_field(name = server["name"], value=str_server(server), inline=False)
|
|
|
|
return await interaction.followup.send(embed=embed, ephemeral=False)
|
|
|
|
|
|
def str_server(data):
|
|
message = ""
|
|
addr = data['address'].split(":")
|
|
message += f"https://{addr[0]}/connect/{addr[1]}\n"
|
|
if data['status'] == False:
|
|
return message + "Сервер не отвечает"
|
|
|
|
message += f"Карта: {data['map']}\n"
|
|
message += f"Игроков: {data['player_count']}/{data['max_players']}\n"
|
|
message += "\n"
|
|
for player in data['players']:
|
|
message += f"{player['duration']:7} | {player['score']:3} | {player['name']}\n"
|
|
return message
|