Skip to content

Commit

Permalink
update guild count stat
Browse files Browse the repository at this point in the history
  • Loading branch information
AiroPi committed Dec 17, 2023
1 parent d4ab0c9 commit 0ee9d8e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/cogs/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
from typing import TYPE_CHECKING

import discord
from discord import app_commands
from discord.app_commands import locale_str as __
from discord.utils import get
Expand All @@ -22,6 +23,22 @@ class Stats(ExtendedCog):
def __init__(self, bot: MyBot):
super().__init__(bot)

@ExtendedCog.listener()
async def on_guild_join(self, guild: discord.Guild):
# TODO: send a message in the 'bot add' channel
async with self.bot.async_session.begin() as session:
await self.bot.get_or_create_db(session, db.GuildDB, guild_id=guild.id)
await self.update_guild_count()

@ExtendedCog.listener()
async def on_guild_remove(self, guild: discord.Guild):
# TODO: send a message in the 'bot add' channel
await self.update_guild_count()

async def update_guild_count(self):
async with self.bot.async_session.begin() as session:
session.add(db.TSGuildCount(value=len(self.bot.guilds)))

@ExtendedCog.listener()
async def on_interaction(self, inter: Interaction) -> None:
if inter.command is None:
Expand Down

0 comments on commit 0ee9d8e

Please sign in to comment.