Fix discord list_by_channel API call
This commit is contained in:
parent
358b3cc24c
commit
45731bda80
2 changed files with 9 additions and 6 deletions
|
|
@ -135,16 +135,19 @@ class Api:
|
|||
def delete(channel_id: int, message_id: int) -> tuple[ApiAction, str]:
|
||||
return ApiAction.DELETE, f'/channels/{channel_id}/messages/{message_id}'
|
||||
|
||||
@staticmethod
|
||||
def list_by_channel(channel_id: int) -> tuple[ApiAction, str]:
|
||||
return ApiAction.GET, f'/channels/{channel_id}/messages'
|
||||
|
||||
class ListMessageParams(TypedDict, total=False):
|
||||
around: int # Get messages around this message ID
|
||||
before: int # Get messages before this message ID
|
||||
after: int # Get messages after this message ID
|
||||
limit: int # Max number of messages to return (1-100), default=50
|
||||
|
||||
@staticmethod
|
||||
def list_by_channel(channel_id: int, params: ListMessageParams | None = None) -> tuple[ApiAction, str]:
|
||||
url = f'/channels/{channel_id}/messages'
|
||||
if params:
|
||||
url += f"?{'&'.join([f'{k}={v}' for k, v in params.items()])}"
|
||||
return ApiAction.GET, url
|
||||
|
||||
class User:
|
||||
@staticmethod
|
||||
def get_current() -> tuple[ApiAction, str]:
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ class DiscordManager:
|
|||
raise RuntimeError(
|
||||
f'HTTP error calling API ({url}): {error}:\nHeaders:\n{error.headers}Body:\n{error.read()}') from error
|
||||
except urllib.error.URLError as error:
|
||||
self._logger.debug('Discord API HTTP error -> data: %s', data)
|
||||
raise RuntimeError(f'URL error calling API ({url}): {error}') from error
|
||||
except TimeoutError as error:
|
||||
raise RuntimeError(f'Timeout calling API ({url}): {error}') from error
|
||||
|
|
@ -207,6 +208,5 @@ class DiscordManager:
|
|||
if after_id is not None:
|
||||
params['after'] = after_id
|
||||
_, messages_info = self._send_request(
|
||||
*Api.Message.list_by_channel(channel.id), request_timeout=request_timeout,
|
||||
data=json.dumps(params, cls=ApiEncoder).encode() if params else None)
|
||||
*Api.Message.list_by_channel(channel.id, params=params), request_timeout=request_timeout)
|
||||
return [Message.from_dict(m) for m in messages_info or []]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue