示例#1
0
    async def _cmd_search(self, channel, deck, query):
        """Handles the search subcommand.

        Args:
            channel: The channel in which the command was executed.
            deck: The requested deck.
            query: The search query.
        """
        results = []
        search_results = 0
        query = query.lower()
        for id, entry in enumerate(deck.cards):
            _, card = entry
            if query in card.lower():
                if search_results < self._results_limit:
                    results.append((id, card))
                search_results += 1
        title = "Search Results"
        if search_results > self._results_limit:
            title += " (showing first %d of %d results)" % (self._results_limit,
                                                            search_results)
        if search_results == 0:
            title = "No Results"
        msg = "\n".join(["#%d: `%s`" % (id, card) for id, card in results])
        embed = create_embed(title, msg, 0x00AA00)
        await channel.send(embed=embed)
示例#2
0
    async def _prompt_check(self, data):
        """Part of the .say command. Constructs the embed and demonstrates it.

        Args:
            data: The session data for this command.
        """
        msg = data["msg"]

        embed = create_embed(data["title"], data["text"], data["color"],
                             data["image"], data["fields"])
        headline = "**THIS IS WHAT YOUR EMBED WILL LOOK LIKE**"
        if data["ping"] is not None:
            headline += "\n(Will also ping `" + data["ping"] \
                        + "` in the target channel)"
        await msg.channel.send(headline, embed=embed)

        await msg.channel.send("Confirm sending this embed? [Yes/Abort]")
        response = await self._input(msg.author, msg.channel)
        if response is None:
            return

        if response.content.lower() == "yes":
            tagline = ""
            if data["ping"] is not None:
                tagline = data["ping"]
            await data["channel"].send(tagline, embed=embed)
        else:
            await msg.channel.send("Action aborted.")
示例#3
0
    async def _error(self, channel, title, content):
        """Sends an error to the given channel.

        Args:
            channel: The channel.
            title: The title of the error.
            content: The error message.
        """
        embed = create_embed("Error - " + title, content, 0xAA0000)
        await channel.send(embed=embed)
示例#4
0
    async def _cmd_add(self, channel, deck, type, text):
        """Handles the add subcommand.

        Args:
            channel: The channel in which the command was executed.
            deck: The requested deck.
            type: The requested card type.
            text: The requested text for the card.
        """
        try:
            deck.add_card(type, text)
            self.save_decks()
            embed = create_embed("New " + type, "`%s`" % text, 0x00AA00)
            await channel.send(embed=embed)
        except ValueError as e:
            await self._error(channel, "Could Not Add", str(e))
示例#5
0
    async def _cmd_replace(self, channel, deck, id, type, text):
        """Handles the replace subcommand.

        Args:
            channel: The channel in which the command was executed.
            deck: The deck that was requested.
            id: The card ID to replace.
            type: The requested card type.
            text: The requested text for the card.
        """
        if len(deck.cards) <= id or id < 0:
            await self._error(channel, "Invalid ID", "This ID is invalid.")
            return
        try:
            deck.add_card(type, text)
            deck.cards[id] = deck.cards.pop()
            self.save_decks()
            embed = create_embed("Replaced card #%d with %s" % (id, type),
                                 "`%s`" % text, 0x00AA00)
            await channel.send(embed=embed)
        except ValueError as e:
            await self._error(channel, "Could Not Add", str(e))