/ commands / oyuncular.py
oyuncular.py
 1  import math
 2  
 3  import discord
 4  
 5  from config import PLAYERS_PER_PAGE
 6  from exaroton import get_server_info
 7  from storage import load_data
 8  from views import PlayersView
 9  
10  
11  def register(tree):
12      @tree.command(name="oyuncular", description="Kayıtlı oyuncuları ve aktiflik durumlarını gösterir.")
13      async def oyuncular(interaction: discord.Interaction):
14          await interaction.response.defer()
15          data = load_data()
16  
17          if not data:
18              return await interaction.followup.send("Henüz kayıtlı oyuncu yok.")
19  
20          server_info = await get_server_info()
21          online_players = []
22          if server_info.get("success") and server_info.get("data"):
23              player_data = server_info["data"].get("players", {})
24              online_players = [p.lower() for p in (player_data.get("list") or [])]
25  
26          entries = []
27          for uid, info in data.items():
28              username = info["username"]
29              is_online = username.lower() in online_players
30              status = "\u2022" if not is_online else "\u25B6"
31              mention = f"<@{info['discord_id']}>"
32              entries.append(f"`{status}` **{username}** — {mention}")
33  
34          total_pages = max(1, math.ceil(len(entries) / PLAYERS_PER_PAGE))
35          pages = []
36          for i in range(total_pages):
37              start = i * PLAYERS_PER_PAGE
38              end = start + PLAYERS_PER_PAGE
39              page_entries = entries[start:end]
40  
41              embed = discord.Embed(
42                  title="Kayıtlı Oyuncular",
43                  description="\n".join(page_entries),
44                  color=discord.Color.blurple(),
45              )
46              embed.set_footer(text=f"Sayfa {i + 1}/{total_pages} | Toplam {len(entries)} oyuncu")
47              pages.append(embed)
48  
49          if total_pages > 1:
50              await interaction.followup.send(embed=pages[0], view=PlayersView(pages, interaction.user.id))
51          else:
52              await interaction.followup.send(embed=pages[0])