示例#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
    async def load(self) -> None:

        user_configs = await self.bot.db.fetch('SELECT * FROM user_configs')
        for user_config in user_configs:
            self.configs[user_config['id']] = objects.UserConfig(data=dict(user_config))

        print(f'[POSTGRESQL] Loaded user configs. [{len(user_configs)} users(s)]')
示例#3
0
    async def create_user_config(self, *, user_id: int) -> objects.UserConfig:

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

        return self.get_user_config(user_id=user_id)
示例#4
0
    async def create_user_config(self, *, user_id: int) -> objects.UserConfig:

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

        log.info(
            f'[USER MANAGER] Created config for user with id \'{user_id}\'')
        return self.configs[user_id]
示例#5
0
    async def set_user_config(self, ctx: context.Context, attribute: str, value: typing.Any, operation: str = 'add') -> None:

        if isinstance(ctx.user_config, objects.DefaultUserConfig):
            query = 'INSERT INTO user_configs (user_id) values ($1) ON CONFLICT (user_id) DO UPDATE SET user_id = excluded.user_id RETURNING *'
            data = await self.bot.db.fetchrow(query, ctx.author.id)
            self.bot.user_configs[ctx.author.id] = objects.UserConfig(data=dict(data))

        elif attribute == 'colour':
            query = 'UPDATE user_configs SET colour = $1 WHERE user_id = $2 RETURNING *'
            data = await self.bot.db.fetchrow(query, value, ctx.author.id)
            ctx.user_config.colour = discord.Colour(int(data['colour'], 16))
示例#6
0
    async def load(self) -> None:

        user_configs = await self.bot.db.fetch('SELECT * FROM user_configs')
        for user_config in user_configs:
            self.configs[user_config['id']] = objects.UserConfig(
                data=dict(user_config))

        log.info(
            f'[USER MANAGER] Loaded user configs. [{len(user_configs)} users]')
        print(
            f'[USER MANAGER] Loaded user configs. [{len(user_configs)} users]')

        await self.remind_manager.load()
示例#7
0
文件: users.py 项目: Axelancerr/Life
    async def fetch_config(self, user_id: int, /) -> objects.UserConfig:

        data = await self.bot.db.fetchrow(
            "INSERT INTO users (id) VALUES ($1) ON CONFLICT (id) DO UPDATE SET id = excluded.id RETURNING *",
            user_id)
        user_config = objects.UserConfig(bot=self.bot, data=data)

        await user_config.fetch_notifications()
        await user_config.fetch_todos()
        await user_config.fetch_reminders()
        await user_config.fetch_member_configs()

        self.cache[user_config.id] = user_config

        __log__.debug(f"[USERS] Cached config for '{user_id}'.")
        return user_config
示例#8
0
文件: bot.py 项目: HimawanRenn/Life
    async def set_user_config(self,
                              *,
                              user: typing.Union[discord.User, discord.Member],
                              attribute: str,
                              value: typing.Any,
                              operation: str = 'add') -> None:

        user_config = self.get_user_config(user=user)
        if isinstance(user_config, objects.DefaultUserConfig):
            query = 'INSERT INTO user_configs (user_id) values ($1) ON CONFLICT (user_id) DO UPDATE SET user_id = excluded.user_id RETURNING *'
            data = await self.db.fetchrow(query, user.id)
            self.user_configs[user.id] = objects.UserConfig(data=dict(data))

        if attribute == 'colour':
            query = 'UPDATE user_configs SET colour = $1 WHERE user_id = $2 RETURNING *'
            data = await self.db.fetchrow(query, value, user.id)
            user_config.colour = discord.Colour(int(data['colour'], 16))

        elif attribute == 'timezone':
            query = 'UPDATE user_configs SET timezone = $1 WHERE user_id = $2 RETURNING *'
            data = await self.db.fetchrow(query, value, user.id)
            user_config.timezone = data['timezone']