Example #1
0
    def get_message(self, user: DiscordUser, bot: Bot) -> str:
        """The markdown-formatted version of the message.txt from the
        action's directory, and its result, as a string.
        """

        story = Template(normalize_newlines(self._message))

        return story.safe_substitute(DISPLAY_NAME=user.display_name,
                                     DISCRIMINATOR=user.discriminator,
                                     BOTNAME=bot.user.name)
Example #2
0
    def get_message(self, user: DiscordUser, bot: Bot) -> str:
        """Return the markdown-formatted story for this bribe as a combined
        string.
        """
        story = Template(normalize_newlines(self._story))

        return story.safe_substitute(NAME=user.name,
                                     DISPLAY_NAME=user.display_name,
                                     DISCRIMINATOR=user.discriminator,
                                     BOTNAME=bot.user.name)
Example #3
0
    def get_message(self, user: BotUser) -> str:
        """The markdown-formatted version of the message.txt from the
        action's directory, and its result, as a string.
        """
        formatted_story = "*" + normalize_newlines(self._message) + "*"
        action_result = "** **\n{emt} `{dfn:.0f}% team damage reduction!`".format(
            emt=Pomwars.Emotes.DEFEND,
            dfn=100 * Pomwars.DEFEND_LEVEL_MULTIPLIERS[user.defend_level],
        )

        return "\n\n".join([action_result, formatted_story])
Example #4
0
    def get_message(self, user: BotUser) -> str:
        """Return the effect and the markdown-formatted story for this defend
        as a combined string.
        """
        action_result = "** **\n{emt} `{dfn:.0f}% team damage reduction!`".format(
            emt=Pomwars.Emotes.DEFEND,
            dfn=100 * Pomwars.DEFEND_LEVEL_MULTIPLIERS[user.defend_level],
        )
        formatted_story = "*" + normalize_newlines(self._story) + "*"

        return "\n\n".join([action_result, formatted_story])
Example #5
0
    def message(self) -> str:
        """Return the effect and the markdown-formatted story for this defend
        as a combined string.
        """
        action_result = "{emt} `{dfn:.0f}% team damage reduction!`".format(
            emt=Pomwars.Emotes.DEFEND,
            dfn=100 * Pomwars.DEFEND_LEVEL_MULTIPLIERS[self._user.defend_level],
        )
        formatted_story = "*" + normalize_newlines(self._story) + "*"

        return ("\n\n".join([action_result, formatted_story])
                if self._outcome != Outcome.MISSED else formatted_story)
Example #6
0
    def get_message(self, adjusted_damage: int = None) -> str:
        """The markdown-formatted version of the message.txt from the
        action's directory, and its result, as a string.
        """
        dmg = adjusted_damage or self.damage
        dmg_str = f"{dmg:.1f}" if dmg % 1 else str(int(dmg))
        message_lines = [f"** **\n{Pomwars.Emotes.ATTACK} `{dmg_str} damage!`"]

        if self.is_critical:
            message_lines += [f"{Pomwars.Emotes.CRITICAL} `Critical attack!`"]

        action_result = "\n".join(message_lines)
        formatted_story = "*" + normalize_newlines(self._message) + "*"

        return "\n\n".join([action_result, formatted_story])
Example #7
0
    def get_message(self, adjusted_damage: int = None) -> str:
        """Return the effect and the markdown-formatted story for this attack as
        a combined string.
        """
        dmg = adjusted_damage or self.damage
        dmg_str = f"{dmg:.1f}" if dmg % 1 else str(int(dmg))
        message_lines = [f"** **\n{Pomwars.Emotes.ATTACK} `{dmg_str} damage!`"]

        if self._is_critical:
            message_lines += [f"{Pomwars.Emotes.CRITICAL} `Critical attack!`"]

        action_result = "\n".join(message_lines)
        formatted_story = "*" + normalize_newlines(self._story) + "*"

        return "\n\n".join([action_result, formatted_story])
Example #8
0
    async def message(self) -> str:
        """Return the effect and the markdown-formatted story for this attack as
        a combined string.
        """
        message_lines = [f"{Pomwars.Emotes.ATTACK} `{{}} damage!`".format(
            ("{:.1f}" if await self.damage % 1 else "{}").format(self._damage)
        )]

        if self._outcome == Outcome.CRITICAL:
            message_lines += [f"{Pomwars.Emotes.CRITICAL} `Critical attack!`"]

        action_result = "\n".join(message_lines)
        formatted_story = "*" + normalize_newlines(self._story) + "*"

        return ("\n\n".join([action_result, formatted_story])
                if self._outcome != Outcome.MISSED else formatted_story)
Example #9
0
def _get_help_for_commands(
    ctx: Context,
    is_public: bool,
    *commands: Tuple[str],
) -> Tuple[Optional[List[EmbedField]], Optional[str]]:
    """Get a specific command(s) help information.

    @param ctx Message context.
    @param commands The commands to lookup.
    @return Tuple of (Response field list, Intended footer).
    """
    # Remove "dot-alias", but preserve order of user-supplied values.
    requested_commands = tuple(cmd.rsplit(".", 1)[0].casefold() for cmd in commands)
    existing_commands = {c.name.casefold() for c in ctx.bot.commands}

    fields = []
    if command_names_found := set(requested_commands) & existing_commands:
        for command in _uniq(requested_commands):

            # If we simply iterate over command_names_found, then they won't
            # appear in the order requested by the user.
            if command not in command_names_found:
                continue

            checks = next(c.checks for c in ctx.bot.commands
                          if c.name == command)

            try:
                for func in checks:
                    func(ctx)
            except NoPrivateMessage:
                return (None, None)
            except MissingAnyRole:
                continue

            fields += [
                EmbedField(name=Config.PREFIX + cmd.name,
                           value="```" + normalize_newlines(cmd.help) + "```",
                           inline=False)
                    for cmd in ctx.bot.commands if cmd.name == command
            ]