robertoszek / pleroma-bot

Bot for mirroring one or multiple Twitter accounts in Pleroma/Mastodon/Misskey.
https://robertoszek.github.io/pleroma-bot
MIT License
104 stars 18 forks source link

error with pinned posts #104

Closed selyod-ka closed 1 year ago

selyod-ka commented 1 year ago

hey! I just noticed an error with importing tweets, that occurs when the pinned post was pinned manually in mastodon and only later a tweet is pinned in twitter. This post then gets imported every time pleroma-bot is running.

Here are the logs:

ℹ 2022-12-20 13:02:44,191 - pleroma_bot - INFO - Processing user:       xxxxxxxxxxxxxxxxxx
ℹ 2022-12-20 13:03:02,801 - pleroma_bot - INFO - Current pinned:        xxxxxxxxxxxxxxxxxx
ℹ 2022-12-20 13:03:02,801 - pleroma_bot - INFO - Previous pinned:       None
ℹ 2022-12-20 13:03:03,931 - pleroma_bot - INFO - Post in Pleroma:       <Response [200]>
ℹ 2022-12-20 13:03:03,932 - pleroma_bot - INFO - File with previous pinned post ID not found or empty. Checking last posts for pinned post...
✖ 2022-12-20 13:03:03,932 - pleroma_bot - ERROR - Exception occurred for user, skipping... (cli.py:576)
Traceback (most recent call last):
  File "./pleroma-bot/myvenv/lib/python3.6/site-packages/pleroma_bot/cli.py", line 561, in main
    user.check_pinned(posted)
  File "./pleroma-bot/myvenv/lib/python3.6/site-packages/pleroma_bot/_utils.py", line 356, in check_pinned
    pinned_post = self.pin(id_post_to_pin)
  File "./pleroma-bot/myvenv/lib/python3.6/site-packages/pleroma_bot/_utils.py", line 630, in pin
    pin_id = self.pin_pleroma(id_post)
  File "./pleroma-bot/myvenv/lib/python3.6/site-packages/pleroma_bot/_pin.py", line 133, in pin_pleroma
    self.unpin_pleroma(pinned_file)
  File "./pleroma-bot/myvenv/lib/python3.6/site-packages/pleroma_bot/_pin.py", line 179, in unpin_pleroma
    pinned = _find_pinned(self, pinned_file)
  File "./pleroma-bot/myvenv/lib/python3.6/site-packages/pleroma_bot/_pin.py", line 200, in _find_pinned
    if post["pinned"]:
KeyError: 'pinned'

I suppose line 200 in _pin.py should read as follows: if "pinned" in post.keys() and post["pinned"]: At least this fixes the error in my case.

robertoszek commented 1 year ago

You are indeed correct! I didn't anticipate the edge-case of a post being manually pinned alongside the ones being automatically pinned/unpinned by the bot. Thanks for this 👍