Skip to content

Conversation

uukelele-scratch
Copy link
Contributor

@uukelele-scratch uukelele-scratch commented Apr 11, 2025

When I got temporarily comment banned by Scratch, I decided to do something useful and log the error messages that the POST endpoint received. Here's what I got:

STATUS: 200 OK
<script id="error-data" type="application/json">
    {
        "mute_status": {
            "offenses": [
                {
                    "expiresAt": 1744997826.41933,
                    "messageType": "chatsite",
                    "createdAt": 1744393026.41933
                }
            ],
            "showWarning": false,
            "muteExpiresAt": 1744393326.777156,
            "currentMessageType": "chatsite"
        },
        "error": "isMuted"
    }</script>

Signed-off-by: uukelele <robustrobot11@gmail.com>
@TheCommCraft
Copy link
Collaborator

Did you test it?

@uukelele-scratch
Copy link
Contributor Author

Did you test it?

Nah not yet, can't test it until I (or someone else) get muted.

Actually, I could test it right now.

@TheCommCraft
Copy link
Collaborator

TheCommCraft commented Apr 12, 2025 via email

@FAReTek1
Copy link
Collaborator

This could potentially be integrated with #327 if that is implemented

@FAReTek1

This comment was marked as off-topic.

@uukelele-scratch
Copy link
Contributor Author

uukelele-scratch commented Apr 13, 2025

Test:

C:\Users\robus>mkdir temp

C:\Users\robus>cd temp

C:\Users\robus\temp>git clone -b patch-1 --single-branch --depth 1 https://github.com/uukelele-scratch/scratchattach.git
Cloning into 'scratchattach'...
remote: Enumerating objects: 189, done.
remote: Counting objects: 100% (189/189), done.
remote: Compressing objects: 100% (170/170), done.
remote: Total 189 (delta 22), reused 107 (delta 11), pack-reused 0 (from 0)
Receiving objects: 100% (189/189), 4.15 MiB | 5.17 MiB/s, done.
Resolving deltas: 100% (22/22), done.

C:\Users\robus\temp>cd scratchattach

C:\Users\robus\temp\scratchattach>pip install -e .
Defaulting to user installation because normal site-packages is not writeable
Obtaining file:///C:/Users/robus/temp/scratchattach
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Requirement already satisfied: websocket-client in c:\users\robus\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from scratchattach==2.1.11) (1.8.0)
Requirement already satisfied: requests in c:\users\robus\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from scratchattach==2.1.11) (2.32.3)
Requirement already satisfied: bs4 in c:\users\robus\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from scratchattach==2.1.11) (0.0.2)
Requirement already satisfied: SimpleWebSocketServer in c:\users\robus\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from scratchattach==2.1.11) (0.1.2)
Requirement already satisfied: beautifulsoup4 in c:\users\robus\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from bs4->scratchattach==2.1.11) (4.12.3)
Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\robus\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from requests->scratchattach==2.1.11) (3.4.0)
Requirement already satisfied: idna<4,>=2.5 in c:\users\robus\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from requests->scratchattach==2.1.11) (3.10)
Requirement already satisfied: urllib3<3,>=1.21.1 in c:\users\robus\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from requests->scratchattach==2.1.11) (1.26.20)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\robus\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from requests->scratchattach==2.1.11) (2024.8.30)
Requirement already satisfied: soupsieve>1.2 in c:\users\robus\appdata\local\packages\pythonsoftwarefoundation.python.3.13_qbz5n2kfra8p0\localcache\local-packages\python313\site-packages (from beautifulsoup4->bs4->scratchattach==2.1.11) (2.6)
Building wheels for collected packages: scratchattach
  Building editable for scratchattach (pyproject.toml) ... done
  Created wheel for scratchattach: filename=scratchattach-2.1.11-0.editable-py3-none-any.whl size=5557 sha256=c8f33d3e8bbc50a805479015d91be687f7ace4631b226bdb336adf99fd3b8d43
  Stored in directory: C:\Users\robus\AppData\Local\Temp\pip-ephem-wheel-cache-eipmswh6\wheels\16\e4\a0\a52beb563537441504e38ae694c9508e3c7621950cdabafc22
Successfully built scratchattach
Installing collected packages: scratchattach
  Attempting uninstall: scratchattach
    Found existing installation: scratchattach 2.1.6
    Uninstalling scratchattach-2.1.6:
      Successfully uninstalled scratchattach-2.1.6
Successfully installed scratchattach-2.1.11

C:\Users\robus\temp\scratchattach>python
Python 3.13.3 (tags/v3.13.3:6280bb5, Apr  8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import scratchattach as sa
>>> import os
>>> session = sa.login_by_id("******", username="uukelele")
C:\Users\robus\temp\scratchattach\scratchattach\site\session.py:1003: LoginDataWarning: IMPORTANT: If you included login credentials directly in your code (e.g. session_id, session_string, ...),         then make sure to EITHER instead load them from environment variables or files OR remember to remove them before         you share your code with anyone else. If you want to remove this warning,         use `warnings.filterwarnings('ignore', category=scratchattach.LoginDataWarning)`
  warnings.warn(
>>> me = session.get_linked_user()
>>> me.post_comment("test")
<scratchattach.site.comment.Comment object at 0x0000020978923770>
>>> me.post_comment("scratchaddons")
Traceback (most recent call last):
  File "C:\Users\robus\temp\scratchattach\scratchattach\site\user.py", line 546, in post_comment
    'id': text.split('<div id="comments-')[1].split('" class="comment')[0],
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<python-input-9>", line 1, in <module>
    me.post_comment("scratchaddons")
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "C:\Users\robus\temp\scratchattach\scratchattach\site\user.py", line 564, in post_comment
    raise(exceptions.CommentPostFailure(f"You have been muted. Mute expires on {expires}"))
scratchattach.utils.exceptions.CommentPostFailure: You have been muted. Mute expires on 2025-04-13 14:46:17.890074
>>> me.post_comment("test")
Traceback (most recent call last):
  File "C:\Users\robus\temp\scratchattach\scratchattach\site\user.py", line 546, in post_comment
    'id': text.split('<div id="comments-')[1].split('" class="comment')[0],
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<python-input-10>", line 1, in <module>
    me.post_comment("test")
    ~~~~~~~~~~~~~~~^^^^^^^^
  File "C:\Users\robus\temp\scratchattach\scratchattach\site\user.py", line 564, in post_comment
    raise(exceptions.CommentPostFailure(f"You have been muted. Mute expires on {expires}"))
scratchattach.utils.exceptions.CommentPostFailure: You have been muted. Mute expires on 2025-04-13 14:46:17.385499
>>> import datetime
>>> str(datetime.datetime.now())
'2025-04-13 15:37:14.609752'
>>>

Test Feedback:

  • ✅ throws the correct error message, as expected
  • ❌ datetime seems to show the timestamp as being around an hour earlier than it actually is, though unable to verify due to not being able to see the original feedback
  • ⚠️ it does throw an error of IndexError: list out of range but then interrupts that exception with the intended CommentPostFailure

@TheCommCraft
Copy link
Collaborator

Are you UTC?

@cybersteve547

This comment was marked as off-topic.

@cybersteve547

This comment was marked as off-topic.

@uukelele-scratch
Copy link
Contributor Author

Are you UTC?

Oh yeah, I completely forgot about timezones. Perhaps that could be added to this? Prefer the user's timezone.

@uukelele-scratch
Copy link
Contributor Author

Perhaps that could be added to this? Prefer the user's timezone.

Nope, we can't do that unless we use third party libraries, pytz and tzlocal - and I think it's best to avoid increasing the dependency count.

We could also use zoneinfo, but that only works on Python 3.9 and above. What version of Python does scratchattach require? If it's 3.9 or higher, we could try using that.

Or I guess we could go to far-fetched solutions like using the network to determine timezone, but that's overcomplicating it.

@FAReTek1

This comment was marked as off-topic.

@TheCommCraft TheCommCraft merged commit 0eddde8 into TimMcCool:main Apr 19, 2025
@TheCommCraft
Copy link
Collaborator

Merging for now, if you want to add timezone, please create a new PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants