Client#
The Client class is the core of this library that brings together everything needed
for building complex Revolt bots. It provides all the machinery in form a rich interface that
can be used to interact with Revolt API.
Client#
- class luster.Client(token: str, bot: bool = True, session: Optional[ClientSession] = None, http_handler_cls: Type[HTTPHandler] = <class 'luster.http.HTTPHandler'>, websocket_handler_cls: Type[WebsocketHandler] = <class 'luster.websocket.WebsocketHandler'>, cache_cls: Type[Cache] = <class 'luster.cache.Cache'>)#
A client that interacts with Revolt API.
This class provides a user friendly interface for interacting with Revolt Events and HTTP API. This class mainly focuses on automating user accounts or creating bots. If you intend to perform simple HTTP requests, Use
HTTPHandlerinstead.- Parameters
token (
str) – The bot or session token.bot (
bool) – Whether the passedtokenis a bot token. Set this toFalsewhen a session token is passed (i.e for a user). Defaults toTrue.session (Optional[
aiohttp.ClientSession]) –The client session used for making HTTP requests.
If not provided, A session is created internally and would be closed automatically after usage. Note that when a session is provided by the user, It must be closed by the user. Library will not take it’s ownership.
http_handler_cls (Type[
HTTPHandler]) – The class type ofHTTPHandler. This can be used to set custom subclasses onhttp_handler.websocket_handler_cls (Type[
WebsocketHandler]) – The class type ofWebsocketHandler. This can be used to set custom subclasses onwebsocket_handler.cache_cls (Type[
Cache]) – The class type ofCache. This can be used to set custom subclasses oncache.
- user#
The user for the connected client. This is only set after connection with Revolt API has been made.
- Type
Optional[
User]
- property cache: luster.cache.Cache#
The cache handler associated to this client.
- Returns
- Return type
- async change_username(username: str, password: str) luster.users.User#
Changes the username of current user.
Note
This can only be used by non-bot accounts.
- async close_hook() None#
A hook that gets called when client has fully closed.
closedproperty will always returnTruein this hook.You can use this hook to perform extra clean up on client closure such as closing database connections etc.
- property closed: bool#
Whether the client’s websocket connection is currently closed.
- Returns
- Return type
- async create_group(name: str, recipients: List[BaseModel] = ..., description: str = ..., nsfw: bool = ...) Group#
Creates a new group.
- async create_server(*, name: str, description: str = ..., nsfw: bool = ...) luster.server.Server#
Creates a server.
- async fetch_channel(channel_id: str) ChannelT#
Fetches a channel.
- Parameters
channel_id (
str) – The ID of channel to fetch.- Returns
The fetched channel.
- Return type
Union[
ServerChannel,PrivateChannel]- Raises
HTTPException – The fetching failed.
HTTPNotFound – Invalid channel ID.
- async fetch_dms() List[Union[DirectMessage, Group]]#
Fetches the direct messages and groups that are currently opened.
- Returns
The current direct message channels.
- Return type
List[Union[
DirectMessage,Group]]- Raises
HTTPException – The fetching failed.
- async fetch_self() luster.users.User#
Fetches the user for current client.
- Returns
The user for current client.
- Return type
- Raises
HTTPException – Fetching the user failed.
- async fetch_server(server_id: str) luster.server.Server#
Fetches a server via it’s ID.
- async fetch_user(user_id: str) luster.users.User#
Fetches the user by their ID.
- property http_handler: luster.http.HTTPHandler#
The HTTP handler associated to this client.
- Returns
- Return type
- property latency: float#
The websocket latency.
A shorthand for
WebsocketHandler.latency.- Returns
- Return type
- launch() None#
Launches the bot.
This is a high level of
connect()that handles asyncio event loop cleanup and provides a synchronous way of starting the client.Consider using
connect()if you intend to have more control over the event loop.
- listen(event: str) Callable[[Callable[[luster.internal.events_handler.BE], Any]], Callable[[luster.internal.events_handler.BE], Any]]#
A decorator for registering an event listener.
- Parameters
event (
str) – The event to listen to.
- property state: luster.state.State#
The state associated to this client.
- Returns
- Return type
- async upload_file(file: BufferedReader, tag: types.FileTag) PartialUploadedFile#
Uploads a file to Autumn file server.
- Parameters
file (
io.BufferedReader) – The file buffer to upload.tag (
types.FileTag) – The tag or bucket to upload this file to.
- Returns
The uploaded file.
- Return type
- property user: Optional[luster.users.User]#
The user for the connected client.
This is only set after connection with Revolt API has been made.
- Returns
- Return type
Optional[
User]
- property websocket_handler: luster.websocket.WebsocketHandler#
The websocket handler associated to this client.
- Returns
- Return type