def __init__(self, bot: TTSBot):
        self.bot = bot
        self.pool = bot.pool
        bot.add_listener(self.on_invalidate_cache)

        self._do_not_cache: List[_DK] = []
        self._cache: Dict[_DK, Optional[asyncpg.Record]] = {}
Exemplo n.º 2
0
    def __init__(self, bot: TTSBot, broadcast: bool, select: str, delete: str,
                 table_name: str, pkey_columns: tuple[str, ...]):
        self.bot = bot
        self.pool = bot.pool

        self.broadcast = broadcast
        self.select_query = select
        self.delete_query = delete
        self.pkey_columns = tuple(sql(pkey) for pkey in pkey_columns)
        self.default_id = 0 if len(
            pkey_columns) == 1 else (0, ) * len(pkey_columns)

        generic_insert_query = """
            INSERT INTO {}({{}})
            VALUES({{}})

            ON CONFLICT ({})
            {}
        """

        args = table_name, ", ".join(pkey_columns)
        self.multi_insert_query = generic_insert_query.format(
            *args, "DO UPDATE SET ({}) = ({})")
        self.single_insert_query = generic_insert_query.format(
            *args, "DO UPDATE SET {} = {}")
        self.ensure_row_query = generic_insert_query.format(
            *args, "DO NOTHING{}{}")

        self._not_fully_fetched: list[_DK] = []
        self._cache: dict[_DK, _CACHE_ITEM] = {}
        self.defaults: Optional[_CACHE_ITEM] = None
        self._write_tasks: defaultdict[_DK, WriteTask] = defaultdict(WriteTask)

        bot.add_listener(self.on_invalidate_cache)
Exemplo n.º 3
0
def setup(bot: TTSBot):
    try:
        from jishaku import Jishaku
    except ModuleNotFoundError:
        print("jishaku not installed, -jsk will not be available")
    else:
        bot.add_cog(Jishaku(bot=bot))
        jsk = cast(Optional[commands.Command], bot.get_command("jsk"))

        assert jsk is not None
        jsk.hidden = True
Exemplo n.º 4
0
async def add_log_level(bot: TTSBot) -> bool:
    if "log_level" in bot.config["Main"]:
        return False

    bot.config["Main"]["log_level"] = "INFO"
    _update_config(bot.config)
    return True
Exemplo n.º 5
0
async def cache_to_redis(bot: TTSBot) -> bool:
    if "Redis Info" in bot.config:
        return False

    bot.config["Redis Info"] = {"url": "redis://cache"}
    _update_config(bot.config)
    return True
Exemplo n.º 6
0
    def __init__(self, bot: TTSBot):
        help_command = FancyHelpCommand()

        bot.help_command = help_command
        bot.help_command.cog = self
        bot.help_command.add_check(
            commands.bot_has_permissions(
                send_messages=True, embed_links=True).predicate  # type: ignore
        )
Exemplo n.º 7
0
async def do_normal_updates(bot: TTSBot):
    if bot.cluster_id not in {0, None}:
        return

    async with bot.pool.acquire() as conn:
        bot.conn = conn
        for func in normal_updates:
            if await func(bot):
                print(f"Completed update: {func.__name__}")
    del bot.conn
Exemplo n.º 8
0
async def setup_bot(bot: TTSBot) -> bool:
    if "key" in bot.config["Main"]:
        return False

    import asyncpg
    from cryptography.fernet import Fernet

    db_info = bot.config["PostgreSQL Info"]
    bot.config["Main"]["key"] = str(Fernet.generate_key())

    conn = await asyncpg.connect(**db_info)
    await conn.execute(utils.DB_SETUP_QUERY)
    await conn.close()

    _update_config(bot.config)
    return True
Exemplo n.º 9
0
async def update_config(bot: TTSBot) -> bool:
    config = bot.config
    if "Webhook URLs" in config:
        return False

    config["Webhook URLs"] = config["Channels"]
    config["Main"].pop("cache_key", None) # old key, to remove
    config["PostgreSQL Info"]["host"] = config["PostgreSQL Info"].pop("ip")
    config["PostgreSQL Info"]["user"] = config["PostgreSQL Info"].pop("name")
    config["PostgreSQL Info"]["database"] = config["PostgreSQL Info"].pop("db")
    config["PostgreSQL Info"]["password"] = config["PostgreSQL Info"].pop("pass")

    del config["Channels"]
    bot.config = config

    _update_config(config)
    return True
Exemplo n.º 10
0
def setup(bot: TTSBot):
    bot.settings, bot.userinfo, bot.nicknames = (TableHandler[int](
        bot,
        table_name="guilds",
        broadcast=True,
        pkey_columns=("guild_id", ),
        select="SELECT * FROM guilds WHERE guild_id = $1",
        delete="DELETE FROM guilds WHERE guild_id = $1",
    ), TableHandler[int](
        bot,
        table_name="userinfo",
        broadcast=False,
        pkey_columns=("user_id", ),
        select="SELECT * FROM userinfo WHERE user_id = $1",
        delete="DELETE FROM userinfo WHERE user_id = $1",
    ), TableHandler[tuple[int, int]](
        bot,
        table_name="nicknames",
        broadcast=False,
        pkey_columns=("guild_id", "user_id"),
        select="SELECT * from nicknames WHERE guild_id = $1 and user_id = $2",
        delete="DELETE FROM nicknames WHERE guild_id = $1 and user_id = $2",
    ))
Exemplo n.º 11
0
def setup(bot: TTSBot):
    bot.add_cog(Loops(bot))
Exemplo n.º 12
0
def setup(bot: TTSBot):
    bot.add_cog(SettingCommands(bot))
Exemplo n.º 13
0
def setup(bot: TTSBot):
    bot.add_cog(DevCommands(bot))
Exemplo n.º 14
0
def setup(bot: TTSBot):
    bot.analytics_buffer = utils.SafeDict()
    bot.add_cog(AnalyticsEvents(bot))
def setup(bot: TTSBot):
    bot.add_cog(OtherEvents(bot))
def setup(bot: TTSBot):
    bot.add_cog(MainEvents(bot))
Exemplo n.º 17
0
def setup(bot: TTSBot):
    bot.add_cog(ExtraCommands(bot))
def setup(bot: TTSBot):
    bot.settings = GeneralSettings(bot)
    bot.userinfo = UserInfoHandler(bot)
    bot.nicknames = NicknameHandler(bot)
Exemplo n.º 19
0
def setup(bot: TTSBot):
    bot.add_cog(MainCommands(bot))
Exemplo n.º 20
0
def setup(bot: TTSBot):
    bot.add_cog(SlashCommands(bot))
Exemplo n.º 21
0
def setup(bot: TTSBot):
    bot.cache = CacheHandler(bot)
Exemplo n.º 22
0
def setup(bot: TTSBot):
    bot.add_cog(FancyHelpCommandCog(bot))
def setup(bot: TTSBot):
    bot.add_cog(TrustedCommands(bot))
Exemplo n.º 24
0
def setup(bot: TTSBot):
    if bot.cluster_id == 0:
        bot.add_cog(DMHandler(bot))
Exemplo n.º 25
0
def setup(bot: TTSBot):
    bot.add_cog(OwnerCommands(bot))
def setup(bot: TTSBot):
    cog = ErrorEvents(bot)

    bot.add_cog(cog)
    bot.on_error = cog.on_error