reply formatted correctly; maybe - still need to test off-instance

This commit is contained in:
Camille Frantz 2025-10-10 16:44:21 -05:00
parent 4c3221af44
commit 6f9eea48b0
Signed by: fyrfli
SSH key fingerprint: SHA256:oxaZT6PRsoNy2x01TIrx3YE6H6p6gdmG2/Ir05d/bjc

View file

@ -19,7 +19,7 @@ message = ""
post_uri = f"https://{endpoint}/api/v1/statuses" post_uri = f"https://{endpoint}/api/v1/statuses"
note_to_post = "" note_to_post = ""
headers = { "Content-Type" : "application/json", headers = { "Content-Type" : "application/json",
"Authorization" : "Bearer " + fyrfli_token, "Authorization" : f"Bearer {fyrfli_token}",
"User-Agent" : "fyrfliBOT" } "User-Agent" : "fyrfliBOT" }
mention_id = "" mention_id = ""
created_note = "" created_note = ""
@ -33,9 +33,11 @@ async def hello(uri):
print(decoded.event, decoded.payload[1:49]) print(decoded.event, decoded.payload[1:49])
match decoded.event: match decoded.event:
case "delete": case "delete":
print("a delete event for id ", decoded.payload) print("a delete event for id ", decoded.payload, "\n===>\n")
case "update"|"status.update": case "update"|"status.update":
the_update = dm.fromDict(json.loads(decoded.payload)) the_update = dm.fromDict(json.loads(decoded.payload))
print(the_update)
if the_update.reblog: if the_update.reblog:
print( print(
"a reblog of ", "a reblog of ",
@ -43,7 +45,8 @@ async def hello(uri):
"\n id ", "\n id ",
the_update.id, the_update.id,
"\n created at ", "\n created at ",
the_update.created_at the_update.created_at,
"\n===>\n"
) )
else: else:
plain_text_content = strip_html(the_update.content) plain_text_content = strip_html(the_update.content)
@ -57,27 +60,26 @@ async def hello(uri):
"\n created at ", "\n created at ",
the_update.created_at, the_update.created_at,
"\n the content \n", "\n the content \n",
plain_text_content plain_text_content,
"\n===>\n"
) )
# payload = { "status": "oh ... hi @" + decoded['account']['acct'], strings_to_listen_for = ["folks" in plain_text_content.lower(),
# "in_reply_to_id": decoded['status']['id'], "love" in plain_text_content.lower(),
# "visibility": "unlisted" } "you" in plain_text_content.lower()]
if "folks" in plain_text_content: if any(strings_to_listen_for):
note_to_post = { note_to_post = {
"status": """ "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 ~ ",
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, "in_reply_to_id": the_update.id,
"visibility": "mutuals_only" "visibility": "mutuals_only",
"content_type": "text/markdown"
} }
r = requests.post( r = requests.post(
post_uri, post_uri,
headers=header, headers=headers,
data=note_to_post json=note_to_post
) )
print(r.reason, r.status_code)
case "notification": case "notification":
the_notification = dm.fromDict(json.loads(decoded.payload)) the_notification = dm.fromDict(json.loads(decoded.payload))
print( print(
@ -87,18 +89,23 @@ async def hello(uri):
" from ", " from ",
the_notification.account.acct, the_notification.account.acct,
" id ", the_notification.id, "\n", " id ", the_notification.id, "\n",
" created at ", the_notification.created_at " created at ", the_notification.created_at,
"\n===>\n"
) )
case _: case _:
print('unknown event: ', decoded.event, "\n", print('unknown event: ', decoded.event, "\n",
" with payload beginning ", " with payload beginning ",
decoded.payload[1:100]) decoded.payload[1:100])
except asyncio.exceptions.CancelledError: except asyncio.exceptions.CancelledError:
print('keyboard interrupt received ... exiting') print('keyboard interrupt received ... exiting')
break break
except KeyboardInterrupt: except KeyboardInterrupt:
print('keyboard interrupt received ... exiting') print('keyboard interrupt received ... exiting')
break break
except websockets.ConnectionClosed: except websockets.ConnectionClosed:
break break