tentative lancement bot twitch

This commit is contained in:
Kepka Ludovic
2025-08-21 09:12:47 +02:00
committed by skylanix
parent 4b68781114
commit a69d09223e
2 changed files with 33 additions and 26 deletions

View File

@@ -1,8 +1,11 @@
import locale import locale
import logging import logging
import threading import threading
from webapp import webapp
from discordbot import bot from discordbot import bot
from webapp import webapp
# from twitchbot import twitchBot
def start_server(): def start_server():
logging.info("Start Web Serveur") logging.info("Start Web Serveur")
@@ -14,12 +17,18 @@ def start_discord_bot():
with webapp.app_context(): with webapp.app_context():
bot.begin() bot.begin()
# def start_twitch_bot():
# logging.info("Start Twitch Bot")
# with webapp.app_context():
# twitchBot.begin()
if __name__ == '__main__': if __name__ == '__main__':
locale.setlocale(locale.LC_TIME, 'fr_FR.UTF-8') locale.setlocale(locale.LC_TIME, 'fr_FR.UTF-8')
jobs = [] jobs = []
jobs.append(threading.Thread(target=start_discord_bot)) jobs.append(threading.Thread(target=start_discord_bot))
jobs.append(threading.Thread(target=start_server)) jobs.append(threading.Thread(target=start_server))
# jobs.append(threading.Thread(target=start_twitch_bot))
for job in jobs: job.start() for job in jobs: job.start()
for job in jobs: job.join() for job in jobs: job.join()

View File

@@ -1,6 +1,7 @@
import asyncio
from twitchAPI.twitch import Twitch from twitchAPI.twitch import Twitch
from twitchAPI.oauth import UserAuthenticator
from twitchAPI.type import AuthScope, ChatEvent from twitchAPI.type import AuthScope, ChatEvent
from twitchAPI.chat import Chat, ChatEvent, ChatMessage, EventData from twitchAPI.chat import Chat, ChatEvent, ChatMessage, EventData
@@ -9,41 +10,38 @@ CLIENT_SECRET='TODO'
USER_SCOPE = [AuthScope.CHAT_READ, AuthScope.CHAT_EDIT] USER_SCOPE = [AuthScope.CHAT_READ, AuthScope.CHAT_EDIT]
CHANNEL = "#TODO" CHANNEL = "#gshionn"
ACCESS_TOKEN = 'TODO' ACCESS_TOKEN = 'TODO'
REFRESH_TOKEN = 'TODO' REFRESH_TOKEN = 'TODO'
async def on_ready(ready_event: EventData): async def _onReady(ready_event: EventData):
print('Bot is ready for work, joining channels') print('Bot is ready for work, joining channels')
await ready_event.chat.join_room(CHANNEL) await ready_event.chat.join_room(CHANNEL)
async def on_message(msg: ChatMessage): async def _onMessage(msg: ChatMessage):
print(f'in {msg.room.name}, {msg.user.name} said: {msg.text}') print(f'in {msg.room.name}, {msg.user.name} said: {msg.text}')
async def start() : class TwitchBot() :
twitch = await Twitch(CLIENT_ID, CLIENT_SECRET)
# auth = UserAuthenticator(twitch, USER_SCOPE, url='todo') async def _connect(self):
# print(f'{auth.return_auth_url()}') self.twitch = await Twitch(CLIENT_ID, CLIENT_SECRET)
# token, refresh_token = await auth.authenticate( use_browser=False) await self.twitch.set_user_authentication(ACCESS_TOKEN, USER_SCOPE, REFRESH_TOKEN)
# token, refresh_token = await auth.authenticate() self.chat = await Chat(self.twitch)
# print(f'{token} :: {refresh_token}') self.chat.register_event(ChatEvent.READY, _onReady)
self.chat.register_event(ChatEvent.MESSAGE, _onMessage)
# chat.register_event(ChatEvent.SUB, on_sub)
# chat.register_command('reply', test_command)
self.chat.start()
await twitch.set_user_authentication(ACCESS_TOKEN, USER_SCOPE, REFRESH_TOKEN) def begin(self):
# await twitch.set_user_authentication(token, USER_SCOPE, refresh_token) asyncio.run(self._connect())
chat = await Chat(twitch) # je sais pas encore comment appeller ca
chat.register_event(ChatEvent.READY, on_ready) async def _close(self):
chat.register_event(ChatEvent.MESSAGE, on_message) self.chat.stop()
# chat.register_event(ChatEvent.SUB, on_sub) await self.twitch.close()
# chat.register_command('reply', test_command)
chat.start() twitchBot = TwitchBot()
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()