From ba7820170c54321881add34265c099d6dbe6be5c Mon Sep 17 00:00:00 2001 From: Kepka Ludovic Date: Fri, 29 Aug 2025 10:27:53 +0200 Subject: [PATCH 01/10] =?UTF-8?q?J'arrive=20=C3=A0=20avoir=20les=20info=20?= =?UTF-8?q?de=20live?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- twitchbot/__init__.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/twitchbot/__init__.py b/twitchbot/__init__.py index 7103c38..061d8b8 100644 --- a/twitchbot/__init__.py +++ b/twitchbot/__init__.py @@ -16,6 +16,8 @@ async def _onReady(ready_event: EventData): logging.info('Bot Twitch prêt') with webapp.app_context(): await ready_event.chat.join_room(ConfigurationHelper().getValue('twitch_channel')) + asyncio.get_event_loop().create_task(twitchBot._checkOnlineStreamers()) + async def _onMessage(msg: ChatMessage): logging.info(f'Dans {msg.room.name}, {msg.user.name} a dit : {msg.text}') @@ -48,6 +50,17 @@ class TwitchBot() : else: logging.info("Twitch n'est pas configuré") + async def _checkOnlineStreamers(self): + # pas bon faudrait faire un truc mieux + while True : + async for stream in self.twitch.get_streams(user_login=['chainesteve']): + print(stream.user_id) + # toutes les 5 minutes + await asyncio.sleep(5*60) + + + + def begin(self): asyncio.run(self._connect()) From fc5697fc3fccb033ed5c9136c47d7d109fd1c7a5 Mon Sep 17 00:00:00 2001 From: Kepka Ludovic Date: Fri, 29 Aug 2025 10:32:41 +0200 Subject: [PATCH 02/10] =?UTF-8?q?uppression=20des=20pages=20qui=20ne=20son?= =?UTF-8?q?t=20pas=20utilis=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/__init__.py | 2 +- webapp/messages.py | 6 ------ webapp/moderation.py | 6 ------ webapp/templates/messages.html | 6 ------ webapp/templates/moderation.html | 6 ------ webapp/templates/template.html | 2 -- 6 files changed, 1 insertion(+), 27 deletions(-) delete mode 100644 webapp/messages.py delete mode 100644 webapp/moderation.py delete mode 100644 webapp/templates/messages.html delete mode 100644 webapp/templates/moderation.html diff --git a/webapp/__init__.py b/webapp/__init__.py index 8620413..341f179 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, messages, moderation, protondb +from webapp import commandes, configurations, index, humeurs, protondb diff --git a/webapp/messages.py b/webapp/messages.py deleted file mode 100644 index 3be8b4d..0000000 --- a/webapp/messages.py +++ /dev/null @@ -1,6 +0,0 @@ -from flask import render_template -from webapp import webapp - -@webapp.route("/messages") -def messages(): - return render_template("messages.html") diff --git a/webapp/moderation.py b/webapp/moderation.py deleted file mode 100644 index 7d59731..0000000 --- a/webapp/moderation.py +++ /dev/null @@ -1,6 +0,0 @@ -from flask import render_template -from webapp import webapp - -@webapp.route("/moderation") -def moderation(): - return render_template("moderation.html") diff --git a/webapp/templates/messages.html b/webapp/templates/messages.html deleted file mode 100644 index 5d5133f..0000000 --- a/webapp/templates/messages.html +++ /dev/null @@ -1,6 +0,0 @@ -{% extends "template.html" %} - -{% block content %} -

Messages de Mamie

-

TODO

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

Modération

-

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

-{% endblock %} \ No newline at end of file diff --git a/webapp/templates/template.html b/webapp/templates/template.html index 628bf7f..86f6506 100644 --- a/webapp/templates/template.html +++ b/webapp/templates/template.html @@ -20,8 +20,6 @@ From 69edfd4771bbb69c956a47999d55e3284d0d0aa6 Mon Sep 17 00:00:00 2001 From: Kepka Ludovic Date: Fri, 29 Aug 2025 13:44:00 +0200 Subject: [PATCH 03/10] Edition des pojos --- database/models.py | 7 ++++ database/schema.sql | 8 +++++ discordbot/__init__.py | 10 +++++- webapp/__init__.py | 2 +- webapp/configurations.py | 7 +--- webapp/live_alert.py | 54 ++++++++++++++++++++++++++++ webapp/static/css/style.css | 4 +++ webapp/templates/commandes.html | 4 +-- webapp/templates/live-alert.html | 60 ++++++++++++++++++++++++++++++++ webapp/templates/template.html | 1 + 10 files changed, 147 insertions(+), 10 deletions(-) create mode 100644 webapp/live_alert.py create mode 100644 webapp/templates/live-alert.html diff --git a/database/models.py b/database/models.py index 1cfca05..5590b51 100644 --- a/database/models.py +++ b/database/models.py @@ -19,6 +19,13 @@ class GameBundle(db.Model): name = db.Column(db.String(256)) json = db.Column(db.String(1024)) +class LiveAlert(db.Model): + id = db.Column(db.Integer, primary_key=True) + enable = db.Column(db.Boolean, default=False) + login = db.Column(db.String(128)) + notify_channel = db.Column(db.Integer) + message = db.Column(db.String(2000)) + class Message(db.Model): id = db.Column(db.Integer, primary_key=True) enable = db.Column(db.Boolean, default=False) diff --git a/database/schema.sql b/database/schema.sql index 24ff873..0989286 100644 --- a/database/schema.sql +++ b/database/schema.sql @@ -22,6 +22,14 @@ CREATE TABLE IF NOT EXISTS `humeur` ( `text` VARCHAR(256) NULL ); +CREATE TABLE IF NOT EXISTS live_alert ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + `enable` BOOLEAN NOT NULL DEFAULT TRUE, + `login` VARCHAR(128) UNIQUE NOT NULL, + `notify_channel` INTEGER NOT NULL, + `message` VARCHAR(2000) NOT NULL +); + CREATE TABLE IF NOT EXISTS `message` ( id INTEGER PRIMARY KEY AUTOINCREMENT, `enable` BOOLEAN NOT NULL DEFAULT FALSE, diff --git a/discordbot/__init__.py b/discordbot/__init__.py index 9b54326..837161c 100644 --- a/discordbot/__init__.py +++ b/discordbot/__init__.py @@ -6,7 +6,7 @@ import random from database import db from database.helpers import ConfigurationHelper from database.models import Configuration, Humeur, Commande -from discord import Message +from discord import Message, TextChannel from discordbot.humblebundle import checkHumbleBundleAndNotify from protondb import searhProtonDb @@ -36,6 +36,14 @@ class DiscordBot(discord.Client): # toutes les 30 minutes await asyncio.sleep(30*60) + def getAllTextChannel(self) -> list[TextChannel]: + channels = [] + for channel in self.get_all_channels(): + if isinstance(channel, TextChannel): + channels.append(channel) + return channels + + def begin(self) : token = Configuration.query.filter_by(key='discord_token').first() if token : diff --git a/webapp/__init__.py b/webapp/__init__.py index 341f179..2edb4b4 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 +from webapp import commandes, configurations, index, humeurs, protondb, live_alert diff --git a/webapp/configurations.py b/webapp/configurations.py index 691629a..63ee1a8 100644 --- a/webapp/configurations.py +++ b/webapp/configurations.py @@ -3,15 +3,10 @@ from webapp import webapp from database import db from database.helpers import ConfigurationHelper from discordbot import bot -from discord import TextChannel @webapp.route("/configurations") def openConfigurations(): - channels = [] - for channel in bot.get_all_channels(): - if isinstance(channel, TextChannel): - channels.append(channel) - return render_template("configurations.html", configuration = ConfigurationHelper(), channels = channels) + return render_template("configurations.html", configuration = ConfigurationHelper(), channels = bot.getAllTextChannel()) @webapp.route("/configurations/update", methods=['POST']) def updateConfiguration(): diff --git a/webapp/live_alert.py b/webapp/live_alert.py new file mode 100644 index 0000000..bd365ff --- /dev/null +++ b/webapp/live_alert.py @@ -0,0 +1,54 @@ +from flask import render_template, request, redirect, url_for + +from webapp import webapp +from database import db +from database.models import LiveAlert +from discordbot import bot + + +@webapp.route("/live-alert") +def openLiveAlert(): + alerts : list[LiveAlert] = LiveAlert.query.all() + channels = bot.getAllTextChannel() + for alert in alerts : + for channel in channels: + if alert.notify_channel == channel.id : + alert.notify_channel_name = channel.name + return render_template("live-alert.html", alerts = alerts, channels = channels) + +@webapp.route("/live-alert/add", methods=['POST']) +def addLiveAlert(): + alert = LiveAlert(enable = True, login = request.form.get('login'), notify_channel = request.form.get('notify_channel'), message = request.form.get('message')) + db.session.add(alert) + db.session.commit() + return redirect(url_for("openLiveAlert")) + +@webapp.route("/live-alert/toggle/") +def toggleLiveAlert(id): + alert : LiveAlert = LiveAlert.query.get_or_404(id) + alert.enable = not alert.enable + db.session.commit() + return redirect(url_for("openLiveAlert")) + +@webapp.route("/live-alert/edit/") +def openEditLiveAlert(id): + alert = LiveAlert.query.get_or_404(id) + channels = bot.getAllTextChannel() + return render_template("live-alert.html", alert = alert, channels = channels) + +@webapp.route("/live-alert/edit/", methods=['POST']) +def submitEditLiveAlert(id): + alert : LiveAlert = LiveAlert.query.get_or_404(id) + alert.login = request.form.get('login') + alert.notify_channel = request.form.get('notify_channel') + alert.message = request.form.get('message') + db.session.commit() + return redirect(url_for("openLiveAlert")) + + +@webapp.route("/live-alert/del/") +def delLiveAlert(id): + alert = LiveAlert.query.get_or_404(id) + db.session.delete(alert) + db.session.commit() + return redirect(url_for("openLiveAlert")) diff --git a/webapp/static/css/style.css b/webapp/static/css/style.css index d546e72..05fd81a 100644 --- a/webapp/static/css/style.css +++ b/webapp/static/css/style.css @@ -11,3 +11,7 @@ table td { white-space: normal; max-width: 250px; } + +a.icon { + text-decoration: none; +} \ No newline at end of file diff --git a/webapp/templates/commandes.html b/webapp/templates/commandes.html index 99ac545..77568d8 100644 --- a/webapp/templates/commandes.html +++ b/webapp/templates/commandes.html @@ -19,12 +19,12 @@ {{ commande.trigger }} {{ commande.response }} - + {{ '✅' if commande.discord_enable else '❌' }} - + {{ '✅' if commande.twitch_enable else '❌' }} diff --git a/webapp/templates/live-alert.html b/webapp/templates/live-alert.html new file mode 100644 index 0000000..d3f8753 --- /dev/null +++ b/webapp/templates/live-alert.html @@ -0,0 +1,60 @@ +{% extends "template.html" %} + +{% block content %} +

Alerte Live

+ +{% if not alert %} +

Alertes

+ + + + + + + + + + + + {% for alert in alerts %} + + + + + + + + {% endfor %} + +
ChaineCanalMessageActif#
{{alert.login}}{{alert.notify_channel_name}}{{alert.message}} + {{ '✅' if alert.enable else '❌' }} + + + 🗑 +
+{% endif %} + +

{{ 'Editer une alerte' if alert else 'Ajouter une alerte de Live' }}

+
+ + + + + + + +

+ La chaine est le login de la chaine, par exemple chainesteve pour https://www.twitch.tv/chainesteve. +

+

+ Pour le message vous avez acces à ces variables : TODO +

+
+ +{% endblock %} \ No newline at end of file diff --git a/webapp/templates/template.html b/webapp/templates/template.html index 86f6506..beca4fe 100644 --- a/webapp/templates/template.html +++ b/webapp/templates/template.html @@ -18,6 +18,7 @@