コード例 #1
0
    async def add_rule_by_self(
        self,
        ctx,
        name: str,
        message: discord.Message,
        emoji: str,
        reward_sticker: Optional[int],
        reward_role: Optional[discord.Role],
    ):
        with session_scope() as session:
            rule = Rule(
                name=name, by_admin=False, message_id=message.id, emoji=str(emoji)
            )

            if reward_sticker is not None:
                rule.reward_sticker = reward_sticker

            if reward_role is not None:
                rule.reward_role_id = reward_role.id

            session.add(rule)
            session.commit()
            self.bot.logger.info("rule add: " + repr(rule))
            await message.add_reaction(emoji)
            await ctx.send(f"규칙 #{rule.id} 추가됨!")
コード例 #2
0
    async def add_rule_by_admin(
        self,
        ctx,
        name: str,
        channel: discord.TextChannel,
        emoji: str,
        reward_sticker: Optional[int],
        reward_role: Optional[discord.Role],
    ):
        with session_scope() as session:
            rule = Rule(
                name=name, by_admin=True, channel_id=channel.id, emoji=str(emoji)
            )

            if reward_sticker is not None:
                rule.reward_sticker = reward_sticker

            if reward_role is not None:
                rule.reward_role_id = reward_role.id

            session.add(rule)
            session.commit()
            self.bot.logger.info("rule add: " + repr(rule))
            await ctx.send(f"규칙 #{rule.id} 추가됨!")