Migration de Kuby vers disnake
This commit is contained in:
parent
dc6e235f27
commit
c8c579eefe
36 changed files with 1205 additions and 1253 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import discord
|
||||
from discord.ext import commands, tasks
|
||||
from discord import app_commands
|
||||
import disnake
|
||||
from disnake.ext import commands, tasks
|
||||
import json
|
||||
import os
|
||||
import asyncio
|
||||
|
|
@ -57,8 +56,8 @@ class Blacklist(commands.Cog):
|
|||
agents = load_json(AGENTS_FILE, {"agents": []})
|
||||
return str(user_id) in agents["agents"]
|
||||
|
||||
@app_commands.command(name="blacklist", description="Blacklist un utilisateur")
|
||||
async def blacklist(self, interaction: discord.Interaction, user: discord.User, reason: str = "Aucune raison fournie"):
|
||||
@commands.slash_command(name="blacklist", description="Blacklist un utilisateur")
|
||||
async def blacklist(self, interaction: disnake.ApplicationCommandInteraction, user: disnake.User, reason: str = "Aucune raison fournie"):
|
||||
if not self.is_agent(interaction.user.id):
|
||||
return await interaction.response.send_message("⛔ Tu n’as pas la permission.", ephemeral=True)
|
||||
|
||||
|
|
@ -70,7 +69,7 @@ class Blacklist(commands.Cog):
|
|||
save_json(BLACKLIST_FILE, blacklist)
|
||||
|
||||
# Préparer l'embed pro
|
||||
embed = discord.Embed(
|
||||
embed = disnake.Embed(
|
||||
title="🚫 Mise en blacklist - Réseau Omega Kube",
|
||||
description=(
|
||||
f"Bonjour {user.mention},\n\n"
|
||||
|
|
@ -82,7 +81,7 @@ class Blacklist(commands.Cog):
|
|||
"📩 Vous disposez de **7 jours** pour contester cette décision en ouvrant un ticket via le bouton ci-dessous.\n\n"
|
||||
"⏳ Passé ce délai, vous serez **définitivement banni de tout le réseau**, sans autre recours possible."
|
||||
),
|
||||
color=discord.Color.red()
|
||||
color=disnake.Color.red()
|
||||
)
|
||||
embed.set_footer(text="Omega Kube - Nixfix06 & Mgstudios")
|
||||
|
||||
|
|
@ -122,8 +121,8 @@ class Blacklist(commands.Cog):
|
|||
ephemeral=True
|
||||
)
|
||||
|
||||
@app_commands.command(name="unblacklist", description="Retirer un utilisateur de la blacklist")
|
||||
async def unblacklist(self, interaction: discord.Interaction, user: discord.User):
|
||||
@commands.slash_command(name="unblacklist", description="Retirer un utilisateur de la blacklist")
|
||||
async def unblacklist(self, interaction: disnake.ApplicationCommandInteraction, user: disnake.User):
|
||||
if not self.is_agent(interaction.user.id):
|
||||
return await interaction.response.send_message("⛔ Tu n’as pas la permission.", ephemeral=True)
|
||||
|
||||
|
|
@ -163,21 +162,21 @@ class Blacklist(commands.Cog):
|
|||
save_json(BLACKLIST_FILE, blacklist)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message(self, message: discord.Message):
|
||||
async def on_message(self, message: disnake.Message):
|
||||
if message.author.bot:
|
||||
return
|
||||
|
||||
tickets = load_json(TICKETS_FILE, {})
|
||||
|
||||
if isinstance(message.channel, discord.DMChannel):
|
||||
if isinstance(message.channel, disnake.DMChannel):
|
||||
user_id = str(message.author.id)
|
||||
if user_id in tickets:
|
||||
guild = self.bot.get_guild(MAIN_GUILD_ID)
|
||||
ticket_channel = guild.get_channel(tickets[user_id]["channel_id"])
|
||||
if ticket_channel:
|
||||
embed = discord.Embed(
|
||||
embed = disnake.Embed(
|
||||
description=message.content,
|
||||
color=discord.Color.blue()
|
||||
color=disnake.Color.blue()
|
||||
).set_author(name=message.author, icon_url=message.author.display_avatar.url)
|
||||
await ticket_channel.send(embed=embed)
|
||||
|
||||
|
|
@ -186,22 +185,22 @@ class Blacklist(commands.Cog):
|
|||
if message.channel.id == data["channel_id"] and self.is_agent(message.author.id):
|
||||
user = await self.bot.fetch_user(int(user_id))
|
||||
try:
|
||||
embed = discord.Embed(
|
||||
embed = disnake.Embed(
|
||||
description=message.content,
|
||||
color=discord.Color.green()
|
||||
color=disnake.Color.green()
|
||||
).set_author(name=f"Agent {message.author}", icon_url=message.author.display_avatar.url)
|
||||
await user.send(embed=embed)
|
||||
except:
|
||||
pass
|
||||
|
||||
# --------- Boutons ---------
|
||||
class TicketButton(discord.ui.View):
|
||||
class TicketButton(disnake.ui.View):
|
||||
def __init__(self, user_id: int):
|
||||
super().__init__(timeout=None)
|
||||
self.user_id = user_id
|
||||
|
||||
@discord.ui.button(label="📩 Ouvrir une demande de révision", style=discord.ButtonStyle.primary, custom_id="blacklist_open_ticket")
|
||||
async def open_ticket(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||
@disnake.ui.button(label="📩 Ouvrir une demande de révision", style=disnake.ButtonStyle.primary, custom_id="blacklist_open_ticket")
|
||||
async def open_ticket(self, interaction: disnake.Interaction, button: disnake.ui.Button):
|
||||
if interaction.user.id != self.user_id:
|
||||
return await interaction.response.send_message("❌ Ce bouton ne t’appartient pas.", ephemeral=True)
|
||||
|
||||
|
|
@ -209,7 +208,7 @@ class TicketButton(discord.ui.View):
|
|||
if str(self.user_id) in tickets:
|
||||
return await interaction.response.send_message("❌ Tu as déjà un ticket ouvert.", ephemeral=True)
|
||||
|
||||
guild = interaction.client.get_guild(MAIN_GUILD_ID)
|
||||
guild = interaction.bot.get_guild(MAIN_GUILD_ID)
|
||||
category = guild.get_channel(TICKET_CATEGORY_ID)
|
||||
|
||||
ticket_channel = await guild.create_text_channel(
|
||||
|
|
@ -222,10 +221,10 @@ class TicketButton(discord.ui.View):
|
|||
save_json(TICKETS_FILE, tickets)
|
||||
|
||||
view_close = CloseTicketView(self.user_id)
|
||||
embed = discord.Embed(
|
||||
embed = disnake.Embed(
|
||||
title="📩 Ticket ouvert",
|
||||
description=f"Un utilisateur blacklisté (<@{self.user_id}>) a ouvert une demande de révision.\n\nUn agent Omega Kube prendra en charge ce dossier.",
|
||||
color=discord.Color.blurple()
|
||||
color=disnake.Color.blurple()
|
||||
)
|
||||
await ticket_channel.send(embed=embed, view=view_close)
|
||||
|
||||
|
|
@ -234,27 +233,27 @@ class TicketButton(discord.ui.View):
|
|||
button.disabled = True
|
||||
self.stop()
|
||||
|
||||
class CloseTicketView(discord.ui.View):
|
||||
class CloseTicketView(disnake.ui.View):
|
||||
def __init__(self, user_id: int):
|
||||
super().__init__(timeout=None)
|
||||
self.user_id = user_id
|
||||
|
||||
@discord.ui.button(label="❌ Fermer le ticket", style=discord.ButtonStyle.danger, custom_id="blacklist_close_ticket")
|
||||
async def close_ticket(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||
if not interaction.client.get_cog("Blacklist").is_agent(interaction.user.id):
|
||||
@disnake.ui.button(label="❌ Fermer le ticket", style=disnake.ButtonStyle.danger, custom_id="blacklist_close_ticket")
|
||||
async def close_ticket(self, interaction: disnake.Interaction, button: disnake.ui.Button):
|
||||
if not interaction.bot.get_cog("Blacklist").is_agent(interaction.user.id):
|
||||
return await interaction.response.send_message("⛔ Seuls les agents peuvent fermer ce ticket.", ephemeral=True)
|
||||
|
||||
view = ConfirmCloseView(self.user_id)
|
||||
await interaction.response.send_message("⚠️ Veux-tu vraiment fermer ce ticket ?", view=view, ephemeral=True)
|
||||
|
||||
class ConfirmCloseView(discord.ui.View):
|
||||
class ConfirmCloseView(disnake.ui.View):
|
||||
def __init__(self, user_id: int):
|
||||
super().__init__(timeout=30)
|
||||
self.user_id = user_id
|
||||
|
||||
@discord.ui.button(label="✅ Oui", style=discord.ButtonStyle.success, custom_id="blacklist_confirm_close")
|
||||
async def confirm(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||
if not interaction.client.get_cog("Blacklist").is_agent(interaction.user.id):
|
||||
@disnake.ui.button(label="✅ Oui", style=disnake.ButtonStyle.success, custom_id="blacklist_confirm_close")
|
||||
async def confirm(self, interaction: disnake.Interaction, button: disnake.ui.Button):
|
||||
if not interaction.bot.get_cog("Blacklist").is_agent(interaction.user.id):
|
||||
return await interaction.response.send_message("⛔ Tu n’as pas la permission.", ephemeral=True)
|
||||
|
||||
tickets = load_json(TICKETS_FILE, {})
|
||||
|
|
@ -268,19 +267,19 @@ class ConfirmCloseView(discord.ui.View):
|
|||
del tickets[str(self.user_id)]
|
||||
save_json(TICKETS_FILE, tickets)
|
||||
|
||||
user = await interaction.client.fetch_user(int(self.user_id))
|
||||
user = await interaction.bot.fetch_user(int(self.user_id))
|
||||
try:
|
||||
embed = discord.Embed(
|
||||
embed = disnake.Embed(
|
||||
title="🔒 Ticket fermé",
|
||||
description="Ton ticket a été examiné et fermé.\n\n⚠️ Après analyse, la sanction est confirmée et tu restes blacklisté de l’ensemble du réseau.",
|
||||
color=discord.Color.orange()
|
||||
color=disnake.Color.orange()
|
||||
)
|
||||
await user.send(embed=embed)
|
||||
await asyncio.sleep(2)
|
||||
except:
|
||||
pass
|
||||
|
||||
for guild in interaction.client.guilds:
|
||||
for guild in interaction.bot.guilds:
|
||||
member = guild.get_member(self.user_id)
|
||||
if member:
|
||||
try:
|
||||
|
|
@ -290,8 +289,8 @@ class ConfirmCloseView(discord.ui.View):
|
|||
|
||||
await interaction.response.send_message("✅ Ticket fermé avec succès.", ephemeral=True)
|
||||
|
||||
@discord.ui.button(label="❌ Non", style=discord.ButtonStyle.secondary, custom_id="blacklist_cancel_close")
|
||||
async def cancel(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||
@disnake.ui.button(label="❌ Non", style=disnake.ButtonStyle.secondary, custom_id="blacklist_cancel_close")
|
||||
async def cancel(self, interaction: disnake.Interaction, button: disnake.ui.Button):
|
||||
await interaction.response.send_message("❌ Fermeture annulée.", ephemeral=True)
|
||||
|
||||
# --------- Setup ---------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue