<commit_before>"""
bots.discord.pw reporting for Dogbot.
"""
import asyncio
import logging

from dog import Cog

logger = logging.getLogger(__name__)


class Abalbots(Cog):
    def __init__(self, bot):
        super().__init__(bot)
        self.reporting_interval = 60 * 10
        self.reporting_task = bot.loop.create_task(self.report())

    def __unload(self):
        logger.debug('Cancelling abal bot reporter task.')
        self.reporting_task.cancel()

    async def report(self):
        logger.debug('Abal bot reporter task started.')

        endpoint = f'https://bots.discord.pw/api/bots/{self.bot.user.id}/stats'
        headers = {'Authorization': self.bot.cfg['monitoring']['discordpw_token']}

        while True:
            logger.info('POSTing guild count to abal\'s website...')
            guilds = len(self.bot.guilds)

            # HTTP POST to the endpoint
            async with self.bot.session.post(endpoint, json={'server_count': guilds}, headers=headers) as resp:
                if resp.status != 200:
                    # this happens a lot
                    logger.warning('Failed to post guild count, ignoring. (HTTP %d)', resp.status)
                else:
                    logger.info('Posted guild count successfully! (%d guilds)', guilds)<commit_msg>Abalbots: Wait until ready before reporting<commit_after>"""
bots.discord.pw reporting for Dogbot.
"""
import asyncio
import logging

from dog import Cog

logger = logging.getLogger(__name__)


class Abalbots(Cog):
    def __init__(self, bot):
        super().__init__(bot)
        self.reporting_interval = 60 * 10
        self.reporting_task = bot.loop.create_task(self.report())

    def __unload(self):
        logger.debug('Cancelling abal bot reporter task.')
        self.reporting_task.cancel()

    async def report(self):
        await self.bot.wait_until_ready()
        logger.debug('Abal bot reporter task started.')

        endpoint = f'https://bots.discord.pw/api/bots/{self.bot.user.id}/stats'
        headers = {'Authorization': self.bot.cfg['monitoring']['discordpw_token']}

        while True:
            logger.info('POSTing guild count to abal\'s website...')
            guilds = len(self.bot.guilds)

            # HTTP POST to the endpoint
            async with self.bot.session.post(endpoint, json={'server_count': guilds}, headers=headers) as resp:
                if resp.status != 200:
                    # this happens a lot
                    logger.warning('Failed to post guild count, ignoring. (HTTP %d)', resp.status)
                else:
                    logger.info('Posted guild count successfully! (%d guilds)', guilds)
{'fraction_non_alphanumeric': 0.1183320811419985, 'fraction_numerical': 0.005259203606311044, 'mean_word_length': 2.414102564102564, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3926378', 'n_tokens_mistral': 801, 'n_tokens_neox': 746, 'n_words': 194}