diff --git a/requirements.txt b/requirements.txt index a535151..9d6ef39 100755 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/run-twitch.py b/run-twitch.py new file mode 100644 index 0000000..550a48f --- /dev/null +++ b/run-twitch.py @@ -0,0 +1,7 @@ + +import asyncio + +from twitchbot import start + +if __name__ == "__main__": + asyncio.run(start()) \ No newline at end of file diff --git a/twitchbot/__init__.py b/twitchbot/__init__.py new file mode 100644 index 0000000..d6bde7f --- /dev/null +++ b/twitchbot/__init__.py @@ -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() \ No newline at end of file diff --git a/webapp/configurations.py b/webapp/configurations.py index 1cd6534..0eb956f 100644 --- a/webapp/configurations.py +++ b/webapp/configurations.py @@ -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") \ No newline at end of file diff --git a/webapp/static/img/twitch-api-01.jpg b/webapp/static/img/twitch-api-01.jpg new file mode 100644 index 0000000..08d3aa8 Binary files /dev/null and b/webapp/static/img/twitch-api-01.jpg differ diff --git a/webapp/static/img/twitch-api-02.jpg b/webapp/static/img/twitch-api-02.jpg new file mode 100644 index 0000000..a878973 Binary files /dev/null and b/webapp/static/img/twitch-api-02.jpg differ diff --git a/webapp/static/img/twitch-api-03.jpg b/webapp/static/img/twitch-api-03.jpg new file mode 100644 index 0000000..1bd71cf Binary files /dev/null and b/webapp/static/img/twitch-api-03.jpg differ diff --git a/webapp/static/img/twitch-api-04.jpg b/webapp/static/img/twitch-api-04.jpg new file mode 100644 index 0000000..55ec373 Binary files /dev/null and b/webapp/static/img/twitch-api-04.jpg differ diff --git a/webapp/static/img/twitch-api-05.jpg b/webapp/static/img/twitch-api-05.jpg new file mode 100644 index 0000000..c5bea6a Binary files /dev/null and b/webapp/static/img/twitch-api-05.jpg differ diff --git a/webapp/templates/configurations.html b/webapp/templates/configurations.html index 749c7e6..6910366 100644 --- a/webapp/templates/configurations.html +++ b/webapp/templates/configurations.html @@ -32,17 +32,38 @@ -

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, +

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), comme le montre cet exemple

-

Api

+

Api Discord

Nécéssite un redémarrage

+ +

Api Twitch

+
+ + + + + + + + + + + +

+ Aide +

+

Nécéssite un redémarrage

+
{% endblock %} \ No newline at end of file diff --git a/webapp/templates/twitch-aide.html b/webapp/templates/twitch-aide.html new file mode 100644 index 0000000..de4d3f9 --- /dev/null +++ b/webapp/templates/twitch-aide.html @@ -0,0 +1,45 @@ +{% extends "template.html" %} + +{% block content %} +

Procedure configuration de Twitch

+

+ Rendez vous sur la console d'application twitch et + ajouter une application. Renseigner : +

+

+ + + +

+ Creer le bot. Puis de retour à la liste, editer le en cliquant sur Gérer. Puis cliquer sur Nouveau + Secret. Vous trouvez ici le Client ID et Client Secret. +

+ + + +

+ Ensuite rendez vous sur twitchtokengenerator.com et + selectionner Custum Scope Target. Dans la section Use My Client Secret and Client + ID, renseigner les deux champs. +

+ + + +

+ Ensuite dans la section Available Token Scopes, cocher chat:read et chat:edit. + Puis, dans la même section, cliquer sur Generate token. +

+ + + +

+ Suivez la procédure et vous avez votre Access Token et Refresh Token +

+ + + + +{% endblock %} \ No newline at end of file