mirror of
https://github.com/skylanix/MamieHenriette.git
synced 2026-02-06 06:40:35 +01:00
draft twitch bot
This commit is contained in:
@@ -5,6 +5,11 @@ discord.py==2.3.2
|
||||
aiohttp>=3.7.4,<4
|
||||
audioop-lts; python_version>='3.13'
|
||||
|
||||
# api twitch
|
||||
# twitchio>=3.1.0
|
||||
# twitch-python>=0.0.20
|
||||
twitchAPI>=4.5.0
|
||||
|
||||
# necessaire pour l'hebergement du site web
|
||||
flask>=2.3.2
|
||||
flask-sqlalchemy>=3.0.3
|
||||
|
||||
7
run-twitch.py
Normal file
7
run-twitch.py
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
from twitchbot import start
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(start())
|
||||
49
twitchbot/__init__.py
Normal file
49
twitchbot/__init__.py
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
from twitchAPI.twitch import Twitch
|
||||
from twitchAPI.oauth import UserAuthenticator
|
||||
from twitchAPI.type import AuthScope, ChatEvent
|
||||
from twitchAPI.chat import Chat, ChatEvent, ChatMessage, EventData
|
||||
|
||||
CLIENT_ID= 'TODO'
|
||||
CLIENT_SECRET='TODO'
|
||||
|
||||
USER_SCOPE = [AuthScope.CHAT_READ, AuthScope.CHAT_EDIT]
|
||||
|
||||
CHANNEL = "#TODO"
|
||||
|
||||
ACCESS_TOKEN = 'TODO'
|
||||
REFRESH_TOKEN = 'TODO'
|
||||
|
||||
|
||||
async def on_ready(ready_event: EventData):
|
||||
print('Bot is ready for work, joining channels')
|
||||
await ready_event.chat.join_room(CHANNEL)
|
||||
|
||||
async def on_message(msg: ChatMessage):
|
||||
print(f'in {msg.room.name}, {msg.user.name} said: {msg.text}')
|
||||
|
||||
async def start() :
|
||||
twitch = await Twitch(CLIENT_ID, CLIENT_SECRET)
|
||||
|
||||
# auth = UserAuthenticator(twitch, USER_SCOPE, url='todo')
|
||||
# print(f'{auth.return_auth_url()}')
|
||||
# token, refresh_token = await auth.authenticate( use_browser=False)
|
||||
# token, refresh_token = await auth.authenticate()
|
||||
# print(f'{token} :: {refresh_token}')
|
||||
|
||||
await twitch.set_user_authentication(ACCESS_TOKEN, USER_SCOPE, REFRESH_TOKEN)
|
||||
# await twitch.set_user_authentication(token, USER_SCOPE, refresh_token)
|
||||
|
||||
chat = await Chat(twitch)
|
||||
chat.register_event(ChatEvent.READY, on_ready)
|
||||
chat.register_event(ChatEvent.MESSAGE, on_message)
|
||||
# chat.register_event(ChatEvent.SUB, on_sub)
|
||||
# chat.register_command('reply', test_command)
|
||||
chat.start()
|
||||
|
||||
try:
|
||||
input('press ENTER to stop\n')
|
||||
finally:
|
||||
# now we can close the chat bot and the twitch api client
|
||||
chat.stop()
|
||||
await twitch.close()
|
||||
@@ -24,3 +24,7 @@ def updateConfiguration():
|
||||
ConfigurationHelper().createOrUpdate('proton_db_enable_enable', False)
|
||||
db.session.commit()
|
||||
return redirect(url_for('openConfigurations'))
|
||||
|
||||
@webapp.route("/configurations/help/twitch")
|
||||
def twitchConfigurationHelp():
|
||||
return render_template("twitch-aide.html")
|
||||
BIN
webapp/static/img/twitch-api-01.jpg
Normal file
BIN
webapp/static/img/twitch-api-01.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 114 KiB |
BIN
webapp/static/img/twitch-api-02.jpg
Normal file
BIN
webapp/static/img/twitch-api-02.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 151 KiB |
BIN
webapp/static/img/twitch-api-03.jpg
Normal file
BIN
webapp/static/img/twitch-api-03.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 100 KiB |
BIN
webapp/static/img/twitch-api-04.jpg
Normal file
BIN
webapp/static/img/twitch-api-04.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 80 KiB |
BIN
webapp/static/img/twitch-api-05.jpg
Normal file
BIN
webapp/static/img/twitch-api-05.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 76 KiB |
@@ -32,17 +32,38 @@
|
||||
<label for="proton_db_api_key">Api KEY</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 clefs, 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,
|
||||
<p>Pour trouver les clefs, 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 clef dans les requetes (onglet Réseau/Network),
|
||||
<a href="/static/img/algolia-key.jpg" target="_blank">comme le montre cet exemple</a>
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<h2>Api</h2>
|
||||
<h2>Api Discord</h2>
|
||||
<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>
|
||||
|
||||
<h2>Api Twitch</h2>
|
||||
<form action="{{ url_for('updateConfiguration') }}" method="POST">
|
||||
<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">Chaine à rejoindre</label>
|
||||
<input name="twitch_channel" type="text" value="{{ configuration.getValue('twitch_channel') }}"
|
||||
placeholder="#machinTruc" />
|
||||
<input type="Submit" value="Définir">
|
||||
<p>
|
||||
<a href="{{ url_for('twitchConfigurationHelp') }}">Aide</a>
|
||||
</p>
|
||||
<p>Nécéssite un redémarrage</p>
|
||||
</form>
|
||||
{% endblock %}
|
||||
45
webapp/templates/twitch-aide.html
Normal file
45
webapp/templates/twitch-aide.html
Normal file
@@ -0,0 +1,45 @@
|
||||
{% extends "template.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Procedure configuration de Twitch</h1>
|
||||
<p>
|
||||
Rendez vous sur <a href="https://dev.twitch.tv/console" target="_blank">la console d'application twitch</a> et
|
||||
ajouter une application. Renseigner :
|
||||
<ul>
|
||||
<li>url de redirection : https://twitchtokengenerator.com</li>
|
||||
<li>catégorie : Chat Bot</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<img src="/static/img/twitch-api-01.jpg">
|
||||
|
||||
<p>
|
||||
Creer le bot. Puis de retour à la liste, editer le en cliquant sur Gérer. Puis cliquer sur <strong>Nouveau
|
||||
Secret</strong>. Vous trouvez ici le <strong>Client ID</strong> et <strong>Client Secret</strong>.
|
||||
</p>
|
||||
|
||||
<img src="/static/img/twitch-api-02.jpg">
|
||||
|
||||
<p>
|
||||
Ensuite rendez vous sur <a href="https://twitchtokengenerator.com/" target="_blank">twitchtokengenerator.com</a> et
|
||||
selectionner <strong>Custum Scope Target</strong>. Dans la section <strong>Use My Client Secret and Client
|
||||
ID</strong>, renseigner les deux champs.
|
||||
</p>
|
||||
|
||||
<img src="/static/img/twitch-api-03.jpg">
|
||||
|
||||
<p>
|
||||
Ensuite dans la section <strong>Available Token Scopes</strong>, cocher <em>chat:read</em> et <em>chat:edit</em>.
|
||||
Puis, dans la même section, cliquer 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 %}
|
||||
Reference in New Issue
Block a user