halcy / Mastodon.py

Python wrapper for the Mastodon ( https://github.com/mastodon/mastodon/ ) API.
MIT License
867 stars 150 forks source link

in_reply_to_id is empty in some cases #326

Closed Sakyce closed 1 year ago

Sakyce commented 1 year ago

Hey,

I'm having an issue with my autotune bot (updated source code at the moment i write this) and it looks like the bot can't see if the message it's replying to is a response to another message higher randomly. Basically, what I expect is that when I ping the bot under a post, it should answer with the autotuned video. Although the bot can't seem to find the post I'm replying to in some random cases.

image

I don't know if I actually did something wrong in my code but here is the code that triggers "stop pinging me"

def check_notifications():
    'Check notifications and schedule the requests'
    notifications = client.notifications()

    for notification in notifications:
        if notification.type == 'mention':
            soup = BeautifulSoup(notification.status.content, 'html.parser') # c'est un html

            try: video_status = client.status(notification.status.in_reply_to_id)
            except MastodonNotFoundError: 
                print(notification.status)
                requests_schedule.append(BadRequest('stop pinging me if you have no media for me to work on', notification))
                continue

Attempts (each json are my status pinging the bot under a post with a YT URL)

attempt 1

{'id': 109926282285499775, 'created_at': datetime.datetime(2023, 2, 25, 16, 19, 5, tzinfo=tzutc()), 'in_reply_to_id': None, 'in_reply_to_account_id': None, 'sensitive': False, 'spoiler_text': '', 'visibility': 'public', 'language': 'en', 'uri': 'https://chitter.xyz/users/dreamykeaver/statuses/109926281719609828', 'url': 'https://chitter.xyz/@dreamykeaver/109926281719609828', 'replies_count': 0, 'reblogs_count': 0, 'favourites_count': 0, 'edited_at': None, 'favourited': False, 'reblogged': False, 'muted': False, 'bookmarked': False, 'content': '<p><span class="h-card"><a href="https://pleroma.1d4.us/users/tiktoksthataregood" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>tiktoksthataregood</span></a></span> <span class="h-card"><a href="https://botsin.space/@autotune" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>autotune</span></a></span> <a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ" rel="nofollow noopener noreferrer" target="_blank"><span class="invisible">https://www.</span><span class="ellipsis">youtube.com/watch?v=dQw4w9WgXc</span><span class="invisible">Q</span></a></p>', 'filtered': [], 'reblog': None, 'account': {'id': 109913143969361466, 'username': 'dreamykeaver', 'acct': 'dreamykeaver@chitter.xyz', 'display_name': 'Dream Keaver :heart_trans:', 'locked': False, 'bot': False, 'discoverable': True, 'group': False, 'created_at': datetime.datetime(2023, 2, 20, 0, 0, tzinfo=tzutc()), 'note': '<p>Closeted trans girl programmer/artist online<br>migrating from twitter and may import twitter culture</p>', 'url': 'https://chitter.xyz/@dreamykeaver', 'avatar': 'https://files.botsin.space/cache/accounts/avatars/109/913/143/969/361/466/original/718a58ef7acb0e91.png', 'avatar_static': 'https://files.botsin.space/cache/accounts/avatars/109/913/143/969/361/466/original/718a58ef7acb0e91.png', 'header': 'https://files.botsin.space/cache/accounts/headers/109/913/143/969/361/466/original/407007094ef9f431.png', 'header_static': 'https://files.botsin.space/cache/accounts/headers/109/913/143/969/361/466/original/407007094ef9f431.png', 'followers_count': 8, 'following_count': 23, 'statuses_count': 71, 'last_status_at': datetime.datetime(2023, 2, 25, 0, 0), 'emojis': [{'shortcode': 'heart_trans', 'url': 'https://files.botsin.space/custom_emojis/images/000/004/430/original/d42dba04c097b7f3.png', 'static_url': 'https://files.botsin.space/custom_emojis/images/000/004/430/static/d42dba04c097b7f3.png', 'visible_in_picker': True}], 'fields': [{'name': 'YouTube', 'value': '@tastysakyceerasement8355', 'verified_at': None}, {'name': 'Discord', 'value': 'DreamKeaver#2638', 'verified_at': None}, {'name': 'Status', 'value': 'Working on @autotune@botsin.space !', 'verified_at': None}]}, 'media_attachments': [], 'mentions': [{'id': 106721770548257475, 'username': 'tiktoksthataregood', 'url': 'https://pleroma.1d4.us/users/tiktoksthataregood', 'acct': 'tiktoksthataregood@pleroma.1d4.us'}, {'id': 109918744581151959, 'username': 'autotune', 'url': 'https://botsin.space/@autotune', 'acct': 'autotune'}], 'tags': [], 'emojis': [], 'card': None, 'poll': None}

attempt 2

{'id': 109926258255982211, 'created_at': datetime.datetime(2023, 2, 25, 16, 12, 59, tzinfo=tzutc()), 'in_reply_to_id': None, 'in_reply_to_account_id': None, 'sensitive': False, 'spoiler_text': '', 'visibility': 'public', 'language': 'en', 'uri': 'https://chitter.xyz/users/dreamykeaver/statuses/109926257757449498', 'url': 'https://chitter.xyz/@dreamykeaver/109926257757449498', 'replies_count': 0, 'reblogs_count': 0, 'favourites_count': 0, 'edited_at': None, 'favourited': False, 'reblogged': False, 'muted': False, 'bookmarked': False, 'content': '<p><span class="h-card"><a href="https://mastodon.xyz/@Xibanya" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>Xibanya</span></a></span> <span class="h-card"><a href="https://botsin.space/@autotune" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>autotune</span></a></span> <a href="https://youtu.be/dQw4w9WgXcQ" rel="nofollow noopener noreferrer" target="_blank"><span class="invisible">https://</span><span class="">youtu.be/dQw4w9WgXcQ</span><span class="invisible"></span></a></p>', 'filtered': [], 'reblog': None, 'account': {'id': 109913143969361466, 'username': 'dreamykeaver', 'acct': 'dreamykeaver@chitter.xyz', 'display_name': 'Dream Keaver :heart_trans:', 'locked': False, 'bot': False, 'discoverable': True, 'group': False, 'created_at': datetime.datetime(2023, 2, 20, 0, 0, tzinfo=tzutc()), 'note': '<p>Closeted trans girl programmer/artist online<br>migrating from twitter and may import twitter culture</p>', 'url': 'https://chitter.xyz/@dreamykeaver', 'avatar': 'https://files.botsin.space/cache/accounts/avatars/109/913/143/969/361/466/original/718a58ef7acb0e91.png', 'avatar_static': 'https://files.botsin.space/cache/accounts/avatars/109/913/143/969/361/466/original/718a58ef7acb0e91.png', 'header': 'https://files.botsin.space/cache/accounts/headers/109/913/143/969/361/466/original/407007094ef9f431.png', 'header_static': 'https://files.botsin.space/cache/accounts/headers/109/913/143/969/361/466/original/407007094ef9f431.png', 'followers_count': 8, 'following_count': 23, 'statuses_count': 69, 'last_status_at': datetime.datetime(2023, 2, 25, 0, 0), 'emojis': [{'shortcode': 'heart_trans', 'url': 'https://files.botsin.space/custom_emojis/images/000/004/430/original/d42dba04c097b7f3.png', 'static_url': 'https://files.botsin.space/custom_emojis/images/000/004/430/static/d42dba04c097b7f3.png', 'visible_in_picker': True}], 'fields': [{'name': 'YouTube', 'value': '@tastysakyceerasement8355', 'verified_at': None}, {'name': 'Discord', 'value': 'DreamKeaver#2638', 'verified_at': None}, {'name': 'Status', 'value': 'Working on @autotune@botsin.space !', 'verified_at': None}]}, 'media_attachments': [], 'mentions': [{'id': 375, 'username': 'Xibanya', 'url': 'https://mastodon.xyz/@Xibanya', 'acct': 'Xibanya@mastodon.xyz'}, {'id': 109918744581151959, 'username': 'autotune', 'url': 'https://botsin.space/@autotune', 'acct': 'autotune'}], 'tags': [], 'emojis': [], 'card': None, 'poll': None}

For some reasons it worked for a nsfw post (that i'm not going to link here) that is in kinky.business while I'm in chitter.xyz and my bot in botsin.space.

Sakyce commented 1 year ago

I actually don't know if it's a bug or an intentional behaviour.

codl commented 1 year ago

I think this is a problem with botsin.space, it's probably backed up. I can see the same kind of behaviour in the web ui, if i mention an account on botsin.space while replying to a post that's not already known by botsin.space, the parent post just doesn't appear (and the api says in_reply_to: null)

e: yeah it eventually showed up

Sakyce commented 1 year ago

Are there any workarounds except asking users to try again a few minutes later ?

codl commented 1 year ago

Not really. You could try refetching the status every couple minutes and see if it gets an in_reply_to, but that's not great.

You could also move the bot somewhere else. In my experience botsin.space is chronically overloaded

Sakyce commented 1 year ago

Do you know some good instances where I can migrate it ?