mirror of
https://github.com/skylanix/MamieHenriette.git
synced 2026-02-06 06:40:35 +01:00
Edition des pojos
This commit is contained in:
@@ -19,6 +19,13 @@ class GameBundle(db.Model):
|
|||||||
name = db.Column(db.String(256))
|
name = db.Column(db.String(256))
|
||||||
json = db.Column(db.String(1024))
|
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):
|
class Message(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
enable = db.Column(db.Boolean, default=False)
|
enable = db.Column(db.Boolean, default=False)
|
||||||
|
|||||||
@@ -22,6 +22,14 @@ CREATE TABLE IF NOT EXISTS `humeur` (
|
|||||||
`text` VARCHAR(256) NULL
|
`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` (
|
CREATE TABLE IF NOT EXISTS `message` (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
`enable` BOOLEAN NOT NULL DEFAULT FALSE,
|
`enable` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import random
|
|||||||
from database import db
|
from database import db
|
||||||
from database.helpers import ConfigurationHelper
|
from database.helpers import ConfigurationHelper
|
||||||
from database.models import Configuration, Humeur, Commande
|
from database.models import Configuration, Humeur, Commande
|
||||||
from discord import Message
|
from discord import Message, TextChannel
|
||||||
from discordbot.humblebundle import checkHumbleBundleAndNotify
|
from discordbot.humblebundle import checkHumbleBundleAndNotify
|
||||||
from protondb import searhProtonDb
|
from protondb import searhProtonDb
|
||||||
|
|
||||||
@@ -36,6 +36,14 @@ class DiscordBot(discord.Client):
|
|||||||
# toutes les 30 minutes
|
# toutes les 30 minutes
|
||||||
await asyncio.sleep(30*60)
|
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) :
|
def begin(self) :
|
||||||
token = Configuration.query.filter_by(key='discord_token').first()
|
token = Configuration.query.filter_by(key='discord_token').first()
|
||||||
if token :
|
if token :
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ from flask import Flask
|
|||||||
|
|
||||||
webapp = Flask(__name__)
|
webapp = Flask(__name__)
|
||||||
|
|
||||||
from webapp import commandes, configurations, index, humeurs, protondb
|
from webapp import commandes, configurations, index, humeurs, protondb, live_alert
|
||||||
|
|||||||
@@ -3,15 +3,10 @@ from webapp import webapp
|
|||||||
from database import db
|
from database import db
|
||||||
from database.helpers import ConfigurationHelper
|
from database.helpers import ConfigurationHelper
|
||||||
from discordbot import bot
|
from discordbot import bot
|
||||||
from discord import TextChannel
|
|
||||||
|
|
||||||
@webapp.route("/configurations")
|
@webapp.route("/configurations")
|
||||||
def openConfigurations():
|
def openConfigurations():
|
||||||
channels = []
|
return render_template("configurations.html", configuration = ConfigurationHelper(), channels = bot.getAllTextChannel())
|
||||||
for channel in bot.get_all_channels():
|
|
||||||
if isinstance(channel, TextChannel):
|
|
||||||
channels.append(channel)
|
|
||||||
return render_template("configurations.html", configuration = ConfigurationHelper(), channels = channels)
|
|
||||||
|
|
||||||
@webapp.route("/configurations/update", methods=['POST'])
|
@webapp.route("/configurations/update", methods=['POST'])
|
||||||
def updateConfiguration():
|
def updateConfiguration():
|
||||||
|
|||||||
54
webapp/live_alert.py
Normal file
54
webapp/live_alert.py
Normal file
@@ -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/<int:id>")
|
||||||
|
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/<int:id>")
|
||||||
|
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/<int:id>", 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/<int:id>")
|
||||||
|
def delLiveAlert(id):
|
||||||
|
alert = LiveAlert.query.get_or_404(id)
|
||||||
|
db.session.delete(alert)
|
||||||
|
db.session.commit()
|
||||||
|
return redirect(url_for("openLiveAlert"))
|
||||||
@@ -11,3 +11,7 @@ table td {
|
|||||||
white-space: normal;
|
white-space: normal;
|
||||||
max-width: 250px;
|
max-width: 250px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.icon {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
@@ -19,12 +19,12 @@
|
|||||||
<td>{{ commande.trigger }}</td>
|
<td>{{ commande.trigger }}</td>
|
||||||
<td>{{ commande.response }}</td>
|
<td>{{ commande.response }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ url_for('toggle_discord_commande', commande_id = commande.id) }}" style="text-decoration: none; font-size: 1.2em;">
|
<a href="{{ url_for('toggle_discord_commande', commande_id = commande.id) }}" class="icon">
|
||||||
{{ '✅' if commande.discord_enable else '❌' }}
|
{{ '✅' if commande.discord_enable else '❌' }}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ url_for('toggle_twitch_commande', commande_id = commande.id) }}" style="text-decoration: none; font-size: 1.2em;">
|
<a href="{{ url_for('toggle_twitch_commande', commande_id = commande.id) }}" class="icon">
|
||||||
{{ '✅' if commande.twitch_enable else '❌' }}
|
{{ '✅' if commande.twitch_enable else '❌' }}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
60
webapp/templates/live-alert.html
Normal file
60
webapp/templates/live-alert.html
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
{% extends "template.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>Alerte Live</h1>
|
||||||
|
|
||||||
|
{% if not alert %}
|
||||||
|
<h2>Alertes</h2>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Chaine</th>
|
||||||
|
<th>Canal</th>
|
||||||
|
<th>Message</th>
|
||||||
|
<th>Actif</th>
|
||||||
|
<th>#</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for alert in alerts %}
|
||||||
|
<tr>
|
||||||
|
<td>{{alert.login}}</td>
|
||||||
|
<td>{{alert.notify_channel_name}}</td>
|
||||||
|
<td>{{alert.message}}</td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ url_for('toggleLiveAlert', id = alert.id) }}" class="icon">{{ '✅' if alert.enable else '❌' }}</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ url_for('openEditLiveAlert', id = alert.id) }}" class="icon">✐</a>
|
||||||
|
<a href="{{ url_for('delLiveAlert', id = alert.id) }}"
|
||||||
|
onclick="return confirm('Êtes-vous sûr de vouloir supprimer cette alerte ?')" class="icon">🗑</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<h2>{{ 'Editer une alerte' if alert else 'Ajouter une alerte de Live' }}</h2>
|
||||||
|
<form action="{{ url_for('submitEditLiveAlert', id = alert.id) if alert else url_for('addLiveAlert') }}" method="POST">
|
||||||
|
<label for="login">Chaine</label>
|
||||||
|
<input name="login" type="text" maxlength="32" required="required" value="{{alert.login if alert}}"/>
|
||||||
|
<label for="notify_channel">Canal de Notification</label>
|
||||||
|
<select name="notify_channel">
|
||||||
|
{% for channel in channels %}
|
||||||
|
<option value="{{channel.id}}"{% if alert and alert.notify_channel == channel.id %}
|
||||||
|
selected="selected" {% endif %}>{{channel.name}}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<label for="message">Message</label>
|
||||||
|
<textarea name="message" rows="5" cols="50" required="required">{{alert.message if alert}}</textarea>
|
||||||
|
<input type="Submit" value="Ajouter">
|
||||||
|
<p>
|
||||||
|
La chaine est le login de la chaine, par exemple <strong>chainesteve</strong> pour <strong>https://www.twitch.tv/chainesteve</strong>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Pour le message vous avez acces à ces variables : <strong>TODO</strong>
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
<nav>
|
<nav>
|
||||||
<a href="/"><img src="/static/ico/favicon.ico"></a>
|
<a href="/"><img src="/static/ico/favicon.ico"></a>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li><a href="/live-alert">Alerte live</a></li>
|
||||||
<li><a href="/commandes">Commandes</a></li>
|
<li><a href="/commandes">Commandes</a></li>
|
||||||
<li><a href="/humeurs">Humeurs</a></li>
|
<li><a href="/humeurs">Humeurs</a></li>
|
||||||
<li><a href="/protondb">ProtonDB</a></li>
|
<li><a href="/protondb">ProtonDB</a></li>
|
||||||
|
|||||||
Reference in New Issue
Block a user