mirror of
https://github.com/skylanix/MamieHenriette.git
synced 2026-02-06 06:40:35 +01:00
configuration humble bundle
This commit is contained in:
32
database/helpers.py
Normal file
32
database/helpers.py
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
from database import db
|
||||
from database.models import Configuration
|
||||
|
||||
class ConfigurationHelper:
|
||||
def getValue(self, key:str) :
|
||||
conf = Configuration.query.filter_by(key=key).first()
|
||||
if conf == None:
|
||||
return None
|
||||
if (key.endswith('_enable')) :
|
||||
return conf.value in ['true', '1', 'yes', 'on']
|
||||
return conf.value
|
||||
|
||||
def getIntValue(self, key:str) :
|
||||
conf = Configuration.query.filter_by(key=key).first()
|
||||
if conf == None:
|
||||
return 0
|
||||
return int(conf.value)
|
||||
|
||||
def createOrUpdate(self, key:str, value) :
|
||||
conf = Configuration.query.filter_by(key=key).first()
|
||||
if (key.endswith('_enable')) :
|
||||
value = value in ['true', '1', 'yes', 'on']
|
||||
if conf :
|
||||
conf.value = value
|
||||
else :
|
||||
conf = Configuration(key = key, value = value)
|
||||
db.session.add(conf)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -22,4 +22,3 @@ CREATE TABLE IF NOT EXISTS `message` (
|
||||
`text` VARCHAR(256) NULL,
|
||||
periodicity INTEGER NULL
|
||||
);
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ def start_server():
|
||||
logging.info("Start Web Serveur")
|
||||
from waitress import serve
|
||||
serve(webapp, host="0.0.0.0", port=5000)
|
||||
# webapp.run()
|
||||
|
||||
def start_discord_bot():
|
||||
logging.info("Start Discord Bot")
|
||||
|
||||
@@ -2,27 +2,24 @@ from flask import render_template, request, redirect, url_for
|
||||
from webapp import webapp
|
||||
from database import db
|
||||
from database.models import Configuration
|
||||
from database.helpers import ConfigurationHelper
|
||||
from discordbot import bot
|
||||
from discord import TextChannel
|
||||
|
||||
@webapp.route("/configurations")
|
||||
def openConfigurations():
|
||||
all = Configuration.query.all()
|
||||
configurations = {conf.key: conf for conf in all}
|
||||
return render_template("configurations.html", configurations = configurations, channels = bot.get_all_channels())
|
||||
channels = []
|
||||
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("/updateConfiguration", methods=['POST'])
|
||||
@webapp.route("/configurations/update", methods=['POST'])
|
||||
def updateConfiguration():
|
||||
|
||||
return redirect(url_for('openConfigurations'))
|
||||
|
||||
|
||||
@webapp.route('/configurations/set/<key>', methods=['POST'])
|
||||
def setConfiguration(key):
|
||||
conf = Configuration.query.filter_by(key=key).first()
|
||||
if conf :
|
||||
conf.value = request.form['value']
|
||||
else :
|
||||
conf = Configuration(key = key, value = request.form['value'])
|
||||
db.session.add(conf)
|
||||
for key in request.form :
|
||||
ConfigurationHelper().createOrUpdate(key, request.form.get(key))
|
||||
if (request.form.get("humble_bundle_channel") != None and request.form.get("humble_bundle_enable") == None) :
|
||||
ConfigurationHelper().createOrUpdate('humble_bundle_enable', False)
|
||||
db.session.commit()
|
||||
return redirect(url_for('openConfigurations'))
|
||||
|
||||
@@ -5,21 +5,25 @@
|
||||
|
||||
<h2>Humble Bundle</h2>
|
||||
<form action="{{ url_for('updateConfiguration') }}" method="POST">
|
||||
<label for="humble_bundle_channel">Api Discord (cachée)</label>
|
||||
{{channels}}
|
||||
<label for="humble_bundle_enable">Activer</label>
|
||||
<input type="checkbox" name="humble_bundle_enable" {% if configuration.getValue('humble_bundle_enable') %}
|
||||
checked="checked" {% endif %}>
|
||||
<label>Activer les notifications Humble bundle</label>
|
||||
<label for="humble_bundle_channel">Canal de notification des pack Humble Bundle</label>
|
||||
<select name="humble_bundle_channel">
|
||||
{% for channel in channels %}
|
||||
<option value="{{channel.id}}">{{channel.name}}</option>
|
||||
<option value="{{channel.id}}" {% if configuration.getIntValue('humble_bundle_channel')==channel.id %}
|
||||
selected="selected" {% endif %}>
|
||||
{{channel.name}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<input type="Submit" value="Définir">
|
||||
</form>
|
||||
|
||||
|
||||
<h2>Api</h2>
|
||||
<form action="{{ url_for('setConfiguration', key = 'discord_token') }}" method="POST">
|
||||
<label for="value">Api Discord (cachée)</label>
|
||||
<input name="value" type="password" />
|
||||
<form action="{{ url_for('updateConfiguration') }}" method="POST">
|
||||
<label for="discord_token">Api Discord (cachée)</label>
|
||||
<input name="discord_token" type="password" />
|
||||
<input type="Submit" value="Définir">
|
||||
<p>Nécéssite un redémarrage</p>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user