scratchattach icon indicating copy to clipboard operation
scratchattach copied to clipboard

Error fetching comment by ID

Open uukelele-scratch opened this issue 11 months ago • 5 comments

Traceback (most recent call last):
  File "main.py", line 160, in replyComment
    comment_obj = user.comment_by_id(commentID)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/.local/lib/python3.11/site-packages/scratchattach/site/user.py", line 730, in comment_by_id
    results = list(filter(lambda x : str(x.id) == str(comment_id), page_content))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not iterable

When I'm replying using the ID of a root-level comment it works fine, but as soon as I attempt to reply using the ID of a reply this error is thrown.

I can't even try replying to the comment with its parent, as I can't even get the comment_obj.

Here's more of my code:

def replyComment(comment, user, commentID):
        user = session.connect_user(user)
        comment_obj = user.comment_by_id(commentID)
        comment_obj.reply(comment)
        return "Comment replied to successfully!"

uukelele-scratch avatar Jan 26 '25 08:01 uukelele-scratch

I have recently also had problems with the comment system, and found some quirks/scratchattach didn't work for me. Perhaps there was an update to the API (possibly at the time when using commentee-id to get username by id was removed) which caused the scratchattach library to go out of date in this respect. It might be something to be investigated

faretek1 avatar Jan 26 '25 09:01 faretek1

Hello! Only replies to top-level comments are shown on the Scratch website. Replies to replies are actually replies to the corresponding top-level comment in the API and aren't different in any way. Thus, you will have to use the parent id of the original comment when trying to reply. The correct syntax to reply to a comment is: user.reply_comment("comment content", parent_id="parent_id", commentee_id=""). Use the commentee_id to notify a user / ping a user about the message (put their user_id) (that is also how replies are handled in the API).

abhiramtx avatar Jan 28 '25 01:01 abhiramtx

Hello! Only replies to top-level comments are shown on the Scratch website. Replies to replies are actually replies to the corresponding top-level comment in the API and aren't different in any way. Thus, you will have to use the parent id of the original comment when trying to reply. The correct syntax to reply to a comment is: user.reply_comment("comment content", parent_id="parent_id", commentee_id=""). Use the commentee_id to notify a user / ping a user about the message (put their user_id) (that is also how replies are handled in the API).

What you're saying I should do is use the comment ID to get a comment object, then use the parent comment method of that comment to find the parent comment, and finally reply to the parent comment.

However, I can't even get the comment object from the comment ID.

uukelele-scratch avatar Jan 28 '25 08:01 uukelele-scratch

I will look into it

uukelele-scratch @.***> schrieb am Di., 28. Jan. 2025, 09:01:

Hello! Only replies to top-level comments are shown on the Scratch website. Replies to replies are actually replies to the corresponding top-level comment in the API and aren't different in any way. Thus, you will have to use the parent id of the original comment when trying to reply. The correct syntax to reply to a comment is: user.reply_comment("comment content", parent_id="parent_id", commentee_id=""). Use the commentee_id to notify a user / ping a user about the message (put their user_id) (that is also how replies are handled in the API).

What you're saying I should do is use the comment ID to get a comment object, then use the parent comment method of that comment to find the parent comment, and finally reply to the parent comment.

However, I can't even get the comment object from the comment ID.

— Reply to this email directly, view it on GitHub https://github.com/TimMcCool/scratchattach/issues/336#issuecomment-2618160738, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATCKMZX5V7BUACHV7UYRWCT2M42MHAVCNFSM6AAAAABV4G2MXGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMJYGE3DANZTHA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

TheCommCraft avatar Jan 28 '25 08:01 TheCommCraft

Interesting. Sometimes, when viewing the comments page, recent comments don't show. Perhaps something needs to be added in this function to handle empty comment pages.

uukelele-scratch avatar Jan 28 '25 10:01 uukelele-scratch