コード例 #1
0
ファイル: CogRetrieval.py プロジェクト: MasN2/laprOS
    async def collectStories(ctx: commands.Context, matcher: Callable[[Story],
                                                                      bool],
                             headerText: str, failText: str):
        archive = getArchiveFromContext(ctx)
        archiveChannel: discord.TextChannel = await fetchChannel(
            ctx.guild, archive.channelID)

        pages = []
        for post in archive.posts.values():
            foundStories: list[Story] = []
            for story in post.stories:
                if matcher(story):
                    foundStories.append(story)

            if foundStories:
                author = await convertMember(post.authorID, ctx)
                try:
                    message: discord.Message = await archiveChannel.fetch_message(
                        post.messageID)
                except discord.HTTPException:
                    fail(R.deletedPost(author.display_name))
                pages.append({
                    "embed":
                    getLaprOSEmbed(**R.collectionEmbed(
                        headerText, author.display_name,
                        [story.title
                         for story in foundStories], message.jump_url))
                })
        if not pages:
            await ctx.send(failText)
        else:
            await paginate(ctx, pages)
コード例 #2
0
ファイル: CogRetrieval.py プロジェクト: MasN2/laprOS
    async def byRandom(self, ctx: commands.Context):
        archive = getArchiveFromContext(ctx)

        archiveChannel: discord.TextChannel = await fetchChannel(
            ctx.guild, archive.channelID)
        post = archive.getRandomPost()
        attempts = 100
        while True:
            try:
                message: discord.Message = await archiveChannel.fetch_message(
                    post.messageID)

                author: discord.Member = await ctx.guild.fetch_member(
                    post.authorID)
                if not author: raise discord.DiscordException()
                break
            except discord.DiscordException:
                post = archive.getRandomPost()

            attempts -= 1
            if attempts <= 0:
                await fail(R.byRandom.error)

        story = post.getRandomStory()
        await ctx.send(embed=getLaprOSEmbed(**R.byRandom.embed(
            story.title, author.display_name, story.summary, message.jump_url))
                       )
コード例 #3
0
ファイル: Help.py プロジェクト: MasN2/laprOS
 async def sendPaginatedHelp(self, parentName: str, cmds: list[commands.Command], aliases: Optional[list[str]]=None):
     pages = []
     commandNames = [cmd.qualified_name for cmd in cmds]
     for i, command in enumerate(cmds):
         pages.append({
             "content": T.HELP.commandPaginationContent(parentName, commandNames, i, aliases),
             "embed": getLaprOSEmbed(**T.HELP.commandEmbed(command.qualified_name, command.aliases, command.help))
         })
     await paginate(self.context, pages, True)
コード例 #4
0
ファイル: Help.py プロジェクト: MasN2/laprOS
 async def send_bot_help(self, mapping: Mapping[Optional[commands.Cog], list[commands.Command]]):
     pages = []
     cogNames = [cog.qualified_name for cog in mapping if isinstance(cog, commands.Cog) and getNonhiddenCommands(mapping[cog])]
     for i, cog in enumerate(mapping):
         if not cog: continue
         cmds = mapping[cog]
         if not cmds: continue
         pages.append({
             "content": T.HELP.cogPaginationContent(cogNames, i),
             "embed": getLaprOSEmbed(**T.HELP.cogEmbed(cog.qualified_name, cog.description, getNonhiddenCommands(cmds, lambda cmd: cmd.qualified_name)))
         })
     await paginate(self.context, pages, True)
コード例 #5
0
ファイル: CogRetrieval.py プロジェクト: MasN2/laprOS
    async def byAuthor(self, ctx: commands.Context, *,
                       author: Union[discord.Member, int, str]):
        author = await convertMember(author, ctx)
        archive = getArchiveFromContext(ctx)
        archiveChannel: discord.TextChannel = await fetchChannel(
            ctx.guild, archive.channelID)

        post = archive.getPost(author.id)
        try:
            message: discord.Message = await archiveChannel.fetch_message(
                post.messageID)
        except AttributeError:
            fail(R.noPost(author.display_name))
        except discord.HTTPException:
            fail(R.deletedPost(author.display_name))
        await ctx.send(embed=getLaprOSEmbed(**R.byAuthor.embed(
            author.display_name, post.getStoryTitles(), message.jump_url)))
コード例 #6
0
ファイル: CogRetrieval.py プロジェクト: MasN2/laprOS
 async def archiveGuide(self, ctx: commands.Context):
     await paginate(ctx, [{
         "embed": getLaprOSEmbed(**page)
     } for page in R.archiveGuide.pages])
コード例 #7
0
ファイル: Help.py プロジェクト: MasN2/laprOS
 async def send_command_help(self, command: commands.Command):
     embed = getLaprOSEmbed(
         **T.HELP.commandEmbedWithFooter(command.qualified_name, command.aliases, command.help, command.cog_name)
     )
     await self.context.send(embed=embed)