add automatically post_stats method parameters fill

This commit is contained in:
Victor Kotlin 2021-09-28 21:19:09 +03:00
parent 8cd4555f18
commit fd59896df9
2 changed files with 9 additions and 6 deletions

View file

@ -84,12 +84,8 @@ class BoticordClient:
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.post_stats(data_to_send)
await self.Bots.post_stats()
if sleep_time is None:
sleep_time = 900

View file

@ -1,3 +1,4 @@
from discord.ext import commands
import asyncio
import aiohttp
@ -59,7 +60,7 @@ class Bots:
raise status(resp)
return data
async def post_stats(self, stats: dict):
async def post_stats(self, stats: dict = None):
"""
Post stats to Boticord API.
@ -73,6 +74,12 @@ class Bots:
headers = {"Authorization": self.token}
if stats is None:
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
async with self.session.post(f'{Config.general_api}/stats', headers=headers, json=stats) as resp:
data = await _json_or_text(resp)
status = Config.http_exceptions.get(resp.status)