From 8224c58da1356b3adf26577eb6493c8d2cdb439d Mon Sep 17 00:00:00 2001 From: neppa Date: Sun, 8 Oct 2023 16:36:44 -0400 Subject: [PATCH] Add translate.py --- translate.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 translate.py diff --git a/translate.py b/translate.py new file mode 100644 index 0000000..666118c --- /dev/null +++ b/translate.py @@ -0,0 +1,29 @@ +import os + +from googletrans import Translator +from twitch_chat_irc import twitch_chat_irc +from dotenv import load_dotenv + +channel_to_read_chat_from = "" +channel_to_send_translations_to = "" + +load_dotenv() + +username = os.getenv('TWITCH_LOGIN_NAME') +oauth = os.getenv('TWITCH_OAUTH_TOKEN') + +connection = twitch_chat_irc.TwitchChatIRC() +connection = twitch_chat_irc.TwitchChatIRC(username, oauth) + +translator = Translator() + +def do_something(message): + + msg = message["message"] + translated_text = translator.translate(msg) + print(translated_text) + + translated = translated_text.text + connection.send(channel_to_read_chat_from, f"{message['display-name']}: {translated}") + +connection.listen(channel_to_send_translations_to, on_message=do_something)