async def dice(self, ctx: commands.Context, *, roll: str): """Perform die roll based on a dice formula. The [PyHedrals](https://github.com/StarlitGhost/pyhedrals) library is used for dice formula parsing. Use the link above to learn the notation allowed. Below are a few examples: `2d20kh` - Roll 2d20, keep highest die (e.g. initiative advantage) `4d4!+2` - Roll 4d4, explode on any 4s, add 2 to result `4d6rdl` - Roll 4d6, reroll all 1s, then drop the lowest die `6d6c>4` - Roll 6d6, count all dice greater than 4 as successes `10d10r<=2kh6` - Roll 10d10, reroll all dice less than or equal to 2, then keep the highest 6 dice Modifier order does matter, and usually they allow for specifying a specific number or number ranges after them. """ try: dr = pyhedrals.DiceRoller( maxDice=await self.config.max_dice_rolls(), maxSides=await self.config.max_die_sides(), ) result = dr.parse(roll) roll_message = "\N{GAME DIE} {} rolled {} and got **{}**".format( ctx.message.author.mention, roll, result.result, ) if len(roll_message) > 2000: raise ValueError("resulting roll message is too big to send in Discord") roll_log = "\n".join(result.strings()) roll_log = self.DROPPED_EXPLODED_RE.sub(r"~~**\1!**~~", roll_log) roll_log = self.EXPLODED_RE.sub(r"**\1!**", roll_log) roll_log = self.DROPPED_RE.sub(r"~~\1~~", roll_log) roll_log = roll_log.replace(",", ", ") if len(roll_message) + len(roll_log) > 2000: roll_log = "*(Roll log too long to display)*" await ctx.send("{}\n{}".format(roll_message, roll_log)) except ( ValueError, NotImplementedError, pyhedrals.InvalidOperandsException, pyhedrals.SyntaxErrorException, pyhedrals.UnknownCharacterException, ) as exception: await ctx.send( error( "{}, I couldn't parse your dice formula:\n`{}`".format( ctx.message.author.mention, str(exception) ) ) )
import logging import random from collections import Counter import discord import pyhedrals client = discord.Client() dispatch = {} roller = pyhedrals.DiceRoller() RED_DICE = [ "<:diered1:552828733430693898>", "<:diered2:552828733354934278>", "<:diered3:552828733451403265>", "<:diered4:552828733594271792>", "<:diered5:552828733782884362>", "<:diered6:552828733787078656>", ] PURPLE_DICE = [ "<:diepurple1:552828732998418459>", "<:diepurple2:552828733841473536>", "<:diepurple3:552828734311497748>", "<:diepurple4:552828733426237441>", "<:diepurple5:552828733036167190>", "<:diepurple6:552828733485219840>", ] def register(fn):
def onLoad(self): self.roller = dice.DiceRoller()