mirror of
https://github.com/boticord/boticordpy.git
synced 2024-11-11 19:07:29 +03:00
add boticord-loop
This commit is contained in:
parent
1076ffed5b
commit
d618cbdcba
1 changed files with 33 additions and 1 deletions
|
@ -31,7 +31,8 @@ class BoticordClient:
|
|||
__slots__ = (
|
||||
"Bots",
|
||||
"Servers",
|
||||
"Users"
|
||||
"Users",
|
||||
"bot"
|
||||
)
|
||||
|
||||
bot: Union[commands.Bot, commands.AutoShardedBot]
|
||||
|
@ -39,6 +40,37 @@ class BoticordClient:
|
|||
def __init__(self, bot, token=None, **kwargs):
|
||||
loop = kwargs.get('loop') or asyncio.get_event_loop()
|
||||
session = kwargs.get('session') or aiohttp.ClientSession(loop=loop)
|
||||
self.bot = bot
|
||||
self.Bots = Bots(bot, token=token, loop=loop, session=session)
|
||||
self.Servers = Servers(bot, token=token, loop=loop, session=session)
|
||||
self.Users = Users(token=token, loop=loop, session=session)
|
||||
|
||||
def start_loop(self, sleep_time: int = None) -> None:
|
||||
"""
|
||||
|
||||
Parameters
|
||||
----------
|
||||
sleep_time: :class:`int`
|
||||
loop sleep time - can be unfilled or None
|
||||
|
||||
"""
|
||||
self.bot.loop.create_task(self.__loop(sleep_time=sleep_time))
|
||||
|
||||
async def __loop(self, sleep_time: int = None) -> None:
|
||||
"""
|
||||
The internal loop used for automatically posting stats
|
||||
"""
|
||||
await self.bot.wait_until_ready()
|
||||
|
||||
while not self.bot.is_closed():
|
||||
data_to_send = {"servers": len(self.bot.guilds), "users": len(self.bot.users)}
|
||||
|
||||
if isinstance(self.bot, commands.AutoShardedBot):
|
||||
data_to_send["shards"] = self.bot.shard_count
|
||||
|
||||
await self.Bots.postStats(data_to_send)
|
||||
|
||||
if sleep_time is None:
|
||||
sleep_time = 900
|
||||
|
||||
await asyncio.sleep(sleep_time)
|
||||
|
|
Loading…
Reference in a new issue