diff --git a/Dockerfile b/Dockerfile index 5c46637..e19f0bb 100755 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ ENV LANG=fr_FR.UTF-8 ENV LC_ALL=fr_FR.UTF-8 RUN apt-get update && apt-get install -y --no-install-recommends \ + apt-utils \ locales \ python3 \ @@ -21,7 +22,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && locale-gen \ && rm -rf /var/lib/apt/lists/* \ && rm zabbix-release_latest_7.4+debian12_all.deb - COPY requirements.txt . COPY run-web.py . COPY ./database ./database diff --git a/database/database.db b/database/database.db new file mode 100644 index 0000000..e69de29 diff --git a/database/models.py b/database/models.py index 020a25e..e3eb3f3 100644 --- a/database/models.py +++ b/database/models.py @@ -19,3 +19,11 @@ class Message(db.Model): enable = db.Column(db.Boolean, default=False) text = db.Column(db.String(256)) periodicity = db.Column(db.Integer) + +class Commande(db.Model): + id = db.Column(db.Integer, primary_key=True) + discord_enable = db.Column(db.Boolean, default=True) + twitch_enable = db.Column(db.Boolean, default=True) + trigger = db.Column(db.String(32), unique=True) + response = db.Column(db.String(2000)) + diff --git a/database/schema.sql b/database/schema.sql index 7a88e61..c73b09c 100644 --- a/database/schema.sql +++ b/database/schema.sql @@ -22,3 +22,12 @@ CREATE TABLE IF NOT EXISTS `message` ( `text` VARCHAR(256) NULL, periodicity INTEGER NULL ); + +CREATE TABLE IF NOT EXISTS `commande` ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + `discord_enable` BOOLEAN NOT NULL DEFAULT TRUE, + `twitch_enable` BOOLEAN NOT NULL DEFAULT TRUE, + `trigger` VARCHAR(16) UNIQUE NOT NULL, + `response` VARCHAR(2000) NOT NULL +); + diff --git a/discordbot/__init__.py b/discordbot/__init__.py index 54f67d3..b38caf3 100644 --- a/discordbot/__init__.py +++ b/discordbot/__init__.py @@ -8,7 +8,7 @@ import requests from database import db from database.helpers import ConfigurationHelper -from database.models import Configuration, GameBundle, Humeur +from database.models import Configuration, GameBundle, Humeur, Commande from protondb import searhProtonDb from discord import Message @@ -67,8 +67,20 @@ intents = discord.Intents.default() intents.message_content = True bot = DiscordBot(intents=intents) +# https://discordpy.readthedocs.io/en/stable/quickstart.html @bot.event async def on_message(message: Message): + if message.author == bot.user: + return + commandes = Commande.query.filter_by(discord_enable=True).all() + for commande in commandes: + if message.content.find(commande.trigger) == 0: + try: + await message.channel.send(commande.response, suppress_embeds=True) + return + except Exception as e: + logging.error(e) + if(ConfigurationHelper().getValue('proton_db_enable_enable') and message.content.find('!protondb')==0) : if (message.content.find('<@')>0) : mention = message.content[message.content.find('<@'):] diff --git a/docker-compose.yml b/docker-compose.yml index 6cc7840..2c7a4ba 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,27 +4,27 @@ services: mamiehenriette: # Nom du conteneur container_name: MamieHenriette - + # Image hébergée sur GitHub Container Registry image: ghcr.io/skylanix/mamiehenriette:latest - + # Build du conteneur à partir d'un Dockerfile local # build: . # image: mamiehenriette - + # Redémarrage automatique en cas d'erreur restart: on-failure - + environment: - - TZ=Europe/Zurich # Fuseau horaire + - TZ=Europe/Paris # Fuseau horaire - ENABLE_ZABBIX=false # Surveillance désactivée - ZABBIX_SERVER=zabbix-server.example.com - ZABBIX_HOSTNAME=mamie-henriette-bot - + volumes: # Base de données et configuration persistante - ./instance:/app/instance - + ports: # Interface web sur http://localhost:8000 - 5000:5000 diff --git a/run-web.py b/run-web.py index 3dcc0b9..13d9634 100644 --- a/run-web.py +++ b/run-web.py @@ -22,4 +22,4 @@ if __name__ == '__main__': jobs.append(threading.Thread(target=start_server)) for job in jobs: job.start() - for job in jobs: job.join() \ No newline at end of file + for job in jobs: job.join() diff --git a/webapp/commandes.py b/webapp/commandes.py index b764609..a6c24d7 100644 --- a/webapp/commandes.py +++ b/webapp/commandes.py @@ -1,6 +1,49 @@ -from flask import render_template +from flask import render_template, request, redirect, url_for, flash from webapp import webapp +from database import db +from database.models import Commande @webapp.route("/commandes") def commandes(): - return render_template("commandes.html") + commandes_list = Commande.query.all() + return render_template("commandes.html", commandes=commandes_list) + +@webapp.route("/commandes/add", methods=['POST']) +def add_commande(): + trigger = request.form.get('trigger') + response = request.form.get('response') + discord_enable = request.form.get('discord_enable') == 'on' + twitch_enable = request.form.get('twitch_enable') == 'on' + + if trigger and response: + if not trigger.startswith('!'): + trigger = '!' + trigger + + existing = Commande.query.filter_by(trigger=trigger).first() + if not existing: + commande = Commande(trigger=trigger, response=response, discord_enable=discord_enable, twitch_enable=twitch_enable) + db.session.add(commande) + db.session.commit() + + return redirect(url_for('commandes')) + +@webapp.route("/commandes/delete/") +def delete_commande(commande_id): + commande = Commande.query.get_or_404(commande_id) + db.session.delete(commande) + db.session.commit() + return redirect(url_for('commandes')) + +@webapp.route("/commandes/toggle-discord/") +def toggle_discord_commande(commande_id): + commande = Commande.query.get_or_404(commande_id) + commande.discord_enable = not commande.discord_enable + db.session.commit() + return redirect(url_for('commandes')) + +@webapp.route("/commandes/toggle-twitch/") +def toggle_twitch_commande(commande_id): + commande = Commande.query.get_or_404(commande_id) + commande.twitch_enable = not commande.twitch_enable + db.session.commit() + return redirect(url_for('commandes')) diff --git a/webapp/static/css/style.css b/webapp/static/css/style.css index 2b70bac..02c7ce4 100644 --- a/webapp/static/css/style.css +++ b/webapp/static/css/style.css @@ -1,3 +1,12 @@ header nav img { border-radius: 50%; +} + +.table_td { + overflow: hidden; + text-overflow: ellipsis; + white-space: normal; + max-width: 250px; + text-align: left; + vertical-align: top; } \ No newline at end of file diff --git a/webapp/templates/commandes.html b/webapp/templates/commandes.html index afcda8a..ddde145 100644 --- a/webapp/templates/commandes.html +++ b/webapp/templates/commandes.html @@ -1,6 +1,55 @@ {% extends "template.html" %} {% block content %} -

Configuration des Commandes.

-

TODO

+

Commandes de Mamie

+

Gérez les commandes personnalisées du bot. Ces commandes peuvent être activées sur Discord et/ou Twitch selon vos besoins.

+ + + + + + + + + + + + {% for commande in commandes %} + + + + + + + + {% endfor %} + +
CommandeRéponseDiscordTwitchActions
{{ commande.trigger }}{{ commande.response }} + + {{ '✅' if commande.discord_enable else '❌' }} + + + + {{ '✅' if commande.twitch_enable else '❌' }} + + + Supprimer +
+ +

Ajouter une commande

+
+ + + + +
+ + +
+
+ + +
+ +
{% endblock %} \ No newline at end of file diff --git a/webapp/templates/configurations.html b/webapp/templates/configurations.html index e6a568a..749c7e6 100644 --- a/webapp/templates/configurations.html +++ b/webapp/templates/configurations.html @@ -1,7 +1,8 @@ {% extends "template.html" %} {% block content %} -

Configuration de Mamie.

+

Configuration de Mamie

+

Configurez les tokens Discord, les notifications Humble Bundle et l'API ProtonDB pour la commande !protondb.

Humble Bundle

diff --git a/webapp/templates/humeurs.html b/webapp/templates/humeurs.html index 812eea4..09acf67 100644 --- a/webapp/templates/humeurs.html +++ b/webapp/templates/humeurs.html @@ -1,19 +1,20 @@ {% extends "template.html" %} {% block content %} -

Humeurs de Mamie.

+

Humeurs de Mamie

+

Définissez les statuts Discord qui changeront automatiquement toutes les 10 minutes pour donner de la personnalité à votre bot.

- - + + {% for humeur in humeurs %} - - + + {% endfor %} diff --git a/webapp/templates/messages.html b/webapp/templates/messages.html index d96c5bb..5d5133f 100644 --- a/webapp/templates/messages.html +++ b/webapp/templates/messages.html @@ -1,6 +1,6 @@ {% extends "template.html" %} {% block content %} -

Configuration des Messages.

+

Messages de Mamie

TODO

{% endblock %} \ No newline at end of file diff --git a/webapp/templates/moderation.html b/webapp/templates/moderation.html index 12ac839..5b7e122 100644 --- a/webapp/templates/moderation.html +++ b/webapp/templates/moderation.html @@ -1,6 +1,6 @@ {% extends "template.html" %} {% block content %} -

Modération.

-

TODO

+

Modération

+

Outils de modération communautaire pour gérer votre serveur Discord (fonctionnalité en développement).

{% endblock %} \ No newline at end of file
TextActionTextAction
{{humeur.text}}Supprimer{{humeur.text}}Supprimer