Merge remote-tracking branch 'origin/main' into configuration-proton-db
@@ -91,7 +91,7 @@ Avant d'installer MamieHenriette, vous devez créer un bot Discord et obtenir so
|
||||
3. **Configurer le bot** :
|
||||
- Dans le menu latéral, cliquez sur "Bot"
|
||||
- Ajoutez une photo de profil et un pseudo à votre bot
|
||||
- **Important activez les intents** :
|
||||
- **Important : activez les intents** :
|
||||
- ☑️ Presence Intent
|
||||
- ☑️ Server Members Intent
|
||||
- ☑️ Message Content Intent
|
||||
|
||||
@@ -12,6 +12,7 @@ twitchAPI>=4.5.0
|
||||
# Nécessaire pour l'hébergement du site web
|
||||
flask>=2.3.2
|
||||
flask-sqlalchemy>=3.0.3
|
||||
flask[async]
|
||||
waitress>=3.0.2
|
||||
|
||||
# Nécessaire pour l'appel à l'API Humble Bundle
|
||||
|
||||
@@ -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, messages, moderation, protondb, twitch_auth
|
||||
|
||||
@@ -25,6 +25,3 @@ def updateConfiguration():
|
||||
db.session.commit()
|
||||
return redirect(request.referrer)
|
||||
|
||||
@webapp.route("/configurations/twitch/help")
|
||||
def twitchConfigurationHelp():
|
||||
return render_template("twitch-aide.html")
|
||||
|
||||
|
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 120 KiB |
|
Before Width: | Height: | Size: 151 KiB After Width: | Height: | Size: 153 KiB |
|
Before Width: | Height: | Size: 100 KiB |
|
Before Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 76 KiB |
@@ -4,24 +4,20 @@
|
||||
<h1>Configuration de Mamie</h1>
|
||||
<p>Configurez les tokens Discord, les notifications Humble Bundle et l'API ProtonDB pour la commande !protondb.</p>
|
||||
|
||||
<h2>Api Discord</h2>
|
||||
<h2>API Discord</h2>
|
||||
<form action="{{ url_for('updateConfiguration') }}" method="POST">
|
||||
<label for="discord_token">Api Discord (cachée)</label>
|
||||
<label for="discord_token">API Discord (cachée)</label>
|
||||
<input name="discord_token" type="password" />
|
||||
<input type="Submit" value="Définir">
|
||||
<p>Nécessite un redémarrage</p>
|
||||
</form>
|
||||
|
||||
<h2>Api Twitch</h2>
|
||||
<h2>API Twitch</h2>
|
||||
<form action="{{ url_for('updateConfiguration') }}" method="POST">
|
||||
<label for="twitch_client_id">Client id</label>
|
||||
<label for="twitch_client_id">Client ID</label>
|
||||
<input name="twitch_client_id" type="text" value="{{ configuration.getValue('twitch_client_id') }}" />
|
||||
<label for="twitch_client_secret">Client Secret</label>
|
||||
<input name="twitch_client_secret" type="text" value="{{ configuration.getValue('twitch_client_secret') }}" />
|
||||
<label for="twitch_access_token">Access Token</label>
|
||||
<input name="twitch_access_token" type="text" value="{{ configuration.getValue('twitch_access_token') }}" />
|
||||
<label for="twitch_refresh_token">Refresh Token</label>
|
||||
<input name="twitch_refresh_token" type="text" value="{{ configuration.getValue('twitch_refresh_token') }}" />
|
||||
<label for="twitch_channel">Chaîne à rejoindre</label>
|
||||
<input name="twitch_channel" type="text" value="{{ configuration.getValue('twitch_channel') }}"
|
||||
placeholder="#machinTruc" />
|
||||
@@ -29,7 +25,18 @@
|
||||
<p>
|
||||
<a href="{{ url_for('twitchConfigurationHelp') }}">Aide</a>
|
||||
</p>
|
||||
<p>Nécessite un redémarrage</p>
|
||||
{% if configuration.getValue('twitch_client_secret') and configuration.getValue('twitch_client_id') %}
|
||||
<p>
|
||||
<a href="{{ url_for('twitchRequestToken') }}">Obtenir token et refresh token</a>
|
||||
</p>
|
||||
<label for="twitch_access_token">Access Token</label>
|
||||
<input name="twitch_access_token" type="text" value="{{ configuration.getValue('twitch_access_token') }}"
|
||||
readonly="readonly" />
|
||||
<label for="twitch_refresh_token">Refresh Token</label>
|
||||
<input name="twitch_refresh_token" type="text" value="{{ configuration.getValue('twitch_refresh_token') }}"
|
||||
readonly="readonly" />
|
||||
<p>Nécessite un redémarrage après l'obtention des Tokens.</p>
|
||||
{% endif %}
|
||||
</form>
|
||||
|
||||
<h2>Humble Bundle</h2>
|
||||
@@ -37,7 +44,7 @@
|
||||
<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>Activer les notifications Humble Bundle</label>
|
||||
<label for="humble_bundle_channel">Canal de notification des packs Humble Bundle</label>
|
||||
<select name="humble_bundle_channel">
|
||||
{% for channel in channels %}
|
||||
@@ -46,7 +53,7 @@
|
||||
{{channel.name}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<label for="humble_bundle_api_key">Client id</label>
|
||||
<label for="humble_bundle_api_key">Clé API</label>
|
||||
<input name="humble_bundle_api_key" type="text" value="{{ configuration.getValue('humble_bundle_api_key') }}" />
|
||||
<input type="Submit" value="Définir">
|
||||
</form>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<label for="name">Nom</label>
|
||||
<input name="name" type="text" maxlength="256" required="required" />
|
||||
<input type="Submit" value="Ajouter">
|
||||
<p>Si vous créer un alias <strong>GTA : Grand Theft Auto</strong> alors si un utilisateur rentre la commande
|
||||
<p>Si vous créez un alias <strong>GTA : Grand Theft Auto</strong> alors si un utilisateur rentre la commande
|
||||
<strong>!protondb GTA 5</strong> cela fera une recherche sur <strong>Grand Theft Auto 5</strong>.
|
||||
</p>
|
||||
</form>
|
||||
@@ -45,14 +45,14 @@
|
||||
<input type="checkbox" name="proton_db_enable_enable" {% if configuration.getValue('proton_db_enable_enable') %}
|
||||
checked="checked" {% endif %}>
|
||||
<label>Activer la commande Proton DB</label>
|
||||
<label for="proton_db_api_id">Api ID</label>
|
||||
<label for="proton_db_api_id">API ID</label>
|
||||
<input name="proton_db_api_id" type="text" value="{{ configuration.getValue('proton_db_api_id') }}" />
|
||||
<label for="proton_db_api_key">Api KEY</label>
|
||||
<label for="proton_db_api_key">Clé API</label>
|
||||
<input name="proton_db_api_key" type="text" value="{{ configuration.getValue('proton_db_api_key') }}" />
|
||||
<input type="Submit" value="Définir">
|
||||
<p>Pour trouver les clés, dans votre navigateur avec l'outil d'inspection ouvert (F12 ou clic droit > Inspecter
|
||||
l'élément dans Firefox/Chrome) faites une recherche de jeux sur protondb,
|
||||
puis chercher les clés dans les requêtes (onglet Réseau/Network),
|
||||
puis cherchez les clés dans les requêtes (onglet Réseau/Network),
|
||||
<a href="/static/img/algolia-key.jpg" target="_blank">comme le montre cet exemple</a>
|
||||
</p>
|
||||
</form>
|
||||
|
||||
@@ -3,14 +3,15 @@
|
||||
{% block content %}
|
||||
<h1>Procédure de configuration de Twitch</h1>
|
||||
<p>
|
||||
<strong>Avant toute chose, activez l'authentification à deux facteurs (2FA) :</strong>
|
||||
<a href="https://help.twitch.tv/s/article/two-factor-authentication?language=en_US" target="_blank">Guide officiel Twitch pour la 2FA</a>
|
||||
<strong>Avant toute chose, activez l'authentification à deux facteurs (2FA) :</strong>
|
||||
<a href="https://help.twitch.tv/s/article/two-factor-authentication?language=en_US" target="_blank">Guide officiel
|
||||
Twitch pour la 2FA</a>
|
||||
</p>
|
||||
<p>
|
||||
Rendez-vous sur <a href="https://dev.twitch.tv/console" target="_blank">la console d'applications Twitch</a> et
|
||||
ajoutez une application. Renseignez :
|
||||
<ul>
|
||||
<li>URL de redirection : https://twitchtokengenerator.com</li>
|
||||
<li>URL de redirection : {{token_redirect_url}}</li>
|
||||
<li>Catégorie : Chat Bot</li>
|
||||
</ul>
|
||||
</p>
|
||||
@@ -25,25 +26,10 @@
|
||||
<img src="/static/img/twitch-api-02.jpg">
|
||||
|
||||
<p>
|
||||
Ensuite, rendez-vous sur <a href="https://twitchtokengenerator.com/" target="_blank">twitchtokengenerator.com</a> et
|
||||
sélectionnez <strong>Custom Scope Target</strong>. Dans la section <strong>Use My Client Secret and Client
|
||||
ID</strong>, renseignez les deux champs.
|
||||
Ensuite, retournez sur la page de <a href="{{url_for('openConfigurations')}}">Configuration</a>, après avoir
|
||||
enregistré le <strong>Client ID</strong> et le <strong>Client Secret</strong>, cliquez sur le lien <strong>Obtenir
|
||||
token et refresh token</strong>. Si tout se passe bien les champs <strong>Access Token</strong> et
|
||||
<strong>Refresh Token</strong> sont remplis.
|
||||
</p>
|
||||
|
||||
<img src="/static/img/twitch-api-03.jpg">
|
||||
|
||||
<p>
|
||||
Ensuite, dans la section <strong>Available Token Scopes</strong>, cochez <em>chat:read</em> et <em>chat:edit</em>.
|
||||
Puis, dans la même section, cliquez sur <strong>Generate token</strong>.
|
||||
</p>
|
||||
|
||||
<img src="/static/img/twitch-api-04.jpg">
|
||||
|
||||
<p>
|
||||
Suivez la procédure et vous avez votre <strong>Access Token</strong> et <strong>Refresh Token</strong>
|
||||
</p>
|
||||
|
||||
<img src="/static/img/twitch-api-05.jpg">
|
||||
|
||||
|
||||
{% endblock %}
|
||||
55
webapp/twitch_auth.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import logging
|
||||
|
||||
from flask import render_template, request, redirect, url_for
|
||||
from twitchAPI.twitch import Twitch
|
||||
from twitchAPI.type import TwitchAPIException
|
||||
from twitchAPI.oauth import UserAuthenticator
|
||||
|
||||
from database import db
|
||||
from database.helpers import ConfigurationHelper
|
||||
from twitchbot import USER_SCOPE
|
||||
from webapp import webapp
|
||||
|
||||
|
||||
auth: UserAuthenticator
|
||||
|
||||
@webapp.route("/configurations/twitch/help")
|
||||
def twitchConfigurationHelp():
|
||||
return render_template("twitch-aide.html", token_redirect_url = _buildUrl())
|
||||
|
||||
@webapp.route("/configurations/twitch/request-token")
|
||||
async def twitchRequestToken():
|
||||
global auth
|
||||
helper = ConfigurationHelper()
|
||||
twitch = await Twitch(helper.getValue('twitch_client_id'), helper.getValue('twitch_client_secret'))
|
||||
auth = UserAuthenticator(twitch, USER_SCOPE, url=_buildUrl())
|
||||
return redirect(auth.return_auth_url())
|
||||
|
||||
@webapp.route("/configurations/twitch/receive-token")
|
||||
async def twitchReceiveToken():
|
||||
global auth
|
||||
state = request.args.get('state')
|
||||
code = request.args.get('code')
|
||||
if state != auth.state :
|
||||
logging('bad returned state')
|
||||
return redirect(url_for('openConfigurations'))
|
||||
if code == None :
|
||||
logging('no returned state')
|
||||
return redirect(url_for('openConfigurations'))
|
||||
|
||||
try:
|
||||
token, refresh = await auth.authenticate(user_token=code)
|
||||
helper = ConfigurationHelper()
|
||||
helper.createOrUpdate('twitch_access_token', token)
|
||||
helper.createOrUpdate('twitch_refresh_token', refresh)
|
||||
db.session.commit()
|
||||
except TwitchAPIException as e:
|
||||
logging(e)
|
||||
return redirect(url_for('openConfigurations'))
|
||||
|
||||
# hack pas fou mais on estime qu'on sera toujours en ssl en connecté
|
||||
def _buildUrl():
|
||||
url = f'{request.url_root[:-1]}{url_for('twitchReceiveToken')}'
|
||||
if url.find('localhost') != -1 : return url
|
||||
url = url.replace('http://', 'https://')
|
||||
return url
|
||||