def get_nescafe(): result = "" result1, expl1 = rolldice.roll_dice('1d4') if result1 == 1: result += "**NESCAFÉ 3 в 1 Классический**" elif result1 == 2: result += "**NESCAFÉ 3 в 1 Крепкий**" elif result1 == 3: result += "**NESCAFÉ 3 в 1 Мягкий**" else: result += "**NESCAFÉ 3 в 1 Карамельный**" result1, expl1 = rolldice.roll_dice('1d5') if result1 == 1: result += "\nВ ледяной воде." elif result1 == 2: result += "\nВ прохладной воде." elif result1 == 3: result += "\nВ тёплой воде." elif result1 == 4: result += "\nВ горячей воде." else: result += "\nВ кипятке." result1, expl1 = rolldice.roll_dice('1d4') if result1 == 1: result += "\nНифига не растворилось." elif result1 == 2: result += "\nПлохо растворилось." elif result1 == 3: result += "\nХорошо растворилось." elif result1 == 4: result += "\nИдеально растворилось." if rolldice.roll_dice('1d10')[0] < 3: result += "\nС плевком в стакан." return result
def roll_attributes(method: str): """roll attributes and provides a score""" output = [] die = "3d6" nscores = 6 if method == "inorder+": die = '4d6K3' elif method == "ve": die = "3d6" nscores = 7 elif method == "heroic": die = '4d6K3' nscores = 7 for _ in range(nscores): result, explanation = rolldice.roll_dice(die) output += [{ "score": result, "details": explanation.replace("~~", " ▾") }] scores = [int(row['score']) for row in output] count = sum(map(lambda x: x < 9, scores)) score = 0 if count < 2: score = sum(scores) if len(output) > 6: output = sorted(output, key=lambda k: int(k['score']), reverse=True) score = score - int(output[-1]['score']) return output, score, die
async def rollinit(ctx, name: str, bonus: int): """ Rolls initiative for a character. """ value, _ = rolldice.roll_dice("d20 + {bonus}") init.add(name, value) await ctx.send(init.get_formatted())
async def roll(self, ctx, *, arg: str = "1d20"): """Roll the specified dice or default to d20.""" die = arg try: result, explanation = rolldice.roll_dice(die) await ctx.send(f'{die} -> **{result}** <- {explanation}') except (rolldice.DiceGroupException) as err: await ctx.send(f'ERROR: {err}') logging.exception(err)
async def roll(ctx, *roll_code): """ Rolls some dice. See https://www.critdice.com/roll-advanced-dice/ for syntax. """ roll = " ".join(roll_code) mention = ctx.author.mention result, explanation = rolldice.roll_dice(roll) await ctx.send(f"{mention}\nResult: {result}\nExplanation: {explanation}")
def on_roll(self, event, dice, comment=''): try: result, explanation = rolldice.roll_dice(dice) except rolldice.DiceGroupException as e: event.msg.reply(str(e)) except rolldice.DiceOperatorException as e: event.msg.reply(str(e)) except Exception as e: event.msg.reply(str(e)) else: if comment: event.msg.reply('{} rolled *{}* \n **{}** \t`{}`'.format( str(event.msg.author)[:-5], comment, result, explanation)) else: event.msg.reply('{} rolled a dice! \n **{}** \t`{}`'.format( str(event.msg.author)[:-5], result, explanation))
def process(self, message): command_length = len(self.command) dice_str = message[command_length:] try: result, explanation = rolldice.roll_dice(dice_str) except rolldice.rolldice.DiceGroupException: self.session.send_to_client( _("That is not a valid dice expression. You can see valid expresions here: https://github.com/Fiona1729/py-rolldice#dice-syntax" )) else: self.session.send_to_room( _('{user_name} rolls {dice_str} and gets a {result} ({explanation})' ).format(user_name=self.session.user.name, dice_str=dice_str, result=result, explanation=explanation)) self.finish_interaction()
def on_coffee(self, event, param=''): try: result = "" if param.lower() == 'nescafe': result += get_nescafe() elif param.lower() == 'topping': result1, expl1 = rolldice.roll_dice('1d7') result += list(Toppings)[result1 - 1].title else: if param.lower() == 'classic': result1, expl1 = rolldice.roll_dice('1d12') elif param.lower() == 'raf': result1, expl1 = (5, 'User') else: result1, expl1 = rolldice.roll_dice('1d23') result += list(Drinks)[result1 - 1].title if result1 == 5: result2, expl2 = rolldice.roll_dice('1d22') if result2 > 19: result2, expl2 = rolldice.roll_dice('1d19') result21, expl21 = rolldice.roll_dice('1d19') result += "\n**Сиропы**: {} и {}".format( list(Syrops)[result2 - 1].title, list(Syrops)[result21 - 1].title) else: result += "\n**Сироп**: {}".format( list(Syrops)[result2 - 1].title) elif result1 == 9: result2, expl2 = rolldice.roll_dice('1d2') if result2 == 1: result += "\nТёмный" else: result += "\nМолочный" elif result1 == 12 or result1 == 19: result2, expl2 = rolldice.roll_dice('1d3') result += " {}".format(list(Teas)[result2 - 1].title) except Exception as e: event.msg.reply(str(e)) else: event.msg.reply(result)
async def dice(context, *roll): """ Command to roll dice in dice notation. See tinyurl.com/pydice :param context: Command context :param roll: Array of parts of the arguments passed to the command. Joined. :return: """ try: result, explanation = rolldice.roll_dice(''.join(roll)) except rolldice.DiceGroupException as e: await context.send(str(e)) except rolldice.DiceOperatorException as e: await context.send(str(e)) else: if len(explanation) > 300: await context.send('Result: %s\n```Explanation too long to display!```' % result) else: await context.send('Result: %s.\n```%s```' % (result, explanation))
async def dicemode(context): timed_out = False await context.send('Beginning dice rolling mode...') while True: try: msg = await client.wait_for('message', check=lambda m: m.author == context.author, timeout=6000) except asyncio.TimeoutError: break else: try: result, explanation = rolldice.roll_dice(msg.content) except: if msg.content.lower() == 'end': await context.send('Exiting dice mode.') return continue else: if len(explanation) > 300: await context.send('Result: %s\n```Explanation too long to display!```' % result) else: await context.send('Result: %s.\n```%s```' % (result, explanation))
async def roll(self, ctx, *, dice): total = 0 modification = ent_modif = "" try: result, explanation = rolldice.roll_dice("".join(dice)) explanation = explanation.replace(",", ", ") if "x" in dice: explanation, *modification = explanation.split("] ", 1) if modification: operator = re.search(r'([+|-])', str(modification).strip()) modifier = re.sub(r'[^0-9]', "", str(modification)) ent_modif = str(operator.group(1)) + str(modifier) explanation += "]" explanation = re.sub(r' ~~ ([0-9]+)', " ~~(\\1)~~", explanation).replace("]]", "]") result = re.sub(r' ~~(\([0-9]\))~~', "", explanation).strip('[]').split(', ') for i in result: total = total + int(i) result = total if ent_modif: result = eval(str(result) + ent_modif) embed = discord.Embed(colour=discord.Colour(0x5e51a8), title="Result: __" + str(result) + "__", description=str(explanation) + " " + str(modification).strip("[']")) embed.set_footer(text="Rolled " + dice) await self.bot.say(embed=embed) except rolldice.DiceGroupException as e: helper = self.bot.formatter.format_help_for( ctx, self.bot.get_command("roll")) for h in helper: em = discord.Embed( title="Format has to be NdN or NdNx or NdN+N or NdNx+N.", description=h.strip("```").replace('<', '[').replace('>', ']'), color=discord.Color.red()) em.set_footer(text=str(e)) await self.bot.say(embed=em)
def get_result(expression): ans, explanation = roll_dice(expression) return (expression, ans, explanation)
async def random_int(ctx, *, dice): await ctx.send(rolldice.roll_dice(dice)[0])