add code to update stats
+from discord.ext import commands
from aiohttp import web
import classyjson as cj
import aiohttp
@@ -16,6 +17,30 @@ class BotLists(commands.Cog):
self.bot.loop.create_task(webhooks_setup())
+ self.bot.loop.create_task(update_stats())
+
+ async def update_stats(self):
+ while True:
+ try:
+ await self.ses.put(
+ 'https://disbots.gg/api/stats',
+ headers={'Authorization': self.d.disbots_auth},
+ json={'servers': str(len(self.bot.guilds))}
+ )
+ except Exception as e:
+ self.bot.logger.error(e)
+
+ try:
+ await self.ses.post(
+ f'https://top.gg/api/bots/{self.bot.user.id}/stats',
+ headers={'Authorization': self.d.topgg_post_auth},
+ json={'server_count': str(len(self.bot.guilds))}
+ )
+ except Exception as e:
+ self.bot.logger.error(e)
+
+ await asyncio.sleep(3600)
+
async def webhooks_setup(self):
async def handler(req):
if req.headers.get('Authorization') == self.d.disbots_auth:
