<commit_before>"""
Main bot class.
"""
import asyncio
import os
import sys
import traceback
from collections import OrderedDict
import time
import random

import discord
import logbook
import logging

from discord.ext.commands import Bot, CommandInvokeError, CheckFailure, MissingRequiredArgument
from logbook.compat import redirect_logging
from logbook import StreamHandler
from rethinkdb import ReqlDriverError

from joku.redis import RedisAdapter
from joku.rethink import RethinkAdapter
from joku import threadmanager

try:
    import yaml
except ImportError:
    import ruamel.yaml as yaml

redirect_logging()

StreamHandler(sys.stderr).push_application()


class Jokusoramame(Bot):
    def __init__(self, config: dict, *args, **kwargs):
        # Get the shard ID.
        shard_id = kwargs.get("shard_id", 0)

        self.manager = kwargs.get("manager")  # type: threadmanager.Manager

        self.config = config

        # Logging stuff
        self.logger = logbook.Logger("Jokusoramame:Shard-{}".format(shard_id))
        self.logger.level = logbook.INFO

        logging.root.setLevel(logging.INFO)

        # Call init.
        super().__init__(command_prefix=self.get_command_prefix, *args, **kwargs)

        self.app_id = ""
        self.owner_id = ""

        self.startup_time = time.time()

        self.rethinkdb = RethinkAdapter(self)

        self.redis = RedisAdapter(self)

        # Re-assign commands and extensions.
        self.commands = OrderedDict()
        self.extensions = OrderedDict()
        self.cogs = OrderedDict()

        self._rotator_task = None  # type: asyncio.Task
        self._avatar_rotator = None  # type: asyncio.Task

    def __del__(self):
        self.loop.set_exception_handler(lambda *args, **kwargs: None)

    # Utility functions.
    def get_member(self, id: str):
        """
        Gets a member from all members.
        """
        return discord.utils.get(self.get_all_members(), id=id)

    @staticmethod
    async def get_command_prefix(self: 'Jokusoramame', message: discord.Message):
        return "j!"

    async def rotate_game_text(self):
        while True:
            await self.change_presence(
                game=discord.Game(name="[Shard {}/{}] {} Servers".format(
                    self.shard_id + 1, self.shard_count, len(self.servers)
                ))
            )<commit_msg>Be more greedy with command prefixes.<commit_after>"""
Main bot class.
"""
import asyncio
import os
import sys
import traceback
from collections import OrderedDict
import time
import random

import discord
import logbook
import logging

from discord.ext.commands import Bot, CommandInvokeError, CheckFailure, MissingRequiredArgument
from logbook.compat import redirect_logging
from logbook import StreamHandler
from rethinkdb import ReqlDriverError

from joku.redis import RedisAdapter
from joku.rethink import RethinkAdapter
from joku import threadmanager

try:
    import yaml
except ImportError:
    import ruamel.yaml as yaml

redirect_logging()

StreamHandler(sys.stderr).push_application()


class Jokusoramame(Bot):
    def __init__(self, config: dict, *args, **kwargs):
        # Get the shard ID.
        shard_id = kwargs.get("shard_id", 0)

        self.manager = kwargs.get("manager")  # type: threadmanager.Manager

        self.config = config

        # Logging stuff
        self.logger = logbook.Logger("Jokusoramame:Shard-{}".format(shard_id))
        self.logger.level = logbook.INFO

        logging.root.setLevel(logging.INFO)

        # Call init.
        super().__init__(command_prefix=self.get_command_prefix, *args, **kwargs)

        self.app_id = ""
        self.owner_id = ""

        self.startup_time = time.time()

        self.rethinkdb = RethinkAdapter(self)

        self.redis = RedisAdapter(self)

        # Re-assign commands and extensions.
        self.commands = OrderedDict()
        self.extensions = OrderedDict()
        self.cogs = OrderedDict()

        self._rotator_task = None  # type: asyncio.Task
        self._avatar_rotator = None  # type: asyncio.Task

    def __del__(self):
        self.loop.set_exception_handler(lambda *args, **kwargs: None)

    # Utility functions.
    def get_member(self, id: str):
        """
        Gets a member from all members.
        """
        return discord.utils.get(self.get_all_members(), id=id)

    @staticmethod
    async def get_command_prefix(self: 'Jokusoramame', message: discord.Message):
        return ["j" + s for s in "!?^&$}#~:"]

    async def rotate_game_text(self):
        while True:
            await self.change_presence(
                game=discord.Game(name="[Shard {}/{}] {} Servers".format(
                    self.shard_id + 1, self.shard_count, len(self.servers)
                ))
            )
{'fraction_non_alphanumeric': 0.09866220735785954, 'fraction_numerical': 0.0008361204013377926, 'mean_word_length': 2.8066825775656326, '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': '1939644', 'n_tokens_mistral': 1463, 'n_tokens_neox': 1408, 'n_words': 349}