mirror of
https://github.com/skylanix/MamieHenriette.git
synced 2026-02-12 11:20:38 +01:00
configuration humble bundle
This commit is contained in:
@@ -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