Main Classes¶
- class IBLPy.BotClient(bot_id, api_token='')¶
Bases:
object
Initialize a Infinity Bots List (IBL) Bot Client. You can use this to get/post bot stats and fetch a bot!
- Parameters
bot_id (
int
) – The Bot ID you wish to use with the IBL APIapi_token (
Optional
[str
,None
]) – The API Token of the bot. You can find this by clicking API Token under the “Owner Section”. This is optional however you will not be able to post stats if you do not pass a API Token
- async get_bot()¶
Asynchronously get a bot. This does not take any parameters.
- Returns
If the bot was not found or if IBLPy could not parse the JSON request for any reason
- Return type
None
- Returns
This will be returned if you are ratelimited
- Return type
- Returns
This is the bot object returned from the API
- Return type
- async has_user_voted(user_id)¶
This returns whether or not a user has voted
- Returns
This will be returned if you are ratelimited
- Return type
- Returns
Whether or not the user has voted or not
- Return type
bool
- async set_stats(guild_count, shard_count=None)¶
Posts bot stats to the IBL API asynchronously
- Parameters
guild_count (
int
) – Amount of servers your bot is inshard_count (
Optional
[int
,None
]) – Amount of shards your bot is in. This is optional
- Returns
This will always be returned unless something goes wrong, in which case you will get an exception
- Return type
- class IBLPy.UserClient(user_id)¶
Bases:
object
Initialize a Infinity Bots List (IBL) User Client. You can use this to get user stats!
- Parameters
user_id (
int
) – The User ID you wish to use with the IBL API
- async get_user()¶
Get a user. This does not take any parameters.
- Returns
If the user was not found or if IBLPy could not parse the JSON request for any reason
- Return type
None
- Returns
This will be returned if you are ratelimited
- Return type
- Returns
This is the user object returned from the API
- Return type
- class IBLPy.AutoPoster(interval, botcli, discli, sharding=None, on_post=None, get_counts=<function _default_get_counts>)¶
Bases:
object
- This is IBL Auto Poster. It will post stats for you on an interval you decide
and it will then run a function of your choice (if requested) after posting each time.
You can stop a Auto Poster by calling the
stop
function.- Parameters
get_counts (
Awaitable
) – A async function that takes in the AutoPoster object and then returns the dict {“guild_count: guild count, “shard_count”: shard_count} for the autoposter. A default value for this is provided for ease of useinterval (
int
) – How long to wait each time you post. It is required to use at least 5 minutes which is 300 seconds. Specifying a value below 300 seconds will set the interval to 300 seconds anywaysbotcli (
BotClient
) – The IBL BotClient of the bot you want to post stats for. It must have the API token set either during initialization or afterwards by setting the api_token parameterdiscli (
Client
) – The discord.Client (or like interfaces like discord.Bot/discord.AutoShardedBot) of the bot you want to post stats for. If you wish to add shard counts, please give a discord.AutoShardedClient and pass sharding = True or use get_countson_post – The function to call after posting. Set to None if you don’t want this. This function needs to accept three arguments, the guild count sent, the shard count set and the response (which will either be a IBLAPIResponse, a IBLAPIRatelimit or None). Shard count will be None if sharding is disabled and/or get_count provided doesn’t support it
sharding – Whether we should post sharding as well. Requires a discord.AutoShardedClient
- async autoposter()¶
This is the autoposting function that is run by the
start
function here (using asyncio.create_task)
- start()¶
Starts the auto poster using asyncio.create_task and returns the created task. This must be done in the on_ready function in discord.py
- stop()¶
Stops the auto poster by setting the
keep_running
attribute to False. Since the exact name may change, it is recommended to usestop
instead of manually setting the attribute.The autoposter will only stopped after the interval specified
This will return the autoposter asyncio task
- class IBLPy.Webhook(botcli, coro, secret=None)¶
Bases:
object
This is an IBLPy webhook. It takes a BotClient, your webhook secret and the awaitable/asyncio corouting to call after getting a vote. To start your webhook:
Use start_ws_task if you are running this in discord.py. make sure you start the webhook in your on_ready event (at the very end of it since it’s blocking)
Use start_ws_normal if you are running this seperately from discord.py. It will be run using asyncio.run instead of asyncio.create_task
Use the start_ws coroutine if you want to run the webhook yourself using asyncio
Use create_app if you want to get the FastAPI ASGI app and deploy the webhook using your own server. Uvicorn still needs to be installed even if you use a different ASGI server
- create_app(route)¶
Creates a FastAPI ASGI app and returns it so you can deploy it how you want to deploy it
- async start_ws(route, port=8012)¶
Coroutine to start webhook using any asyncio method you want.
- start_ws_normal(route, port=8012)¶
Start webhook using asyncio.run for normal non-discord.py usecases
- start_ws_task(route, port=8012)¶
Start webhook using asyncio.create_task (discord.py). Use this in a discord.py on_ready event (at the very end of it since it’s blocking).