From 17d1dd48e4fbbb62b375a556d0d325beedf1b26a Mon Sep 17 00:00:00 2001 From: Camille Frantz Date: Fri, 10 Oct 2025 17:28:39 -0500 Subject: [PATCH] replying to mentions only now; still to come - respond based on substring found --- gts_socket_listen.py | 59 +++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/gts_socket_listen.py b/gts_socket_listen.py index c8b4001..de67996 100644 --- a/gts_socket_listen.py +++ b/gts_socket_listen.py @@ -19,7 +19,7 @@ message = "" post_uri = f"https://{endpoint}/api/v1/statuses" note_to_post = "" headers = { "Content-Type" : "application/json", - "Authorization" : f"Bearer {fyrfli_token}", + "Authorization" : f"Bearer {api_token}", "User-Agent" : "fyrfliBOT" } mention_id = "" created_note = "" @@ -37,7 +37,7 @@ async def hello(uri): case "update"|"status.update": the_update = dm.fromDict(json.loads(decoded.payload)) - print(the_update) + print(json.dumps(the_update)) if the_update.reblog: print( "a reblog of ", @@ -63,35 +63,48 @@ async def hello(uri): plain_text_content, "\n===>\n" ) - strings_to_listen_for = ["folks" in plain_text_content.lower(), - "love" in plain_text_content.lower(), - "you" in plain_text_content.lower()] - if any(strings_to_listen_for): - note_to_post = { - "status": f"[@{the_update.account.acct}](the_update.account.url) We come to love not by finding a perfect person, but by learning to see an imperfect person perfectly.\n ~ Sam Keen ~ ", - "in_reply_to_id": the_update.id, - "visibility": "mutuals_only", - "content_type": "text/markdown" - } - r = requests.post( - post_uri, - headers=headers, - json=note_to_post - ) - print(r.reason, r.status_code) + if the_update.mentions: + for mention in the_update.mentions: + if mention.username == "botsy": + note_to_post = { + "status": f"[@{the_update.account.acct}](the_update.account.url) We come to love not by finding a perfect person, but by learning to see an imperfect person perfectly.\n ~ Sam Keen ~ ", + "in_reply_to_id": the_update.id, + "visibility": "mutuals_only", + "content_type": "text/markdown" + } + r = requests.post( + post_uri, + headers=headers, + json=note_to_post + ) + print(r.reason, r.status_code) + break case "notification": - the_notification = dm.fromDict(json.loads(decoded.payload)) + the_notif = dm.fromDict(json.loads(decoded.payload)) print( "a ", - the_notification.type, + the_notif.type, " notification\n", " from ", - the_notification.account.acct, - " id ", the_notification.id, "\n", - " created at ", the_notification.created_at, + the_notif.account.acct, + " id ", the_notif.id, "\n", + " created at ", the_notif.created_at, "\n===>\n" ) + note_to_post = { + "status": f"[@{the_notif.account.acct}](the_notif.account.url) We come to love not by finding a perfect person, but by learning to see an imperfect person perfectly.\n ~ Sam Keen ~ ", + "in_reply_to_id": the_notif.id, + "visibility": "mutuals_only", + "content_type": "text/markdown" + } + r = requests.post( + post_uri, + headers=headers, + json=note_to_post + ) + print(r.reason, r.status_code) + case _: print('unknown event: ', decoded.event, "\n",