BuStudios / StashConnect

An API wrapper for stashcat.
MIT License
4 stars 1 forks source link

Messages generator not actually readable? #1

Closed JSmaler closed 4 days ago

JSmaler commented 3 weeks ago

I'll admit that I am not much of a programmer. I have managed to slap together a small UI, into which I now want to add some way to simply load the last message(s) from a Chanel. For this, I use: msg = client.messages.get_messages("[chanel ID]") This appears to work. It appears to output a generator object MessageManager.get_messages. Now, however I may try to read anything from this, it leads to the following error, in many different versions.

Traceback (most recent call last):
  File "/run/media/jkr/priv/priv/dev/python/./script.py", line 24, in <module>
    print(next(msg)) #)[message])
          ^^^^^^^^^
  File "/home/jkr/.local/lib/python3.12/site-packages/stashconnect/messages.py", line 262, in get_messages
    yield Message(self.client, message)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jkr/.local/lib/python3.12/site-packages/stashconnect/models.py", line 39, in __init__
    self.files = [File(self.client, file) for file in data["files"]]
                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jkr/.local/lib/python3.12/site-packages/stashconnect/models.py", line 651, in __init__
    self.set_attributes(data)
  File "/home/jkr/.local/lib/python3.12/site-packages/stashconnect/models.py", line 688, in set_attributes
    self.owner = User(self.client, data["owner"])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jkr/.local/lib/python3.12/site-packages/stashconnect/models.py", line 168, in __init__
    user_data = self.client.users._info(self.id)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jkr/.local/lib/python3.12/site-packages/stashconnect/users.py", line 18, in _info
    response = self.client._post(
               ^^^^^^^^^^^^^^^^^^
  File "/home/jkr/.local/lib/python3.12/site-packages/stashconnect/client.py", line 137, in _post
    raise Exception(status["message"])
Exception: no permission to display user information

This may be because my understanding of generators is quite literally nonexistent, though I doubt that, since any possible way to manage the message, extract any useful information from it, leads to the same kind of issue. If it is an issue with my understanding of generators, however, I am sorry for creating an unended issue.

Either way, it would be great to have an example of how to read messages from a channel, as exists with such things as changing account password, which is a significantly less obvious use of the API.

BuStudios commented 3 weeks ago

Hi, the issue seems to occur because the account you logged in with does not have permission to display user information, your code seems to be correct though. I just committed a fix that should hopefully fix the issue your having. You can upgrade your current version using pip install stashconnect -U. Could you perhaps send me a follow up so i know if it works, since i can't verify it myself? I also added a small example of how to get the latest messages in the readme but i intend to create a full wiki for the whole stashconnect project.