From 61c0e9bd624e3f647bdc4aeb387fca3e9570ce6b Mon Sep 17 00:00:00 2001 From: sugoidogo Date: Wed, 27 May 2026 03:47:14 -0700 Subject: [PATCH] allow running bot under alternate user --- astrolobot.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/astrolobot.py b/astrolobot.py index b3ff1ed..5342000 100755 --- a/astrolobot.py +++ b/astrolobot.py @@ -479,6 +479,12 @@ def main(): @client.event async def on_ready() -> None: + global user + user=client.user + config=load_settings() + if('channel' in config): + user=await client.get_user(config['channel']) + await client.add_custom_event('on_chat_message',user,on_chat_message) print('astrolobot ready') while True: tokens=client.http.get_token(client.user.id) @@ -486,32 +492,32 @@ def main(): tokens=refresh_tokens(tokens['refresh_token']) await client.authorize(tokens['access_token'],tokens['refresh_token']) - @client.event async def on_chat_message(data: eventsub.chat.MessageEvent): + global user config=load_settings() if data['message']['text']==config['positions']: for line in get_positions_formatted().splitlines(False): - await client.channel.chat.send_message(line,data['message_id']) + await user.channel.chat.send_message(line,data['message_id']) return if data['message']['text']==config['transits']: for line in get_transits_formatted().splitlines(False): - await client.channel.chat.send_message(line,data['message_id']) + await user.channel.chat.send_message(line,data['message_id']) return if data['message']['text']==config['major_aspects']: for line in get_aspects_formatted().splitlines(False): - await client.channel.chat.send_message(line,data['message_id']) + await user.channel.chat.send_message(line,data['message_id']) return if data['message']['text']==config['minor_aspects']: for line in get_aspects_formatted(minor=True).splitlines(False): - await client.channel.chat.send_message(line,data['message_id']) + await user.channel.chat.send_message(line,data['message_id']) return if data['message']['text']==config['major_aspect_transits']: for line in get_aspect_transits_formatted().splitlines(False): - await client.channel.chat.send_message(line,data['message_id']) + await user.channel.chat.send_message(line,data['message_id']) return if data['message']['text']==config['minor_aspect_transits']: for line in get_aspect_transits_formatted(minor=True).splitlines(False): - await client.channel.chat.send_message(line,data['message_id']) + await user.channel.chat.send_message(line,data['message_id']) return client.run(*tokens.values()) @@ -562,6 +568,7 @@ def script_properties(): properties=obspython.obs_properties_create() obspython.obs_properties_add_button(properties,'login','Login to Twitch',login) obspython.obs_properties_add_button(properties,'update','Check for Updates',obs_update) + obspython.obs_properties_add_text(properties,'channel','channel name',obspython.OBS_TEXT_DEFAULT) obspython.obs_properties_add_text(properties,'commands','commands',obspython.OBS_TEXT_INFO) obspython.obs_properties_add_text(properties,'positions','positions',obspython.OBS_TEXT_DEFAULT) obspython.obs_properties_add_text(properties,'transits','transits',obspython.OBS_TEXT_DEFAULT)