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:
Mow
2025-10-14 22:37:28 +02:00
parent 22abbcb02d
commit aff236fd0c
8 changed files with 111 additions and 1 deletions

View File

@@ -40,3 +40,12 @@ class Commande(db.Model):
trigger = db.Column(db.String(32), unique=True)
response = db.Column(db.String(2000))
class Warning(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(256))
discord_id = db.Column(db.String(64))
created_at = db.Column(db.DateTime)
reason = db.Column(db.String(1024))
staff_id = db.Column(db.String(64))
staff_name = db.Column(db.String(256))

View File

@@ -45,3 +45,13 @@ CREATE TABLE IF NOT EXISTS `commande` (
`trigger` VARCHAR(16) UNIQUE NOT NULL,
`response` VARCHAR(2000) NOT NULL
);
CREATE TABLE IF NOT EXISTS `warning` (
id INTEGER PRIMARY KEY AUTOINCREMENT,
`username` VARCHAR(256) NOT NULL,
`discord_id` VARCHAR(64) NOT NULL,
`created_at` DATETIME NOT NULL,
`reason` VARCHAR(1024) NOT NULL,
`staff_id` VARCHAR(64) NOT NULL,
`staff_name` VARCHAR(256) NOT NULL
);

View File

@@ -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
View 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()

View File

@@ -2,4 +2,4 @@ from flask import Flask
webapp = Flask(__name__)
from webapp import commandes, configurations, index, humeurs, protondb, live_alert, twitch_auth
from webapp import commandes, configurations, index, humeurs, protondb, live_alert, twitch_auth, moderation

9
webapp/moderation.py Normal file
View File

@@ -0,0 +1,9 @@
from flask import render_template
from webapp import webapp
from database.models import Warning
@webapp.route("/moderation")
def moderation():
warnings = Warning.query.order_by(Warning.created_at.desc()).all()
return render_template("moderation.html", warnings=warnings)

View File

@@ -0,0 +1,30 @@
{% extends "template.html" %}
{% block content %}
<h1>Modération Discord</h1>
<p>Liste des avertissements émis sur le serveur Discord.</p>
<table>
<thead>
<tr>
<th>Utilisateur</th>
<th>Discord ID</th>
<th>Date & Heure</th>
<th>Raison</th>
<th>Staff</th>
</tr>
</thead>
<tbody>
{% for warning in warnings %}
<tr>
<td>{{ warning.username }}</td>
<td>{{ warning.discord_id }}</td>
<td>{{ warning.created_at.strftime('%d/%m/%Y %H:%M') if warning.created_at else 'N/A' }}</td>
<td>{{ warning.reason }}</td>
<td>{{ warning.staff_name }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@@ -21,6 +21,7 @@
<li><a href="/live-alert">Alerte live</a></li>
<li><a href="/commandes">Commandes</a></li>
<li><a href="/humeurs">Humeurs</a></li>
<li><a href="/moderation">Modération</a></li>
<li><a href="/protondb">ProtonDB</a></li>
<li><a href="/configurations">Configurations</a></li>
</ul>