wiki.py 文件源码

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

项目:Socrates 作者: Curlybear 项目源码 文件源码
def wiki(self, ctx, *, search_query):
        logger.info('!wiki ' + search_query + ' - User: ' + str(ctx.message.author))
        data = self.utils.search_wiki(search_query)

        if len(data) == 1:
            result_id = 0
        else:
            if 1 < len(data) <= 10:
                # Display all results then await choice
                i = 1
                text = ''
                for entry in data:
                    text += str(i) + ') **' + entry[1] + '** - *Category: ' + str(entry[2]) + '*\n'
                    i += 1
                em = discord.Embed(title='Please enter the number of the targeted wiki entry',
                                   description=text,
                                   colour=0x3D9900)
                await self.bot.send_message(ctx.message.channel, '', embed=em)
                msg = await self.bot.wait_for_message(author=ctx.message.author)
                if int(msg.content) >= i or int(msg.content) < 1:
                    await self.bot.say('Invalid choice')
                    return
                result_id = int(msg.content) - 1
            else:
                await self.bot.send_message(ctx.message.channel, 'No matching entry found.')
                return
        temp = json.JSONDecoder().decode(data[result_id][3])
        tempembed = discord.Embed().from_data(temp)
        await self.bot.send_message(ctx.message.channel, '', embed=tempembed)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号