mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 12:18:59 +00:00
Some initial response typings
This commit is contained in:
parent
74f92387ac
commit
a30ec197c2
@ -22,10 +22,13 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
from typing import Any, Coroutine, List, TYPE_CHECKING, TypeVar
|
||||||
from urllib.parse import quote as _uriquote
|
from urllib.parse import quote as _uriquote
|
||||||
import weakref
|
import weakref
|
||||||
|
|
||||||
@ -37,6 +40,14 @@ from . import __version__, utils
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .types import (
|
||||||
|
interactions,
|
||||||
|
)
|
||||||
|
|
||||||
|
T = TypeVar('T')
|
||||||
|
Response = Coroutine[Any, Any, T]
|
||||||
|
|
||||||
|
|
||||||
async def json_or_text(response):
|
async def json_or_text(response):
|
||||||
text = await response.text(encoding='utf-8')
|
text = await response.text(encoding='utf-8')
|
||||||
@ -138,7 +149,7 @@ class HTTPClient:
|
|||||||
|
|
||||||
return await self.__session.ws_connect(url, **kwargs)
|
return await self.__session.ws_connect(url, **kwargs)
|
||||||
|
|
||||||
async def request(self, route, *, files=None, form=None, **kwargs):
|
async def request(self, route, *, files=None, form=None, **kwargs) -> Any:
|
||||||
bucket = route.bucket
|
bucket = route.bucket
|
||||||
method = route.method
|
method = route.method
|
||||||
url = route.url
|
url = route.url
|
||||||
@ -1039,10 +1050,10 @@ class HTTPClient:
|
|||||||
|
|
||||||
# Application commands (global)
|
# Application commands (global)
|
||||||
|
|
||||||
def get_global_commands(self, application_id):
|
def get_global_commands(self, application_id) -> Response[List[interactions.ApplicationCommand]]:
|
||||||
return self.request(Route('GET', '/applications/{application_id}/commands', application_id=application_id))
|
return self.request(Route('GET', '/applications/{application_id}/commands', application_id=application_id))
|
||||||
|
|
||||||
def get_global_command(self, application_id, command_id):
|
def get_global_command(self, application_id, command_id) -> Response[interactions.ApplicationCommand]:
|
||||||
r = Route(
|
r = Route(
|
||||||
'GET',
|
'GET',
|
||||||
'/applications/{application_id}/commands/{command_id}',
|
'/applications/{application_id}/commands/{command_id}',
|
||||||
@ -1051,11 +1062,11 @@ class HTTPClient:
|
|||||||
)
|
)
|
||||||
return self.request(r)
|
return self.request(r)
|
||||||
|
|
||||||
def upsert_global_command(self, application_id, payload):
|
def upsert_global_command(self, application_id, payload) -> Response[interactions.ApplicationCommand]:
|
||||||
r = Route('POST', '/applications/{application_id}/commands', application_id=application_id)
|
r = Route('POST', '/applications/{application_id}/commands', application_id=application_id)
|
||||||
return self.request(r, json=payload)
|
return self.request(r, json=payload)
|
||||||
|
|
||||||
def edit_global_command(self, application_id, command_id, payload):
|
def edit_global_command(self, application_id, command_id, payload) -> Response[interactions.ApplicationCommand]:
|
||||||
valid_keys = (
|
valid_keys = (
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
@ -1079,13 +1090,13 @@ class HTTPClient:
|
|||||||
)
|
)
|
||||||
return self.request(r)
|
return self.request(r)
|
||||||
|
|
||||||
def bulk_upsert_global_commands(self, application_id, payload):
|
def bulk_upsert_global_commands(self, application_id, payload) -> Response[List[interactions.ApplicationCommand]]:
|
||||||
r = Route('PUT', '/applications/{application_id}/commands', application_id=application_id)
|
r = Route('PUT', '/applications/{application_id}/commands', application_id=application_id)
|
||||||
return self.request(r, json=payload)
|
return self.request(r, json=payload)
|
||||||
|
|
||||||
# Application commands (guild)
|
# Application commands (guild)
|
||||||
|
|
||||||
def get_guild_commands(self, application_id, guild_id):
|
def get_guild_commands(self, application_id, guild_id) -> Response[List[interactions.ApplicationCommand]]:
|
||||||
r = Route(
|
r = Route(
|
||||||
'GET',
|
'GET',
|
||||||
'/applications/{application_id}/{guild_id}/commands',
|
'/applications/{application_id}/{guild_id}/commands',
|
||||||
@ -1094,7 +1105,7 @@ class HTTPClient:
|
|||||||
)
|
)
|
||||||
return self.request(r)
|
return self.request(r)
|
||||||
|
|
||||||
def get_guild_command(self, application_id, guild_id, command_id):
|
def get_guild_command(self, application_id, guild_id, command_id) -> Response[interactions.ApplicationCommand]:
|
||||||
r = Route(
|
r = Route(
|
||||||
'GET',
|
'GET',
|
||||||
'/applications/{application_id}/{guild_id}/commands/{command_id}',
|
'/applications/{application_id}/{guild_id}/commands/{command_id}',
|
||||||
@ -1104,7 +1115,7 @@ class HTTPClient:
|
|||||||
)
|
)
|
||||||
return self.request(r)
|
return self.request(r)
|
||||||
|
|
||||||
def upsert_guild_command(self, application_id, guild_id, payload):
|
def upsert_guild_command(self, application_id, guild_id, payload) -> Response[interactions.ApplicationCommand]:
|
||||||
r = Route(
|
r = Route(
|
||||||
'POST',
|
'POST',
|
||||||
'/applications/{application_id}/{guild_id}/commands',
|
'/applications/{application_id}/{guild_id}/commands',
|
||||||
@ -1113,7 +1124,7 @@ class HTTPClient:
|
|||||||
)
|
)
|
||||||
return self.request(r, json=payload)
|
return self.request(r, json=payload)
|
||||||
|
|
||||||
def edit_guild_command(self, application_id, guild_id, command_id, payload):
|
def edit_guild_command(self, application_id, guild_id, command_id, payload) -> Response[interactions.ApplicationCommand]:
|
||||||
valid_keys = (
|
valid_keys = (
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
@ -1139,7 +1150,9 @@ class HTTPClient:
|
|||||||
)
|
)
|
||||||
return self.request(r)
|
return self.request(r)
|
||||||
|
|
||||||
def bulk_upsert_guild_commands(self, application_id, guild_id, payload):
|
def bulk_upsert_guild_commands(
|
||||||
|
self, application_id, guild_id, payload
|
||||||
|
) -> Response[List[interactions.ApplicationCommand]]:
|
||||||
r = Route(
|
r = Route(
|
||||||
'PUT',
|
'PUT',
|
||||||
'/applications/{application_id}/{guild_id}/commands',
|
'/applications/{application_id}/{guild_id}/commands',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user