making the roll method nicer, now supports addition and splits on d
This commit is contained in:
parent
e4a9cb8378
commit
2137f1c159
18
app/dice.py
18
app/dice.py
@ -4,7 +4,7 @@ from random import randint
|
||||
def roll_logic(sides):
|
||||
return randint(1, sides)
|
||||
|
||||
def roll(number_of_die, sides):
|
||||
def roll(number_of_die, sides, number_to_add=None):
|
||||
results = list(tuple(roll_logic(int(sides)) for _ in range(int(number_of_die))))
|
||||
|
||||
# blue
|
||||
@ -21,9 +21,19 @@ def roll(number_of_die, sides):
|
||||
|
||||
embed = discord.Embed(description=None, color=embed_color, type="rich")
|
||||
embed.set_author(name="Rolling %s %s sided die" % (number_of_die, sides))
|
||||
embed.add_field(name="**Total**", value=":game_die: %s" % results)
|
||||
embed.add_field(name="**Total**", value=sum(results))
|
||||
embed.add_field(name='Rolls', value=results, inline=False)
|
||||
if number_to_add:
|
||||
embed.add_field(name="**Total**", value=":game_die: %s+%s = %s" % (sum(results), number_to_add, (sum(results) + number_to_add)), inline=False)
|
||||
else:
|
||||
embed.add_field(name="**Total**", value=":game_die: %s" % sum(results), inline=False)
|
||||
return embed
|
||||
|
||||
def parse_message(message):
|
||||
return roll(message.split()[1], message.split()[2])
|
||||
message = ' '.join(message.split()[1:])
|
||||
if '+' in message:
|
||||
try:
|
||||
number_to_add = int(message.split('+')[-1])
|
||||
return roll(message.split('d')[0], message.split('d')[1].split('+')[0], number_to_add)
|
||||
except ValueError:
|
||||
return "Could not add %s to the total roll"
|
||||
return roll(message.split('d')[0], message.split('d')[1])
|
||||
|
@ -129,8 +129,10 @@ def get_help_message(method):
|
||||
'Usage: !quake <player name>'
|
||||
],
|
||||
'roll': [
|
||||
'Rolls N number of Y sided die\n'
|
||||
'Usage: !roll 3 20'
|
||||
'Rolls N number of Y sided die\n',
|
||||
'Usage: !roll 3d20\n',
|
||||
'You can also add a modifier on the end with a +',
|
||||
'Usage: !roll 2d20+5'
|
||||
],
|
||||
'smug': [
|
||||
'Returns the URL for smug anime girl'
|
||||
|
Loading…
x
Reference in New Issue
Block a user