Migration vers Disnake et ajout des components V2
This commit is contained in:
parent
c8c579eefe
commit
98f7501e07
47 changed files with 1196 additions and 722 deletions
|
|
@ -7,7 +7,7 @@ import re
|
|||
|
||||
class ModReasonModal(disnake.ui.Modal):
|
||||
def __init__(self, parent_view, action_type):
|
||||
super().__init__(title=f"Raison pour {action_type}")
|
||||
super().__init__(title=f"Raison pour {action_type}", components=[])
|
||||
self.parent_view = parent_view
|
||||
self.action_type = action_type
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ class ModReasonModal(disnake.ui.Modal):
|
|||
required=True,
|
||||
max_length=500
|
||||
)
|
||||
self.add_item(self.reason)
|
||||
self.append_component(self.reason)
|
||||
|
||||
if action_type == "TIMEOUT":
|
||||
self.duration = disnake.ui.TextInput(
|
||||
|
|
@ -26,7 +26,7 @@ class ModReasonModal(disnake.ui.Modal):
|
|||
required=True,
|
||||
max_length=10
|
||||
)
|
||||
self.add_item(self.duration)
|
||||
self.append_component(self.duration)
|
||||
|
||||
async def callback(self, interaction: disnake.Interaction):
|
||||
reason = self.reason.value
|
||||
|
|
@ -78,43 +78,43 @@ class ModPanelView(disnake.ui.View):
|
|||
await interaction.edit_original_response(embed=embed, view=self)
|
||||
|
||||
@disnake.ui.button(label="Avertir", style=disnake.ButtonStyle.secondary, emoji="⚠️")
|
||||
async def warn_btn(self, interaction: disnake.Interaction, button: disnake.ui.Button):
|
||||
async def warn_btn(self, button: disnake.ui.Button, interaction: disnake.Interaction):
|
||||
await interaction.response.send_modal(ModReasonModal(self, "WARN"))
|
||||
|
||||
@disnake.ui.button(label="Timeout", style=disnake.ButtonStyle.secondary, emoji="⏳")
|
||||
async def timeout_btn(self, interaction: disnake.Interaction, button: disnake.ui.Button):
|
||||
async def timeout_btn(self, button: disnake.ui.Button, interaction: disnake.Interaction):
|
||||
await interaction.response.send_modal(ModReasonModal(self, "TIMEOUT"))
|
||||
|
||||
@disnake.ui.button(label="Expulser", style=disnake.ButtonStyle.secondary, emoji="👢")
|
||||
async def kick_btn(self, interaction: disnake.Interaction, button: disnake.ui.Button):
|
||||
async def kick_btn(self, button: disnake.ui.Button, interaction: disnake.Interaction):
|
||||
await interaction.response.send_modal(ModReasonModal(self, "KICK"))
|
||||
|
||||
@disnake.ui.button(label="Bannir", style=disnake.ButtonStyle.danger, emoji="🔨")
|
||||
async def ban_btn(self, interaction: disnake.Interaction, button: disnake.ui.Button):
|
||||
async def ban_btn(self, button: disnake.ui.Button, interaction: disnake.Interaction):
|
||||
await interaction.response.send_modal(ModReasonModal(self, "BAN"))
|
||||
|
||||
@disnake.ui.button(label="Historique", style=disnake.ButtonStyle.primary, emoji="📜")
|
||||
async def history_btn(self, interaction: disnake.Interaction, button: disnake.ui.Button):
|
||||
async def history_btn(self, button: disnake.ui.Button, interaction: disnake.Interaction):
|
||||
cog = interaction.bot.get_cog("Moderation")
|
||||
await cog.history(interaction, self.member)
|
||||
|
||||
@disnake.ui.button(label="Clear Warns", style=disnake.ButtonStyle.danger, emoji="🧹")
|
||||
async def clear_btn(self, interaction: disnake.Interaction, button: disnake.ui.Button):
|
||||
async def clear_btn(self, button: disnake.ui.Button, interaction: disnake.Interaction):
|
||||
cog = interaction.bot.get_cog("Moderation")
|
||||
await cog.clearwarns(interaction, self.member, reason="Nettoyage via Panel")
|
||||
await self.update_panel(interaction)
|
||||
|
||||
class ModConfigModal(disnake.ui.Modal):
|
||||
def __init__(self, field_name, current_value):
|
||||
super().__init__(title=f"Modifier {field_name}")
|
||||
super().__init__(components=[], title=f"Modifier {field_name}")
|
||||
self.field_name = field_name
|
||||
self.input = disnake.ui.TextInput(
|
||||
label=field_name,
|
||||
default=str(current_value),
|
||||
value=str(current_value),
|
||||
placeholder="Entrez une valeur numérique...",
|
||||
required=True
|
||||
)
|
||||
self.add_item(self.input)
|
||||
self.append_component(self.input)
|
||||
|
||||
async def callback(self, interaction: disnake.Interaction):
|
||||
value = self.input.value
|
||||
|
|
@ -146,7 +146,7 @@ class ModConfigView(disnake.ui.View):
|
|||
self.db_path = db_path
|
||||
|
||||
@disnake.ui.button(label="Log Channel", style=disnake.ButtonStyle.primary, emoji="📁")
|
||||
async def log_btn(self, interaction: disnake.Interaction, button: disnake.ui.Button):
|
||||
async def log_btn(self, button: disnake.ui.Button, interaction: disnake.Interaction):
|
||||
view = disnake.ui.View()
|
||||
select = disnake.ui.ChannelSelect(
|
||||
placeholder="Sélectionnez le salon de logs...",
|
||||
|
|
@ -166,7 +166,7 @@ class ModConfigView(disnake.ui.View):
|
|||
await interaction.response.send_message("Choisissez le salon de logs :", view=view, ephemeral=True)
|
||||
|
||||
@disnake.ui.button(label="Paliers Warns", style=disnake.ButtonStyle.secondary, emoji="⚖️")
|
||||
async def limits_btn(self, interaction: disnake.Interaction, button: disnake.ui.Button):
|
||||
async def limits_btn(self, button: disnake.ui.Button, interaction: disnake.Interaction):
|
||||
conn = sqlite3.connect(self.db_path)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT warn_limit_timeout, warn_limit_kick, warn_limit_ban FROM mod_config WHERE guild_id = ?", (self.guild_id,))
|
||||
|
|
@ -187,7 +187,7 @@ class ModConfigView(disnake.ui.View):
|
|||
await interaction.response.send_message("Quelle limite modifier ?", view=view, ephemeral=True)
|
||||
|
||||
@disnake.ui.button(label="Durée Timeout", style=disnake.ButtonStyle.secondary, emoji="⏱️")
|
||||
async def duration_btn(self, interaction: disnake.Interaction, button: disnake.ui.Button):
|
||||
async def duration_btn(self, button: disnake.ui.Button, interaction: disnake.Interaction):
|
||||
conn = sqlite3.connect(self.db_path)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT timeout_duration FROM mod_config WHERE guild_id = ?", (self.guild_id,))
|
||||
|
|
@ -320,5 +320,5 @@ class Moderation(commands.Cog):
|
|||
if not interaction.response.is_done(): await interaction.response.send_message(f"✅ Warns de {member.name} effacés.", ephemeral=True)
|
||||
else: await interaction.followup.send(f"✅ Warns de {member.name} effacés.", ephemeral=True)
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(Moderation(bot))
|
||||
def setup(bot):
|
||||
bot.add_cog(Moderation(bot))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue