mirror of
https://github.com/skylanix/MamieHenriette.git
synced 2026-02-06 14:50:34 +01:00
Ajout fonctionnalité des commandes Discord
This commit is contained in:
@@ -7,6 +7,7 @@ ENV LANG=fr_FR.UTF-8
|
|||||||
ENV LC_ALL=fr_FR.UTF-8
|
ENV LC_ALL=fr_FR.UTF-8
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
|
||||||
apt-utils \
|
apt-utils \
|
||||||
locales \
|
locales \
|
||||||
python3 \
|
python3 \
|
||||||
@@ -21,7 +22,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|||||||
&& locale-gen \
|
&& locale-gen \
|
||||||
&& rm -rf /var/lib/apt/lists/* \
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
&& rm zabbix-release_latest_7.4+debian12_all.deb
|
&& rm zabbix-release_latest_7.4+debian12_all.deb
|
||||||
|
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
COPY run-web.py .
|
COPY run-web.py .
|
||||||
COPY ./database ./database
|
COPY ./database ./database
|
||||||
|
|||||||
0
database/database.db
Normal file
0
database/database.db
Normal file
@@ -19,3 +19,11 @@ class Message(db.Model):
|
|||||||
enable = db.Column(db.Boolean, default=False)
|
enable = db.Column(db.Boolean, default=False)
|
||||||
text = db.Column(db.String(256))
|
text = db.Column(db.String(256))
|
||||||
periodicity = db.Column(db.Integer)
|
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))
|
||||||
|
|
||||||
|
|||||||
@@ -22,3 +22,12 @@ CREATE TABLE IF NOT EXISTS `message` (
|
|||||||
`text` VARCHAR(256) NULL,
|
`text` VARCHAR(256) NULL,
|
||||||
periodicity INTEGER 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
|
||||||
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import requests
|
|||||||
|
|
||||||
from database import db
|
from database import db
|
||||||
from database.helpers import ConfigurationHelper
|
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 protondb import searhProtonDb
|
||||||
from discord import Message
|
from discord import Message
|
||||||
|
|
||||||
@@ -67,8 +67,20 @@ intents = discord.Intents.default()
|
|||||||
intents.message_content = True
|
intents.message_content = True
|
||||||
bot = DiscordBot(intents=intents)
|
bot = DiscordBot(intents=intents)
|
||||||
|
|
||||||
|
# https://discordpy.readthedocs.io/en/stable/quickstart.html
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_message(message: Message):
|
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(ConfigurationHelper().getValue('proton_db_enable_enable') and message.content.find('!protondb')==0) :
|
||||||
if (message.content.find('<@')>0) :
|
if (message.content.find('<@')>0) :
|
||||||
mention = message.content[message.content.find('<@'):]
|
mention = message.content[message.content.find('<@'):]
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ services:
|
|||||||
restart: on-failure
|
restart: on-failure
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
- TZ=Europe/Zurich # Fuseau horaire
|
- TZ=Europe/Paris # Fuseau horaire
|
||||||
- ENABLE_ZABBIX=false # Surveillance désactivée
|
- ENABLE_ZABBIX=false # Surveillance désactivée
|
||||||
- ZABBIX_SERVER=zabbix-server.example.com
|
- ZABBIX_SERVER=zabbix-server.example.com
|
||||||
- ZABBIX_HOSTNAME=mamie-henriette-bot
|
- ZABBIX_HOSTNAME=mamie-henriette-bot
|
||||||
|
|||||||
@@ -1,6 +1,49 @@
|
|||||||
from flask import render_template
|
from flask import render_template, request, redirect, url_for, flash
|
||||||
from webapp import webapp
|
from webapp import webapp
|
||||||
|
from database import db
|
||||||
|
from database.models import Commande
|
||||||
|
|
||||||
@webapp.route("/commandes")
|
@webapp.route("/commandes")
|
||||||
def 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/<int:commande_id>")
|
||||||
|
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/<int:commande_id>")
|
||||||
|
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/<int:commande_id>")
|
||||||
|
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'))
|
||||||
|
|||||||
@@ -1,3 +1,12 @@
|
|||||||
header nav img {
|
header nav img {
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.table_td {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: normal;
|
||||||
|
max-width: 250px;
|
||||||
|
text-align: left;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
@@ -1,6 +1,55 @@
|
|||||||
{% extends "template.html" %}
|
{% extends "template.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Configuration des Commandes.</h1>
|
<h1>Commandes de Mamie</h1>
|
||||||
<p>TODO</p>
|
<p>Gérez les commandes personnalisées du bot. Ces commandes peuvent être activées sur Discord et/ou Twitch selon vos besoins.</p>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="table_td">Commande</th>
|
||||||
|
<th class="table_td">Réponse</th>
|
||||||
|
<th class="table_td">Discord</th>
|
||||||
|
<th class="table_td">Twitch</th>
|
||||||
|
<th class="table_td">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for commande in commandes %}
|
||||||
|
<tr>
|
||||||
|
<td class="table_td">{{ commande.trigger }}</td>
|
||||||
|
<td class="table_td">{{ commande.response }}</td>
|
||||||
|
<td class="table_td">
|
||||||
|
<a href="{{ url_for('toggle_discord_commande', commande_id = commande.id) }}" style="text-decoration: none; font-size: 1.2em;">
|
||||||
|
{{ '✅' if commande.discord_enable else '❌' }}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td class="table_td">
|
||||||
|
<a href="{{ url_for('toggle_twitch_commande', commande_id = commande.id) }}" style="text-decoration: none; font-size: 1.2em;">
|
||||||
|
{{ '✅' if commande.twitch_enable else '❌' }}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td class="table_td">
|
||||||
|
<a href="{{ url_for('delete_commande', commande_id = commande.id) }}" onclick="return confirm('Êtes-vous sûr de vouloir supprimer cette commande ?')">Supprimer</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h2>Ajouter une commande</h2>
|
||||||
|
<form action="{{ url_for('add_commande') }}" method="POST">
|
||||||
|
<label for="trigger">Commande</label>
|
||||||
|
<input name="trigger" type="text" />
|
||||||
|
<label for="response">Réponse</label>
|
||||||
|
<textarea name="response" rows="5" cols="50"></textarea>
|
||||||
|
<div>
|
||||||
|
<label for="discord_enable">Discord</label>
|
||||||
|
<input name="discord_enable" type="checkbox" checked />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="twitch_enable">Twitch</label>
|
||||||
|
<input name="twitch_enable" type="checkbox" unchecked />
|
||||||
|
</div>
|
||||||
|
<input type="Submit" value="Ajouter">
|
||||||
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
{% extends "template.html" %}
|
{% extends "template.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Configuration de Mamie.</h1>
|
<h1>Configuration de Mamie</h1>
|
||||||
|
<p>Configurez les tokens Discord, les notifications Humble Bundle et l'API ProtonDB pour la commande !protondb.</p>
|
||||||
|
|
||||||
<h2>Humble Bundle</h2>
|
<h2>Humble Bundle</h2>
|
||||||
<form action="{{ url_for('updateConfiguration') }}" method="POST">
|
<form action="{{ url_for('updateConfiguration') }}" method="POST">
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
{% extends "template.html" %}
|
{% extends "template.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Humeurs de Mamie.</h1>
|
<h1>Humeurs de Mamie</h1>
|
||||||
|
<p>Définissez les statuts Discord qui changeront automatiquement toutes les 10 minutes pour donner de la personnalité à votre bot.</p>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Text</th>
|
<th class="table_td">Text</th>
|
||||||
<th>Action</th>
|
<th class="table_td">Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for humeur in humeurs %}
|
{% for humeur in humeurs %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{humeur.text}}</td>
|
<td class="table_td">{{humeur.text}}</td>
|
||||||
<td><a href="{{ url_for('delHumeur', id = humeur.id) }}">Supprimer</a></td>
|
<td class="table_td"><a href="{{ url_for('delHumeur', id = humeur.id) }}" onclick="return confirm('Êtes-vous sûr de vouloir supprimer cette humeur ?')">Supprimer</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{% extends "template.html" %}
|
{% extends "template.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Configuration des Messages.</h1>
|
<h1>Messages de Mamie</h1>
|
||||||
<p>TODO</p>
|
<p>TODO</p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{% extends "template.html" %}
|
{% extends "template.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Modération.</h1>
|
<h1>Modération</h1>
|
||||||
<p>TODO</p>
|
<p>Outils de modération communautaire pour gérer votre serveur Discord (fonctionnalité en développement).</p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user