Browse Source

banlist

huy
gsd 2 years ago
parent
commit
99faa18db1
  1. 14
      player.py
  2. 21
      user_ext/banlist.py

14
player.py

@ -329,4 +329,16 @@ def human_TIME(seconds):
elif d < 2:
return "%d день %d:%02d:%02d" % (d ,h, m, s)
else:
return "%d дней %d:%02d:%02d" % (d ,h, m, s)
return "%d дней %d:%02d:%02d" % (d ,h, m, s)
def ban2message(ban):
message = f"Ник: {ban['player_name']}\n"
message += f"Причина: {ban['ban_reason']}\n"
message += f"Время: {utime2human(ban['ban_utime'])}\n"
message += f"Кто забанил: {ban['banned_by']} | <@{ban['admin_info']['discord_id']}>\n"
if ban['active'] == True:
if ban['ban_length'] == 0:
message += "Данный бан навсегда!\n"
else:
message += f"Дата разбана: {utime2human(ban['ban_utime'] + ban['ban_length_seconds'])}\n"
return message

21
user_ext/banlist.py

@ -0,0 +1,21 @@
import discord
import aiohttp, os
import player
class Extension:
def __init__(self, core):
@core.tree.command(name = "banlist", description = "Посмотреть последнии 10 банов")
async def banlist(
interaction: discord.Interaction
):
await interaction.response.defer(thinking=True)
embed = discord.Embed(title="Последние 10 банов")
ban_list = await self.getBanList(10)
for ban in ban_list:
embed.add_field(name=f"#{ban['id']}", value=player.ban2message(ban), inline=False)
return await interaction.followup.send(embed=embed, ephemeral=False)
async def getBanList(self, limit = 10):
async with aiohttp.ClientSession(cookies={"secretkey":os.getenv("BACKEND_SECRETKEY")}) as session:
async with session.get(f"{os.getenv('BACKEND_URL')}/api/admin/ban/list?limit={limit}", ssl=False) as response:
return await response.json()
Loading…
Cancel
Save