disambiguate.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:Chiaki-Nanami 作者: Ikusaba-san 项目源码 文件源码
def convert(self, ctx, argument):
        bot = ctx.bot

        match = self._get_id_match(argument) or re.match(r'<#([0-9]+)>$', argument)
        result = None
        guild = ctx.guild

        if match is not None:
            return await super().convert(ctx, argument)
        else:
            if self.case_sensitive:
                def check(c):
                    return isinstance(c, discord.TextChannel) and c.name == argument
            else:
                # not a mention
                lowered = argument.lower()

                def check(c):
                    return isinstance(c, discord.TextChannel) and c.name.lower() == lowered

            if guild:
                result = list(filter(check, guild.text_channels))
                transform = str
            else:
                result = list(filter(check, bot.get_all_channels()))
                transform = '{0} (Server: {0.guild})'

        return await ctx.disambiguate(result, transform)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号