Client
Contents
Client#
UnbeliClient#
- class unbelipy.UnbeliClient(token, *, prevent_rate_limits=True, retry_rate_limits=False, session=None)#
The client to interact with UnbelievaBoat’s API.
- Parameters
token (
str
) – The Authorization token which will be used when requesting data.prevent_rate_limits (Optional[
bool
]) – Whether the client will sleep through ratelimits to prevent 429 errors. This defaults toTrue
.retry_rate_limits (Optional[
bool
]) – Whether the client will sleep and retry after 429 errors. This defaults toFalse
.session (Optional[
aiohttp.ClientSession
]) – An open ClientSession which will be used throughout to request with. If this isNone
, a new ClientSession will be opened.
- Return type
None
- rate_limits#
Dictionary containing information on the rate limit status of the client in the API.
Key name
Description
X-RateLimit-Limit
The number of requests that can be made.
X-RateLimit-Remaining
The number of remaining requests that can be made.
X-RateLimit-Reset
Datetime to when the rate limit resets.
retry_after
The number of seconds to wait before being able to make another request.
- Type
ClientRateLimits
- async close_session()#
Closes the current session.
- Return type
None
- async edit_user_balance(guild_id, user_id, cash=None, bank=None, reason=None)#
Increase or decrease the user’s balance by a value given in the params. To decrease the balance, provide a negative number.
- Parameters
guild_id (
int
) – The guild’s ID which the user belongs to.user_id (
int
) – The user’s ID.cash (Optional[Union[
int
,str
]]) – Amount to modify the user’s cash amount to. If this is astr
, it must be set to “Infinity”.bank (Optional[Union[
int
,str
]]) – Amount to modify the user’s bank amount to. If this is astr
, it must be set to “Infinity”.reason (Optional[
str
]) – The reason to why the balance was modified.
- Raises
Unauthorized – The wrong Application Token was passed.
Forbidden – The Application is not authorized to perform this action.
NotFound – You provided an invalid guild, and/or user ID.
- Returns
A dataclass containing information on the user’s newly modified balance.
- Return type
- async generate_new_session(session=None)#
Generates a new
ClientSession
for the client.:param session Optional[
ClientSession
]: The session to use with the client.- Parameters
session (Optional[aiohttp.client.ClientSession]) –
- async get_guild(guild_id)#
Retrieves a guild from the API.
- async get_guild_leaderboard(guild_id, sort=None, limit=None, offset=1, page=None)#
Retrieves the leaderboard for a guild.
- Parameters
guild_id (
int
) – The target guild’s ID.sort (
str
) – Sort the leaderboard by “cash”, “bank” or “total”.limit (
int
) – Limit the amount of users to retrieve.offset (
int
) – retrieve users only from said place and below in the leaderboardpage (
int
) – page number to retrieve if specified returns a dictionary containing the list of user’s leaderboard under key ‘users’ and additional ‘page’ with the current page and ‘total_pages’ with number available pages.
- Raises
TypeError – You specified both
offset
andpage
.ValueError – You specified something other than “cash”, “bank” or “total” for
sort
.Unauthorized – The wrong Application Token was passed.
NotFound – You provided an invalid guild ID.
Returns: – Union[List[
UserBalance
], [Dict[str
, Union[int
, List[Userbalance
]]]]] Dictionary containing leaderboard information.
- Return type
Union[List[unbelipy.objects.UserBalance], Dict[str, Union[int, List[unbelipy.objects.UserBalance]]]]
- async get_permissions(guild_id)#
Returns the application’s permissions for the specified guild’s ID.
- async get_user_balance(guild_id, user_id)#
Retrieves a user’s balance.
- Parameters
- Raises
Unauthorized – The wrong Application Token was passed.
NotFound – You provided an invalid guild, and/or user ID.
- Returns
A dataclass containing information on the retrieved user’s balance.
- Return type
- async set_user_balance(guild_id, user_id, cash=None, bank=None, reason=None)#
Sets a user’s balance to a given amount. At least one of cash, or bank must be specified.
- Parameters
guild_id (
int
) – The guild’s ID which the user belongs to.user_id (
int
) – The user’s ID.cash (Optional[Union[
int
,str
]]) – Amount to set the user’s cash amount to. If this is astr
, it must be set to “Infinity”.bank (Optional[Union[
int
,str
]]) – Amount to set the user’s bank amount to. If this is astr
, it must be set to “Infinity”.reason (Optional[
str
]) – The reason to why the balance was mofified.
- Raises
Unauthorized – The wrong Application Token was passed.
Forbidden – The Application is not authorized to perform this action.
NotFound – You provided an invalid guild, and/or user ID.
- Returns
A dataclass containing information on the user’s newly modified balance.
- Return type