How to use the d20.MarkdownStringifier function in d20

To help you get started, we’ve selected a few d20 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github avrae / avrae / cogs5e / models / sheet / resistance.py View on Github external
if __name__ == '__main__':
    import traceback

    resists = Resistances(resist=[Resistance('resist', ['magical']), Resistance('both')],
                          immune=[Resistance('immune'), Resistance('this', only=['magical'])],
                          vuln=[Resistance('vuln'), Resistance('both')],
                          neutral=[Resistance('neutral')])

    while True:
        try:
            result = d20.roll(input())
            print(str(result))
            do_resistances(result.expr, resists)
            print(d20.MarkdownStringifier().stringify(result.expr))
        except Exception as e:
            traceback.print_exc()
github avrae / avrae / cogs5e / funcs / scripting / functions.py View on Github external
def __init__(self, result):
        """
        :type result: d20.RollResult
        """
        self.dice = d20.MarkdownStringifier().stringify(result.expr.roll)
        self.total = result.total
        self.full = str(result)
        self.result = result
        self.raw = result.expr
        self._roll = result
github avrae / avrae / utils / dice.py View on Github external
import d20


class VerboseMDStringifier(d20.MarkdownStringifier):
    def _str_expression(self, node):
        return f"**{node.comment or 'Result'}**: {self._stringify(node.roll)}\n" \
               f"**Total:** {int(node.total)}"


class PersistentRollContext(d20.RollContext):
    """
    A roll context that tracks lifetime rolls as well as individual rolls.
    """

    def __init__(self, max_rolls=1000, max_total_rolls=None):
        """
        :param max_rolls: The maximum number of rolls allowed in an individual roll.
        :param max_total_rolls: The maximum number of rolls allowed throughout this object's lifetime.
        """
        super().__init__(max_rolls)
github avrae / avrae / cogs5e / models / automation.py View on Github external
elif transforms:
            for frm in transforms:
                autoctx.meta_queue(f"**Damage Change**: {frm} > {transforms[frm]}")

        # evaluate resistances
        do_resistances(dmgroll.expr, resistances, always, transforms)

        # generate output
        result = d20.MarkdownStringifier().stringify(dmgroll.expr)

        # output
        if not hide:
            autoctx.queue(f"**{roll_for}**: {result}")
        else:
            d20.utils.simplify_expr(dmgroll.expr)
            autoctx.queue(f"**{roll_for}**: {d20.MarkdownStringifier().stringify(dmgroll.expr)}")
            autoctx.add_pm(str(autoctx.ctx.author.id), f"**{roll_for}**: {result}")

        autoctx.target.damage(autoctx, dmgroll.total, allow_overheal=self.overheal)

        # return metadata for scripting
        return {'damage': f"**{roll_for}**: {result}", 'total': dmgroll.total, 'roll': dmgroll}