mirror of
https://github.com/skylanix/MamieHenriette.git
synced 2026-02-14 12:10:38 +01:00
Ajouter un modèle d'avertissement et des fonctionnalités de modération
Ajout d'un nouveau modèle Warning dans database/models.py pour suivre les avertissements donnés aux utilisateurs. Mise à jour de database/schema.sql pour créer la table correspondante 'warning'. Amélioration du bot Discord pour gérer les commandes d'avertissement. Ajout d'une route de modération dans webapp pour de futures fonctionnalités de modération. Mise à jour de template.html pour inclure un lien vers la page de modération.
This commit is contained in:
@@ -8,6 +8,7 @@ from database.helpers import ConfigurationHelper
|
||||
from database.models import Configuration, Humeur, Commande
|
||||
from discord import Message, TextChannel
|
||||
from discordbot.humblebundle import checkHumbleBundleAndNotify
|
||||
from discordbot.command import handle_warning_command
|
||||
from protondb import searhProtonDb
|
||||
|
||||
class DiscordBot(discord.Client):
|
||||
@@ -63,6 +64,12 @@ async def on_message(message: Message):
|
||||
if not message.content.startswith('!'):
|
||||
return
|
||||
command_name = message.content.split()[0]
|
||||
|
||||
if command_name in ['!averto', '!av', '!avertissement', '!warn']:
|
||||
await handle_warning_command(message, bot)
|
||||
return
|
||||
|
||||
|
||||
commande = Commande.query.filter_by(discord_enable=True, trigger=command_name).first()
|
||||
if commande:
|
||||
try:
|
||||
|
||||
44
discordbot/command.py
Normal file
44
discordbot/command.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import discord
|
||||
from datetime import datetime
|
||||
from database import db
|
||||
from database.models import Warning
|
||||
from discord import Message
|
||||
|
||||
STAFF_ROLE_ID = 581990740431732738
|
||||
|
||||
async def handle_warning_command(message: Message, bot):
|
||||
if not any(role.id == STAFF_ROLE_ID for role in message.author.roles):
|
||||
return
|
||||
|
||||
parts = message.content.split(maxsplit=2)
|
||||
|
||||
if len(parts) < 2 or not message.mentions:
|
||||
return
|
||||
|
||||
target_user = message.mentions[0]
|
||||
reason = parts[2] if len(parts) > 2 else "Sans raison"
|
||||
|
||||
warning = Warning(
|
||||
username=target_user.name,
|
||||
discord_id=str(target_user.id),
|
||||
created_at=datetime.utcnow(),
|
||||
reason=reason,
|
||||
staff_id=str(message.author.id),
|
||||
staff_name=message.author.name
|
||||
)
|
||||
db.session.add(warning)
|
||||
db.session.commit()
|
||||
|
||||
embed = discord.Embed(
|
||||
title="⚠️ Avertissement",
|
||||
description=f"{target_user.mention} a reçu un avertissement de la part de l'équipe de modération",
|
||||
color=discord.Color.red(),
|
||||
timestamp=datetime.utcnow()
|
||||
)
|
||||
embed.add_field(name="👤 Utilisateur", value=f"{target_user.name}\n`{target_user.id}`", inline=True)
|
||||
#embed.add_field(name="🛡️ Modérateur", value=f"{message.author.name}\n`{message.author.id}`", inline=True)
|
||||
embed.add_field(name="📝 Raison", value=reason, inline=False)
|
||||
embed.set_footer(text="Mamie Henriette")
|
||||
|
||||
await message.channel.send(embed=embed)
|
||||
await message.delete()
|
||||
Reference in New Issue
Block a user