mirror of
https://github.com/stoatchat/python-client-sdk.git
synced 2026-07-22 10:35:25 -04:00
initial user support
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
# Revolt.py
|
||||
|
||||
An async library to interact with the https://revolt.chat API. This library will **only support bots** and I will **not** implement anything exclusively for user accounts.
|
||||
An async library to interact with the https://revolt.chat API.
|
||||
|
||||
You can join the support server [here](https://rvlt.gg/FDXER6hr) and find the library's documentation [here](https://revoltpy.readthedocs.io/en/latest/).
|
||||
You can join the support server [here](https://rvlt.gg/FDXER6hr) and find the library's documentation [here](https://revoltpy.readthedocs.io/en/latest/).
|
||||
|
||||
## Installing
|
||||
|
||||
|
||||
+7
-6
@@ -32,7 +32,7 @@ logger = logging.getLogger("revolt")
|
||||
|
||||
class Client:
|
||||
"""The client for interacting with revolt
|
||||
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
session: :class:`aiohttp.ClientSession`
|
||||
@@ -44,13 +44,14 @@ class Client:
|
||||
max_messages: :class:`int`
|
||||
The max amount of messages stored in the cache, by default this is 5k
|
||||
"""
|
||||
|
||||
def __init__(self, session: aiohttp.ClientSession, token: str, api_url: str = "https://api.revolt.chat", max_messages: int = 5000):
|
||||
|
||||
def __init__(self, session: aiohttp.ClientSession, token: str, *, api_url: str = "https://api.revolt.chat", max_messages: int = 5000, bot: bool = True):
|
||||
self.session = session
|
||||
self.token = token
|
||||
self.api_url = api_url
|
||||
self.max_messages = max_messages
|
||||
|
||||
self.bot = bot
|
||||
|
||||
self.api_info: ApiInfo
|
||||
self.http: HttpClient
|
||||
self.state: State
|
||||
@@ -62,7 +63,7 @@ class Client:
|
||||
|
||||
def dispatch(self, event: str, *args: Any):
|
||||
"""Dispatch an event, this is typically used for testing and internals.
|
||||
|
||||
|
||||
Parameters
|
||||
----------
|
||||
event: class:`str`
|
||||
@@ -90,7 +91,7 @@ class Client:
|
||||
api_info = await self.get_api_info()
|
||||
|
||||
self.api_info = api_info
|
||||
self.http = HttpClient(self.session, self.token, self.api_url, self.api_info)
|
||||
self.http = HttpClient(self.session, self.token, self.api_url, self.api_info, self.bot)
|
||||
self.state = State(self.http, api_info, self.max_messages)
|
||||
self.websocket = WebsocketHandler(self.session, self.token, api_info["ws"], self.dispatch, self.state)
|
||||
await self.websocket.start()
|
||||
|
||||
+4
-3
@@ -38,13 +38,14 @@ T = TypeVar("T")
|
||||
Request = Coroutine[Any, Any, T]
|
||||
|
||||
class HttpClient:
|
||||
__slots__ = ("session", "token", "api_url", "api_info")
|
||||
__slots__ = ("session", "token", "api_url", "api_info", "auth_header")
|
||||
|
||||
def __init__(self, session: aiohttp.ClientSession, token: str, api_url: str, api_info: ApiInfo):
|
||||
def __init__(self, session: aiohttp.ClientSession, token: str, api_url: str, api_info: ApiInfo, bot: bool = True):
|
||||
self.session = session
|
||||
self.token = token
|
||||
self.api_url = api_url
|
||||
self.api_info = api_info
|
||||
self.auth_header = "x-bot-token" if bot else "x-session-token"
|
||||
|
||||
async def request(self, method: Literal["GET", "POST", "PUT", "DELETE", "PATCH"], route: str, *, json: Optional[dict[str, Any]] = None, nonce: bool = True, params: Optional[dict[str, Any]] = None) -> Any:
|
||||
url = f"{self.api_url}{route}"
|
||||
@@ -53,7 +54,7 @@ class HttpClient:
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Revolt.py (https://github.com/revoltchat/revolt.py)",
|
||||
"x-bot-token": self.token
|
||||
self.auth_header: self.token
|
||||
}
|
||||
|
||||
if json:
|
||||
|
||||
Reference in New Issue
Block a user