<commit_before>import logging

import discord.ext.commands as commands

import paths
from .util import config, utils

log = logging.getLogger(__name__)


def setup(bot):
    bot.add_cog(Prefix(bot))


class PrefixesConfig(config.ConfigElement):
    def __init__(self, global_, **kwargs):
        self.global_ = global_
        self.guild_specific = utils.dict_keys_to_int(kwargs.get('guild_specific', {}))


class Prefix:
    """Custom prefixes per server."""
    def __init__(self, bot):
        self.bot = bot
        self.conf = config.Config(paths.PREFIXES_CONFIG, encoding='utf-8')
        self.saved_prefixes = self.bot.command_prefix
        self.bot.command_prefix = self.get_prefixes

    def __unload(self):
        self.bot.command_prefix = self.saved_prefixes

    def get_prefixes(self, bot, message):
        if message.guild is not None:
            prefixes = self.conf.guild_specific.get(message.guild.id, []) + self.conf.global_
        else:
            prefixes = self.conf.global_

        if 'mention' in prefixes:
            prefixes[prefixes.index('mention')] = f'{bot.user.mention} '

        return prefixes

    async def on_guild_remove(self, guild):
        if guild.id in self.conf.guild_specific:
            del self.conf.guild_specific[guild.id]
<commit_msg>Fix mention as a prefix with nicknames.<commit_after>import logging

import discord.ext.commands as commands

import paths
from .util import config, utils

log = logging.getLogger(__name__)


def setup(bot):
    bot.add_cog(Prefix(bot))


class PrefixesConfig(config.ConfigElement):
    def __init__(self, global_, **kwargs):
        self.global_ = global_
        self.guild_specific = utils.dict_keys_to_int(kwargs.get('guild_specific', {}))


class Prefix:
    """Custom prefixes per server."""
    def __init__(self, bot):
        self.bot = bot
        self.conf = config.Config(paths.PREFIXES_CONFIG, encoding='utf-8')
        self.saved_prefixes = self.bot.command_prefix
        self.bot.command_prefix = self.get_prefixes

    def __unload(self):
        self.bot.command_prefix = self.saved_prefixes

    def get_prefixes(self, bot, message):
        if message.guild is not None:
            prefixes = self.conf.guild_specific.get(message.guild.id, []) + self.conf.global_
        else:
            prefixes = self.conf.global_

        if 'mention' in prefixes:
            prefixes[prefixes.index('mention')] = f'{message.guild.me.mention} '

        return prefixes

    async def on_guild_remove(self, guild):
        if guild.id in self.conf.guild_specific:
            del self.conf.guild_specific[guild.id]

{'fraction_non_alphanumeric': 0.10771581359816654, 'fraction_numerical': 0.0007639419404125286, 'mean_word_length': 2.9383458646616543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6090213', 'n_tokens_mistral': 839, 'n_tokens_neox': 820, 'n_words': 172}