コード例 #1
0
ファイル: faq.py プロジェクト: lars-vc/didier
    async def faq(self, ctx, *args):
        """
        Command group that controls the FAQ commands.
        When this command is invoked, it sends a list of valid categories.
        :param ctx: Discord Context
        :param args: args passed
        """
        # A category was requested
        # This is not the cleanest but 80 subcommands is a bit much
        if len(args) != 0 and any("@" not in arg for arg in args):
            return await self.faqCategory(ctx, args)

        # List of all categories with the first letter capitalized
        resp = [stringFormatters.titleCase(cat[0]) for cat in faq.getCategories()]

        # Sort alphabetically
        resp.sort()

        # Create an embed with all the categories
        embed = discord.Embed(colour=discord.Colour.blue())
        embed.set_author(name="FAQ Categorieën")
        embed.description = "\n".join(resp)

        # Check if the embed has to be sent to the user
        # or if the user tagged anyone
        if len(ctx.message.mentions) == 0:
            await ctx.author.send(embed=embed)
        else:
            embed.set_footer(text="Doorgestuurd door {}".format(ctx.author.display_name))
            # Send it to everyone that was mentioned
            for person in ctx.message.mentions:
                if not person.bot:
                    await person.send(embed=embed)
コード例 #2
0
    async def faqCategory(self, ctx, args):
        """
        Function that sends everything from a category.
        :param ctx: Discord Context
        :param args: the args passed
        """

        # Create a list of categories
        categories = [t[0] for t in faq.getCategories()]

        # Random word was passed as a category
        if not any(arg.lower() in categories for arg in args):
            return await self.sendErrorEmbed(ctx,
                                             "Dit is geen geldige categorie.")
        elif len(args) - len(ctx.message.mentions) != 1:
            # Multiple categories were requested, which is not allowed
            return await self.sendErrorEmbed(ctx, "Controleer je argumenten.")

        category = ""

        # Find the category the user requested
        for word in args:
            if word.lower() in categories:
                category = word
                break

        resp = faq.getCategory(category.lower())

        # Sort by entry Id
        resp.sort(key=lambda x: int(x[0]))

        embed = discord.Embed(colour=discord.Colour.blue())
        embed.set_author(
            name="FAQ {}".format(stringFormatters.titleCase(category)))

        # Add everything into the embed
        for i, pair in enumerate(resp):
            # Add custom markdown if it exists
            embed.add_field(name="#{}: {}".format(str(i + 1), pair[2]),
                            value=pair[3] if pair[4] is None else pair[4],
                            inline=False)

        # Check if anyone was tagged to send the embed to
        if len(ctx.message.mentions) == 0:
            await ctx.author.send(embed=embed)
        else:
            embed.set_footer(
                text="Doorgestuurd door {}".format(ctx.author.display_name))
            # Author tagged some people to send it to
            for person in ctx.message.mentions:
                await person.send(embed=embed)
コード例 #3
0
    async def memes(self, ctx):
        """
        Command that shows a list of memes in the database.
        :param ctx: Discord Context
        """
        memeList = memes.getAllMemes()

        # Turn the list into a list of [Name: fields]
        memeList = [": ".join([stringFormatters.titleCase(meme[1]),
                               str(meme[2])]) for meme in sorted(memeList, key=lambda x: x[1])]

        pages = paginatedLeaderboard.Pages(source=paginatedLeaderboard.Source(memeList, "Memes", discord.Colour.blue()),
                                           clear_reactions_after=True)
        await pages.start(ctx)
コード例 #4
0
ファイル: fun.py プロジェクト: lars-vc/didier
    async def memes(self, ctx):
        """
        Command that shows a list of memes in the database.
        :param ctx: Discord Context
        """
        memeList = memes.getAllMemes()

        # Turn the list into a list of [Name: fields]
        memeList = [
            ": ".join([stringFormatters.titleCase(meme[1]),
                       str(meme[2])])
            for meme in sorted(memeList, key=lambda x: x[1])
        ]

        # Add the fields into the embed
        embed = discord.Embed(colour=discord.Colour.blue())
        embed.add_field(name="Meme: aantal velden",
                        value="\n".join(memeList),
                        inline=False)
        await ctx.send(embed=embed)