Reference¶
This explains how to use unionchat
Client¶
-
class
unionchat.Client(username, password, **)¶
Instances a client to connect to Union. You can pass some options to Client.
Parameters
- loop(Optional) - Pass an asyncio event loop
- cache_size(Optional[int]) - The maximum number of messages to store in the message cache. This defaults to 500. Anything lower than 100 will use the default value.
-
user¶
Object[SelfUser] - Simple user that contains password and username
-
ready¶
Bool: Indicates whether client has finished connecting or not.
-
loop¶
The event loop for the websocket and HTTP requests
-
servers¶
Dict[Server] - The servers that the client can see.
-
api¶
An instance of aiohttp ClientSession
-
start()¶
Blocking call that runs the event loop so you don’t have to create it yourself.
This function must always be called last.
-
coroutine create_message(server, content)
This function is a coroutine
Sends a message to a Union server
-
coroutine send_message(server, content)
This function is a coroutine
This is an alias of create_message(server, content)
-
coroutine delete_message(id)
Deletes a message
You cannot delete messages send by others
-
get_message(id)¶
Returns a Message
-
get_member_info(id)¶
Returns a Member
Union Objects¶
Member¶
-
class
unionchat.Member¶
Represents a Union member. You normally don’t have to create one of these yourself. Members don’t have ID’s, their names are used internally.
-
avatar_url¶
str - Returns the avatar url of the member
-
created_at¶
timestamp - Returns the creation data of the member
-
status¶
bool - Indicates whether a member is online or offline
-
str(member)¶
Returns the member’s name
-
mention()¶
str - Returns a preformatted mention
Message¶
-
class
unionchat.Message¶
Represents a Union message. You normally don’t have to create one of these yourself.
-
client
The client used, you usually don’t use this.
-
server¶
int - The server the message originates from.
Object[Member] - Returns a member of the message author.
-
content¶
str - Returns the message content.
-
id¶
str - Returns the message id
-
created_at
int - Unix timestamp from when the message was created
-
self¶
Object[Member] - Only available when the client sent the message
-
str(Message)
str - Returns message content
-
coroutine reply(content)
Replies to a message
Returns Message of the message that was sent
-
coroutine send(content)
Alias of reply(content)
Deletes the message.
You cannot delete messages sent by others
Server¶
-
class
unionchat.Server¶
Represents a Union server
-
name¶
str - Returns the server name
-
id
int - Returns the server ID
-
messages¶
list - Returns the messages in the server by id
-
icon_url¶
str - Returns the server’s icon url
-
members¶
dict - Returns the members in the server
-
get_member(id)¶
Get a member by ID
Exceptions¶
-
exception
CannotDeleteOtherMessages¶
Raised when you attempt to delete a message that was not send by you
-
exception
UsernameMustExist¶
Raised when you do not include a username when creating a Client.
-
exception
PasswordMustExist¶
Raised when you do not include a password when creating a Client.
-
exception
NotReadyYet¶
Raised when the client has not connected yet