Skip to content

Commit

Permalink
Post stats to dbl and update presence
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinfuchs committed Nov 27, 2018
1 parent 582642c commit 6ab191e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
40 changes: 40 additions & 0 deletions cogs/stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import discord
import asyncio
import traceback


class Stats:
def __init__(self, bot):
self.bot = bot
self.bot.loop.create_task(self.update_loop())

async def update_discordbots_org(self):
async with self.bot.session.post(
url=f"https://discordbots.org/api/bots/{self.bot.user.id}/stats",
headers={
"Authorization": self.bot.config.dbl_token
},
json={
"server_count": len(self.bot.guilds),
"shard_count": self.bot.shard_count
}
) as resp:
if resp.status != 200:
self.bot.log.error(resp)

async def update_loop(self):
while True:
await asyncio.sleep(60)
if not self.bot.config.self_host:
await self.bot.change_presence(activity=discord.Activity(
name=f"{len(self.bot.guilds)} Servers | {self.bot.config.prefix}help",
type=discord.ActivityType.watching
), afk=False)
try:
await self.update_discordbots_org()
except:
traceback.print_exc()


def setup(bot):
bot.add_cog(Stats(bot))
10 changes: 9 additions & 1 deletion example_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
"cogs.admin",
"cogs.backups",
"cogs.templates",
"cogs.pro"
"cogs.pro",
"cogs.blacklist",
"cogs.basics",
"cogs.stats"
]

support_guild = 410488579140354049

self_host = True
# The options below are not required if "self_host" is enabled

dbl_token = ""

0 comments on commit 6ab191e

Please sign in to comment.