From 206e71758c9ec1301a788e37263520c446400582 Mon Sep 17 00:00:00 2001 From: Kepka Ludovic Date: Thu, 21 Aug 2025 09:22:17 +0200 Subject: [PATCH] =?UTF-8?q?le=20bot=20se=20connect=20et=20repond=20=C3=A0?= =?UTF-8?q?=20\!hello?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run-web.py | 14 +++++++------- twitchbot/__init__.py | 10 +++++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/run-web.py b/run-web.py index 3a650a0..354d024 100644 --- a/run-web.py +++ b/run-web.py @@ -2,9 +2,9 @@ import locale import logging import threading -from discordbot import bot from webapp import webapp -# from twitchbot import twitchBot +from discordbot import bot +from twitchbot import twitchBot def start_server(): @@ -17,10 +17,10 @@ def start_discord_bot(): with webapp.app_context(): bot.begin() -# def start_twitch_bot(): -# logging.info("Start Twitch Bot") -# with webapp.app_context(): -# twitchBot.begin() +def start_twitch_bot(): + logging.info("Start Twitch Bot") + with webapp.app_context(): + twitchBot.begin() if __name__ == '__main__': locale.setlocale(locale.LC_TIME, 'fr_FR.UTF-8') @@ -28,7 +28,7 @@ if __name__ == '__main__': jobs = [] jobs.append(threading.Thread(target=start_discord_bot)) jobs.append(threading.Thread(target=start_server)) - # jobs.append(threading.Thread(target=start_twitch_bot)) + jobs.append(threading.Thread(target=start_twitch_bot)) for job in jobs: job.start() for job in jobs: job.join() diff --git a/twitchbot/__init__.py b/twitchbot/__init__.py index 0d618cf..907b9af 100644 --- a/twitchbot/__init__.py +++ b/twitchbot/__init__.py @@ -1,5 +1,6 @@ import asyncio +import logging from twitchAPI.twitch import Twitch from twitchAPI.type import AuthScope, ChatEvent @@ -10,19 +11,22 @@ CLIENT_SECRET='TODO' USER_SCOPE = [AuthScope.CHAT_READ, AuthScope.CHAT_EDIT] -CHANNEL = "#gshionn" +CHANNEL = "#TODO" ACCESS_TOKEN = 'TODO' REFRESH_TOKEN = 'TODO' async def _onReady(ready_event: EventData): - print('Bot is ready for work, joining channels') + logging.info('Twitch bot ready') await ready_event.chat.join_room(CHANNEL) async def _onMessage(msg: ChatMessage): print(f'in {msg.room.name}, {msg.user.name} said: {msg.text}') +async def _helloCommand(msg: ChatMessage): + await msg.reply(f'Bonjour {msg.user.name}') + class TwitchBot() : async def _connect(self): @@ -32,7 +36,7 @@ class TwitchBot() : 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.register_command('hello', _helloCommand) self.chat.start() def begin(self):