shayypy / guilded.py

Asynchronous Guilded API wrapper for Python
https://guildedpy.rtfd.io
Other
133 stars 25 forks source link

Embed timestamp error - not a valid ISO8601 datetime. #15

Closed czechbol closed 3 years ago

czechbol commented 3 years ago

Describe the bug If I want to add a timestamp (where I can only use datetime.datetime or Embed.Empty), guilded.py throws an error at me that it's not a valid ISO8601 datetime.

To Reproduce Create an embed and add a timestamp:

embed = guilded.Embed(
            title="Title",
            description="Description"
        )
embed.timestamp = datetime.datetime.utcnow()
await ctx.send(embed=embed)

Expected behavior I would expect that guilded.py would convert the timestamp to ISO8601 for me since I cannot use an ISO8601 str instead.

Actual behavior I receive a TypeError and the message gets sent with a timestamp (not sure if it is correct, the embed shows the correct date at least)

Traceback (Note in the screenshot that I send an embed on an exception, so the traceback is doubled) ``` Traceback (most recent call last): File "/root/.local/lib/python3.9/site-packages/guilded/client.py", line 231, in _run_event await coro(*args, **kwargs) File "/Pumpkin/modules/base/errors/module.py", line 34, in on_error await bot_log.error(None, None, traceback=tb) TypeError: error() missing 1 required positional argument: 'message' Task exception was never retrieved future: exception=GuildedException(TypeError('2021-09-04T15:17:24.372247+00:00 is not a valid ISO8601 datetime.'))> Traceback (most recent call last): File "/root/.local/lib/python3.9/site-packages/guilded/utils.py", line 75, in ISO8601 return datetime.datetime.strptime(string, '%Y-%m-%dT%H:%M:%S.%fZ') File "/usr/local/lib/python3.9/_strptime.py", line 568, in _strptime_datetime tt, fraction, gmtoff_fraction = _strptime(data_string, format) File "/usr/local/lib/python3.9/_strptime.py", line 349, in _strptime raise ValueError("time data %r does not match format %r" % ValueError: time data '2021-09-04T15:17:24.372247+00:00' does not match format '%Y-%m-%dT%H:%M:%S.%fZ' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/root/.local/lib/python3.9/site-packages/guilded/gateway.py", line 173, in received_event await event File "/root/.local/lib/python3.9/site-packages/guilded/gateway.py", line 239, in ChatMessageCreated message = self._state.create_message(channel=channel, data=data, author=author, team=team) File "/root/.local/lib/python3.9/site-packages/guilded/http.py", line 727, in create_message return ChatMessage(state=self, **data) File "/root/.local/lib/python3.9/site-packages/guilded/message.py", line 277, in __init__ self.content = self._get_full_content(data) File "/root/.local/lib/python3.9/site-packages/guilded/message.py", line 424, in _get_full_content self.embeds.append(Embed.from_dict(msg_embed)) File "/root/.local/lib/python3.9/site-packages/guilded/embed.py", line 191, in from_dict self._timestamp = utils.ISO8601(data['timestamp']) File "/root/.local/lib/python3.9/site-packages/guilded/utils.py", line 81, in ISO8601 raise TypeError(f'{string} is not a valid ISO8601 datetime.') TypeError: 2021-09-04T15:17:24.372247+00:00 is not a valid ISO8601 datetime. The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/root/.local/lib/python3.9/site-packages/guilded/client.py", line 283, in start await self.connect() File "/root/.local/lib/python3.9/site-packages/guilded/client.py", line 372, in connect await asyncio.gather( File "/root/.local/lib/python3.9/site-packages/guilded/client.py", line 346, in listen_socks await ws.poll_event() File "/root/.local/lib/python3.9/site-packages/guilded/gateway.py", line 186, in poll_event await self.received_event(msg.data) File "/root/.local/lib/python3.9/site-packages/guilded/gateway.py", line 181, in received_event raise exc from e guilded.errors.GuildedException: 2021-09-04T15:17:24.372247+00:00 is not a valid ISO8601 datetime. Ignoring exception in on_command_error: Traceback (most recent call last): File "/root/.local/lib/python3.9/site-packages/guilded/utils.py", line 75, in ISO8601 return datetime.datetime.strptime(string, '%Y-%m-%dT%H:%M:%S.%fZ') File "/usr/local/lib/python3.9/_strptime.py", line 568, in _strptime_datetime tt, fraction, gmtoff_fraction = _strptime(data_string, format) File "/usr/local/lib/python3.9/_strptime.py", line 349, in _strptime raise ValueError("time data %r does not match format %r" % ValueError: time data '2021-09-04T15:17:25.902639+00:00' does not match format '%Y-%m-%dT%H:%M:%S.%fZ' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/root/.local/lib/python3.9/site-packages/guilded/client.py", line 231, in _run_event await coro(*args, **kwargs) File "/Pumpkin/modules/base/errors/module.py", line 67, in on_command_error await ctx.send(embed=embed) File "/root/.local/lib/python3.9/site-packages/guilded/abc.py", line 188, in send return Message(state=self._state, channel=self, data=payload, author=author) File "/root/.local/lib/python3.9/site-packages/guilded/message.py", line 277, in __init__ self.content = self._get_full_content(data) File "/root/.local/lib/python3.9/site-packages/guilded/message.py", line 424, in _get_full_content self.embeds.append(Embed.from_dict(msg_embed)) File "/root/.local/lib/python3.9/site-packages/guilded/embed.py", line 191, in from_dict self._timestamp = utils.ISO8601(data['timestamp']) File "/root/.local/lib/python3.9/site-packages/guilded/utils.py", line 81, in ISO8601 raise TypeError(f'{string} is not a valid ISO8601 datetime.') TypeError: 2021-09-04T15:17:25.902639+00:00 is not a valid ISO8601 datetime. ```

Screenshot

Screenshot_20210904_171741

Environment