コード例 #1
0
ファイル: gamelog.py プロジェクト: storytellermahkasad/avrae
    async def _dice_roll_embed_common(self, gctx, roll_request, title_fmt: str,
                                      **fmt_kwargs):
        """
        Common method to display a character embed based on some check/save result.

        Note: {name} will be formatted with the character's name in title_fmt.
        """
        # check for valid caster
        caster = await gctx.get_statblock()
        if caster is None:
            await self.dice_roll_roll(
                gctx,
                roll_request,
                comment_getter=gamelogutils.default_comment_getter(
                    roll_request))
            return

        # only listen to the first roll
        the_roll = roll_request.rolls[0]

        # send embed
        embed = gamelogutils.embed_for_caster(caster)
        embed.title = title_fmt.format(name=caster.get_title_name(),
                                       **fmt_kwargs)
        embed.description = str(the_roll.to_d20())
        embed.set_footer(text=f"Rolled in {gctx.campaign.campaign_name}",
                         icon_url=constants.DDB_LOGO_ICON)
        await gctx.send(embed=embed)
コード例 #2
0
ファイル: gamelog.py プロジェクト: storytellermahkasad/avrae
    async def dice_roll(self, gctx):
        """
        Sends a message with the result of the roll, similar to `!r`.
        """
        await gctx.trigger_typing()

        roll_request = ddb.dice.RollRequest.from_dict(gctx.event.data)
        if not roll_request.rolls:  # do nothing if there are no rolls actually made
            return
        elif len(
                roll_request.rolls
        ) > 1:  # if there are multiple rolls in the same event, just use the default handler
            await self.dice_roll_roll(
                gctx,
                roll_request,
                comment_getter=gamelogutils.default_comment_getter(
                    roll_request))
            return
        first_roll = roll_request.rolls[0]

        roll_callbacks = {  # takes in (gctx, roll_request)
            ddb.dice.RollType.CHECK: self.dice_roll_check,
            ddb.dice.RollType.SAVE: self.dice_roll_save,
            ddb.dice.RollType.TO_HIT: self.dice_roll_to_hit,
            ddb.dice.RollType.DAMAGE: self.dice_roll_damage,
            ddb.dice.RollType.SPELL: self.dice_roll_spell,
            ddb.dice.RollType.HEAL: self.dice_roll_heal
        }

        # noinspection PyArgumentList
        await roll_callbacks.get(first_roll.roll_type,
                                 self.dice_roll_roll)(gctx, roll_request)
コード例 #3
0
ファイル: gamelog.py プロジェクト: storytellermahkasad/avrae
    async def dice_roll_roll(gctx,
                             roll_request,
                             comment=None,
                             comment_getter=None):
        """
        Generic roll: Display the roll in a format similar to ``!r``.

        :type gctx: ddb.gamelog.context.GameLogEventContext
        :type roll_request: ddb.dice.RollRequest
        :param comment: If comment_getter is not supplied, the comment used for all rolls.
        :type comment: str or None
        :param comment_getter: A function that takes a RollRequestRoll and returns a string, or None.
        :type comment_getter: Callable[[ddb.dice.RollRequestRoll], str]
        """
        if comment_getter is None:
            if comment is None:
                comment_getter = gamelogutils.default_comment_getter(
                    roll_request)
            else:
                comment_getter = lambda _: comment

        results = []
        for rr in roll_request.rolls:
            results.append(
                str(
                    rr.to_d20(stringifier=VerboseMDStringifier(),
                              comment=comment_getter(rr))))

        if sum(len(r)
               for r in results) > 1950:  # some len removed for other stuff
            final_results = '\n'.join(
                f"**{comment_getter(rr)}**: {rr.result.total}"
                for rr in roll_request.rolls)
        else:
            final_results = '\n'.join(results)

        out = f"<@!{gctx.discord_user_id}> **rolled from** {constants.DDB_LOGO_EMOJI}:\n{final_results}"
        # the user knows they rolled - don't need to ping them in discord
        await gctx.send(out, allowed_mentions=discord.AllowedMentions.none())