Protect against some sorts of throws
This commit is contained in:
parent
50e1acc8fc
commit
d815b27ce9
1 changed files with 15 additions and 9 deletions
24
roller.py
24
roller.py
|
|
@ -114,25 +114,31 @@ class Roller:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def throw(amount, sides):
|
def throw(amount, sides):
|
||||||
results = [random.randint(1, sides) for _ in range(amount)]
|
if 0 < amount <= 100 and 0 < sides <= 10000:
|
||||||
result = sum(results)
|
results = [random.randint(1, sides) for _ in range(amount)]
|
||||||
resultstr = "(" + "+".join(str(r) for r in results) + ")"
|
result = sum(results)
|
||||||
|
resultstr = "(" + "+".join(str(r) for r in results) + ")"
|
||||||
|
else:
|
||||||
|
result = 0
|
||||||
|
resultstr = "[invalid throw]"
|
||||||
return result, resultstr
|
return result, resultstr
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def advantage(dis, amount, sides):
|
def advantage(dis, amount, sides):
|
||||||
results = [random.randint(1, sides) for _ in range(amount)]
|
if 0 < amount <= 100 and 0 < sides <= 10000:
|
||||||
result = min(results) if dis else max(results)
|
results = [random.randint(1, sides) for _ in range(amount)]
|
||||||
resultstr = "(" + ",".join(str(r) for r in results) + ")"
|
result = min(results) if dis else max(results)
|
||||||
resultstr = ("d" if dis else "a") + resultstr
|
resultstr = "(" + ",".join(str(r) for r in results) + ")"
|
||||||
|
resultstr = ("d" if dis else "a") + resultstr
|
||||||
|
else:
|
||||||
|
result = 0
|
||||||
|
resultstr = "[invalid throw]"
|
||||||
return result, resultstr
|
return result, resultstr
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def number(number):
|
def number(number):
|
||||||
return number, str(number)
|
return number, str(number)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RollerBot(yaboli.Bot):
|
class RollerBot(yaboli.Bot):
|
||||||
SHORT_HELP = Roller.SHORT_DESCRIPTION
|
SHORT_HELP = Roller.SHORT_DESCRIPTION
|
||||||
LONG_HELP = Roller.DESCRIPTION + Roller.COMMANDS + "\n" + Roller.SYNTAX + "\n" + Roller.EXAMPLES + "\n" + Roller.AUTHOR + Roller.CREDITS
|
LONG_HELP = Roller.DESCRIPTION + Roller.COMMANDS + "\n" + Roller.SYNTAX + "\n" + Roller.EXAMPLES + "\n" + Roller.AUTHOR + Roller.CREDITS
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue