diff --git a/database/models.py b/database/models.py index 308f11c..a9c464a 100644 --- a/database/models.py +++ b/database/models.py @@ -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)) + diff --git a/database/schema.sql b/database/schema.sql index de38db0..e9b4dad 100644 --- a/database/schema.sql +++ b/database/schema.sql @@ -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 +); diff --git a/discordbot/__init__.py b/discordbot/__init__.py index 837161c..f7a7da0 100644 --- a/discordbot/__init__.py +++ b/discordbot/__init__.py @@ -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: diff --git a/discordbot/command.py b/discordbot/command.py new file mode 100644 index 0000000..2ca851d --- /dev/null +++ b/discordbot/command.py @@ -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() diff --git a/webapp/__init__.py b/webapp/__init__.py index 357676a..28f6c3c 100644 --- a/webapp/__init__.py +++ b/webapp/__init__.py @@ -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 diff --git a/webapp/moderation.py b/webapp/moderation.py new file mode 100644 index 0000000..ae1df0f --- /dev/null +++ b/webapp/moderation.py @@ -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) + diff --git a/webapp/templates/moderation.html b/webapp/templates/moderation.html new file mode 100644 index 0000000..77de26d --- /dev/null +++ b/webapp/templates/moderation.html @@ -0,0 +1,30 @@ +{% extends "template.html" %} + +{% block content %} +
Liste des avertissements émis sur le serveur Discord.
+| Utilisateur | +Discord ID | +Date & Heure | +Raison | +Staff | +
|---|---|---|---|---|
| {{ warning.username }} | +{{ warning.discord_id }} | +{{ warning.created_at.strftime('%d/%m/%Y %H:%M') if warning.created_at else 'N/A' }} | +{{ warning.reason }} | +{{ warning.staff_name }} | +