コード例 #1
0
    async def load(self) -> None:

        await self.bot.wait_until_ready()

        guild_configs = await self.bot.db.fetch('SELECT * FROM guild_configs')
        for guild_config in guild_configs:
            if self.bot.guild_configs.get(
                    guild_config['guild_id']) is not None:
                continue
            self.bot.guild_configs[
                guild_config['guild_id']] = objects.GuildConfig(
                    data=dict(guild_config))

        print(
            f'[POSTGRESQL] Loaded guild configs. [{len(guild_configs)} guild(s)]'
        )

        user_configs = await self.bot.db.fetch('SELECT * FROM user_configs')
        for user_config in user_configs:
            if self.bot.user_configs.get(user_config['user_id']) is not None:
                continue
            self.bot.user_configs[user_config['user_id']] = objects.UserConfig(
                data=dict(user_config))

        print(
            f'[POSTGRESQL] Loaded user configs. [{len(user_configs)} users(s)]'
        )
コード例 #2
0
ファイル: guild_manager.py プロジェクト: TrissieTheHusky/Life
    async def load(self) -> None:

        guild_configs = await self.bot.db.fetch('SELECT * FROM guild_configs')
        for guild_config in guild_configs:
            self.configs[guild_config['id']] = objects.GuildConfig(data=dict(guild_config))

        print(f'[POSTGRESQL] Loaded guild configs. [{len(guild_configs)} guild(s)]')
コード例 #3
0
ファイル: bot.py プロジェクト: HimawanRenn/Life
    async def set_guild_config(self,
                               *,
                               guild: discord.Guild,
                               attribute: str,
                               value: typing.Any,
                               operation: str = 'add') -> None:

        guild_config = self.get_guild_config(guild=guild)
        if isinstance(guild_config, objects.DefaultGuildConfig):
            query = 'INSERT INTO guild_configs (guild_id) values ($1) ON CONFLICT (guild_id) DO UPDATE SET guild_id = excluded.guild_id RETURNING *'
            data = await self.db.fetchrow(query, guild.id)
            self.guild_configs[guild.id] = objects.GuildConfig(data=dict(data))

        if attribute == 'prefix':
            query = 'UPDATE guild_configs SET prefixes = array_append(prefixes, $1) WHERE guild_id = $2 RETURNING prefixes'
            if operation == 'remove':
                query = 'UPDATE guild_configs SET prefixes = array_remove(prefixes, $1) WHERE guild_id = $2 RETURNING prefixes'
            if operation == 'clear':
                query = 'UPDATE guild_configs SET prefixes = $1 WHERE guild_id = $2 RETURNING prefixes'

            data = await self.db.fetchrow(query, value, guild.id)
            guild_config.prefixes = data['prefixes']

        elif attribute == 'colour':
            query = 'UPDATE guild_configs SET colour = $1 WHERE guild_id = $2 RETURNING *'
            data = await self.db.fetchrow(query, value, guild.id)
            guild_config.colour = discord.Colour(int(data['colour'], 16))
コード例 #4
0
    async def create_guild_config(self, *,
                                  guild_id: int) -> objects.GuildConfig:

        data = await self.bot.db.fetchrow(
            'INSERT INTO guild_configs (id) values ($1) ON CONFLICT (id) DO UPDATE SET id = excluded.id RETURNING *',
            guild_id)
        self.configs[guild_id] = objects.GuildConfig(data=dict(data))

        return self.configs[guild_id]
コード例 #5
0
ファイル: guild_manager.py プロジェクト: vzymox/Life
    async def create_guild_config(self, *,
                                  guild_id: int) -> objects.GuildConfig:

        data = await self.bot.db.fetchrow(
            'INSERT INTO guild_configs (id) values ($1) ON CONFLICT (id) DO UPDATE SET id = excluded.id RETURNING *',
            guild_id)
        self.configs[guild_id] = objects.GuildConfig(data=dict(data))

        log.info(
            f'[GUILD MANAGER] Created config for guild with id \'{guild_id}\'')
        return self.configs[guild_id]
コード例 #6
0
    async def fetch_config(self, guild_id: int) -> objects.GuildConfig:

        data = await self.bot.db.fetchrow(
            "INSERT INTO guilds (id) values ($1) ON CONFLICT (id) DO UPDATE SET id = excluded.id RETURNING *",
            guild_id)
        guild_config = objects.GuildConfig(bot=self.bot, data=data)

        await guild_config.fetch_tags()

        self.cache[guild_config.id] = guild_config

        __log__.debug(f"[GUILDS] Cached config for '{guild_id}'.")
        return guild_config
コード例 #7
0
ファイル: guild_manager.py プロジェクト: vzymox/Life
    async def load(self) -> None:

        guild_configs = await self.bot.db.fetch('SELECT * FROM guild_configs')
        for guild_config in guild_configs:
            self.configs[guild_config['id']] = objects.GuildConfig(
                data=dict(guild_config))

        log.info(
            f'[GUILD MANAGER] Loaded guild configs. [{len(guild_configs)} guilds]'
        )
        print(
            f'[GUILD MANAGER] Loaded guild configs. [{len(guild_configs)} guilds]'
        )