Added first working chat recorder

This commit is contained in:
Vitalii Lebedynskyi
2022-08-09 13:17:29 +03:00
parent e00fb5bd70
commit 86ac82f28d
7 changed files with 178 additions and 145 deletions

View File

@@ -1,19 +1,17 @@
import twitch
import logging
logger = logging.getLogger(__name__)
class TwitchChatRecorder:
def __init__(self, authenticator, streamer_name, on_finish=None):
def __init__(self, api, streamer_name, ignored_prefix=["!"], on_finish=None):
self.ignored_prefix = ignored_prefix
self.on_finish = on_finish
self.streamer_name = streamer_name
self.authenticator = authenticator
self.api = api
def run(self):
chat = twitch.Chat(self.streamer_name, self.authenticator.username, self.authenticator.get_token())
logger.info("Subscribing to chat for %s as %s", self.streamer_name, self.authenticator.username)
chat.subscribe(on_next=self.on_message, on_error=self.on_error)
self.api.start_chat(self.streamer_name)
def on_error(self, error):
logger.error(error)