1+ import json
2+ import discord
3+ from discord .ext import commands
4+ from discord import app_commands
5+ import os
6+ from dotenv import load_dotenv
7+
8+ BLACKLIST_ARCHIVE = "blacklisted_users.json" # arquivo da Caramelo BlackList
9+
10+ load_dotenv ()
11+
12+ owner_id = os .getenv ("OWNER_ID" )
13+
14+ # --- BOT --- #
15+ bot = commands .Bot (command_prefix = "!" , intents = discord .Intents .all ())
16+ # ----------- #
17+
18+ def load_blacklist ():
19+ try :
20+ with open ('blacklisted_users.json' , 'r' ) as f :
21+ return json .load (f )
22+ except (FileNotFoundError , json .JSONDecodeError ):
23+ return {"usuarios" : [], "servidores" : []} # Retorna nada quando tiver erro
24+
25+ def save_blacklist ():
26+ with open ('blacklisted_users.json' , 'w' ) as f :
27+ json .dump (blacklist_data , f , indent = 4 )
28+
29+ blacklist_data = load_blacklist () # carrega os dados na memória ao iniciar
30+
31+ @bot .check
32+ async def check_blacklist (interaction : discord .Interaction ):
33+ user_id = interaction .user .id
34+ guild_id = interaction .guild .id if interaction .guild else None
35+
36+ if user_id in blacklist_data ["usuarios" ]:
37+ await interaction .response .send_message ("🚫 Você está na minha blacklist e não pode usar meus comandos!" , ephemeral = True )
38+ return False
39+ return True
40+
41+ if guild_id in blacklist_data ["servidores" ]:
42+ return False
43+
44+ return True
45+
46+ @bot .tree .command (name = "blacklist_add" , description = "[Caramelo Blacklist] Adiciona um usuário à blacklist" )
47+ async def blacklist_add (interaction : discord .Interaction , usuario : discord .User ):
48+
49+ if owner_id :
50+ if usuario .id not in blacklist_data ["usuarios" ]:
51+ blacklist_data ["usuarios" ].append (usuario .id )
52+ save_blacklist ()
53+ await interaction .response .send_message (f"✅ { usuario .name } foi silenciado globalmente." )
54+ else :
55+ await interaction .response .send_message ("Este usuário já está na lista." , ephemeral = True )
56+
57+ if not owner_id :
58+ await interaction .response .send_message ("Você não pode usar esse comando!" )
59+
60+ # TODO: /blacklist_remove
0 commit comments