dice roll
This commit is contained in:
+56
-2
@@ -346,8 +346,62 @@ class Shitpost(object):
|
|||||||
else:
|
else:
|
||||||
yield from ctx.channel.send(ctx.author.mention + ' Het is nu ' + datetime.now().strftime('%H:%M'))
|
yield from ctx.channel.send(ctx.author.mention + ' Het is nu ' + datetime.now().strftime('%H:%M'))
|
||||||
|
|
||||||
#Used by function weer()
|
|
||||||
|
@commands.command(pass_context=True)
|
||||||
|
@asyncio.coroutine
|
||||||
|
def roll(self, ctx, dice="1d20", modifier1="", modifier2=""):
|
||||||
|
"""Roll een dobbelsteen. Of een paar. Bijvoorbeeld:
|
||||||
|
!roll 4d20
|
||||||
|
!roll 1d6 + 5
|
||||||
|
"""
|
||||||
|
diceSplit = dice.lower().split('d')
|
||||||
|
if len(diceSplit) != 2:
|
||||||
|
return
|
||||||
|
modifier1 = modifier1.replace("+", "") #this is both possible: "1d20 + 1" and "1d20 +1"
|
||||||
|
modifier2 = modifier2.replace("+", "")
|
||||||
|
if modifier1 == "-":
|
||||||
|
modifier1 = ""; #this is also possible: "1d20 - 1"
|
||||||
|
modifier2 = "-" + modifier2
|
||||||
|
try: #check if they are numbers:
|
||||||
|
nrOfDice = 1 if (diceSplit[0]=="") else int(diceSplit[0]) #allow input like: "!roll d20"
|
||||||
|
dieType = int(diceSplit[1])
|
||||||
|
mod1 = 0 if (modifier1=="") else int(modifier1)
|
||||||
|
mod2 = 0 if (modifier2=="") else int(modifier2)
|
||||||
|
except ValueError:
|
||||||
|
return
|
||||||
|
#validate values:
|
||||||
|
if nrOfDice < 1 or nrOfDice > 99 or dieType < 2 or dieType > 100:
|
||||||
|
return
|
||||||
|
if mod1 < -999 or mod1 > 999 or mod2 < -999 or mod2 > 999:
|
||||||
|
return
|
||||||
|
|
||||||
|
#roll:
|
||||||
|
random.seed(datetime.now())
|
||||||
|
total = 0
|
||||||
|
returnText = "Rolling " + str(nrOfDice) + "d" + str(dieType) + "...\n"
|
||||||
|
for x in range(0, nrOfDice):
|
||||||
|
if x != 0:
|
||||||
|
returnText += "+ "
|
||||||
|
roll = random.randint(1, dieType)
|
||||||
|
total += roll
|
||||||
|
if dieType >= 10 and (roll == 1 or roll == dieType):
|
||||||
|
returnText += "[**" + str(roll) + "**] " #make significant numbers bold
|
||||||
|
else:
|
||||||
|
returnText += "[" + str(roll) + "] "
|
||||||
|
total += mod1 + mod2
|
||||||
|
if mod1 != 0:
|
||||||
|
if mod1 > 0:
|
||||||
|
returnText += "+"
|
||||||
|
returnText += str(mod1) + " "
|
||||||
|
if mod2 != 0:
|
||||||
|
if mod2 > 0:
|
||||||
|
returnText += "+"
|
||||||
|
returnText += str(mod2) + " "
|
||||||
|
if nrOfDice > 1 or mod1 != 0 or mod2 != 0: #only show calculation if it makes sense:
|
||||||
|
returnText += " = __**" + str(total) + "**__"
|
||||||
|
|
||||||
|
yield from ctx.channel.send(returnText)
|
||||||
|
|
||||||
|
|
||||||
@commands.command(pass_context=True)
|
@commands.command(pass_context=True)
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
|||||||
Reference in New Issue
Block a user