<commit_before>import logging

from discord.ext import commands

from .common import Cog

BOT_RATIO_MAX = 1.1

WHITELIST = (295341979800436736, 319540379495956490)

log = logging.getLogger(__name__)

class BotCollection(Cog):
    """Bot collection commands."""
    def bot_human_ratio(self, guild):
        bots = [member for member in guild.members if member.bot]
        humans = [member for member in guild.members if not member.bot]

        return bots, humans, (len(bots) / len(humans))

    def bhratio_global(self):
        all_members = self.bot.get_all_members

        bots = [member for member in all_members() if member.bot]
        humans = [member for member in all_members() if not member.bot]

        return bots, humans, (len(bots) / len(humans))

    async def on_guild_join(self, guild):
        bots, humans, ratio = self.bot_human_ratio(guild)

        log.info(f'[bh] {guild!s} -> ratio {len(bots)} / {len(humans)} = {ratio:.2}')

        if guild.id in WHITELIST:
            return

        if ratio > BOT_RATIO_MAX:
            log.info(f'[bh] leaving {guild!s}')
            await guild.leave()

    async def on_member_join(self, member):
        guild = member.guild

        bots, humans, ratio = self.bot_human_ratio(guild)

        if guild.id in WHITELIST:
            return

        if ratio > BOT_RATIO_MAX:
            log.info('[bh:member_join] leaving')
            await guild.leave()

    @commands.command()
    @commands.guild_only()
    async def bhratio(self, ctx):
        """Get your guild's bot-to-human ratio"""

        bots, humans, ratio = self.bot_human_ratio(ctx.guild)
        _, _, global_ratio = self.bhratio_global()

        await ctx.send(f'{len(bots)} bots / {len(humans)} humans => `{ratio:.2}b/h`, global is `{global_ratio:.2}`')<commit_msg>botcollection: add guilds to the whitelist and add better log<commit_after>import logging

from discord.ext import commands

from .common import Cog

BOT_RATIO_MAX = 1.1

WHITELIST = (
    273863625590964224, # José's server
    295341979800436736, # Memework
    319540379495956490, # le tru meme lounge
    297710090687873024, # Luma's testing server
)

log = logging.getLogger(__name__)

class BotCollection(Cog):
    """Bot collection commands."""
    def bot_human_ratio(self, guild):
        bots = [member for member in guild.members if member.bot]
        humans = [member for member in guild.members if not member.bot]

        return bots, humans, (len(bots) / len(humans))

    def bhratio_global(self):
        all_members = self.bot.get_all_members

        bots = [member for member in all_members() if member.bot]
        humans = [member for member in all_members() if not member.bot]

        return bots, humans, (len(bots) / len(humans))

    async def on_guild_join(self, guild):
        bots, humans, ratio = self.bot_human_ratio(guild)

        log.info(f'[bh:join] {guild!s} -> ratio {len(bots)} / {len(humans)} = {ratio:.2}')

        if guild.id in WHITELIST:
            return

        if ratio > BOT_RATIO_MAX:
            log.info(f'[bh:leave] leaving {guild!s}')
            await guild.leave()

    async def on_member_join(self, member):
        guild = member.guild
        bots, humans, ratio = self.bot_human_ratio(guild)

        if guild.id in WHITELIST:
            return

        if ratio > BOT_RATIO_MAX:
            log.info('[bh:leave:member_join] leaving {guild!r} {guild.id}, {len(bots)}/{len(humans)} = {ratio}')
            await guild.leave()

    @commands.command()
    @commands.guild_only()
    async def bhratio(self, ctx):
        """Get your guild's bot-to-human ratio"""

        bots, humans, ratio = self.bot_human_ratio(ctx.guild)
        _, _, global_ratio = self.bhratio_global()

        await ctx.send(f'{len(bots)} bots / {len(humans)} humans => `{ratio:.2}b/h`, global is `{global_ratio:.2}`')
{'fraction_non_alphanumeric': 0.12166709811027698, 'fraction_numerical': 0.030546207610665285, 'mean_word_length': 2.7660818713450293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '4360755', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1301, 'n_words': 320}