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 HTTPHandler instead.

Parameters
  • token (str) – The bot or session token.

  • bot (bool) – Whether the passed token is a bot token. Set this to False when a session token is passed (i.e for a user). Defaults to True.

  • 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 of HTTPHandler. This can be used to set custom subclasses on http_handler.

  • websocket_handler_cls (Type[WebsocketHandler]) – The class type of WebsocketHandler. This can be used to set custom subclasses on websocket_handler.

  • cache_cls (Type[Cache]) – The class type of Cache. This can be used to set custom subclasses on cache.

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

Cache

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.

Parameters
  • username (str) – The new username.

  • password (str) – The current account password.

Returns

The updated user.

Return type

User

Raises
  • HTTPException – The request failed.

  • HTTPForbidden – The credentials are incorrect.

async close_hook() None#

A hook that gets called when client has fully closed.

closed property will always return True in 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

bool

async connect() None#

Connects the client to Revolt websocket.

async create_group(name: str, recipients: List[BaseModel] = ..., description: str = ..., nsfw: bool = ...) Group#

Creates a new group.

Parameters
  • name (str) – The name of group.

  • recipients (List[BaseModel]) – The recipients to add to group.

  • description (str) – The description of group.

  • nsfw (bool) – Whether this group is NSFW.

Returns

The created group.

Return type

Group

Raises

HTTPException – Creation of group failed.

async create_server(*, name: str, description: str = ..., nsfw: bool = ...) luster.server.Server#

Creates a server.

Parameters
  • name (str) – The name of server.

  • description (str) – The description of server.

  • nsfw (bool) – Whether this server is NSFW.

Returns

The created server.

Return type

Server

Raises

HTTPException – Creation of server failed.

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

User

Raises

HTTPException – Fetching the user failed.

async fetch_server(server_id: str) luster.server.Server#

Fetches a server via it’s ID.

Parameters

channel_id (str) – The ID of channel to fetch.

Returns

The requested server.

Return type

Server

Raises
  • HTTPNotFound – The server does not exist.

  • HTTPException – Fetching of server failed.

async fetch_user(user_id: str) luster.users.User#

Fetches the user by their ID.

Parameters

user_id (str) – The ID of user.

Returns

The requested user.

Return type

User

Raises
  • HTTPNotFound – User does not exist.

  • HTTPException – The request failed.

property http_handler: luster.http.HTTPHandler#

The HTTP handler associated to this client.

Returns

Return type

HTTPHandler

property latency: float#

The websocket latency.

A shorthand for WebsocketHandler.latency.

Returns

Return type

float

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

State

async upload_file(file: BufferedReader, tag: types.FileTag) PartialUploadedFile#

Uploads a file to Autumn file server.

Parameters
Returns

The uploaded file.

Return type

PartialUploadedFile

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

WebsocketHandler