Protect against some sorts of throws

This commit is contained in:
Joscha 2018-08-08 14:55:48 +00:00
parent 50e1acc8fc
commit d815b27ce9

View file

@ -114,25 +114,31 @@ class Roller:
@staticmethod
def throw(amount, sides):
if 0 < amount <= 100 and 0 < sides <= 10000:
results = [random.randint(1, sides) for _ in range(amount)]
result = sum(results)
resultstr = "(" + "+".join(str(r) for r in results) + ")"
else:
result = 0
resultstr = "[invalid throw]"
return result, resultstr
@staticmethod
def advantage(dis, amount, sides):
if 0 < amount <= 100 and 0 < sides <= 10000:
results = [random.randint(1, sides) for _ in range(amount)]
result = min(results) if dis else max(results)
resultstr = "(" + ",".join(str(r) for r in results) + ")"
resultstr = ("d" if dis else "a") + resultstr
else:
result = 0
resultstr = "[invalid throw]"
return result, resultstr
@staticmethod
def number(number):
return number, str(number)
class RollerBot(yaboli.Bot):
SHORT_HELP = Roller.SHORT_DESCRIPTION
LONG_HELP = Roller.DESCRIPTION + Roller.COMMANDS + "\n" + Roller.SYNTAX + "\n" + Roller.EXAMPLES + "\n" + Roller.AUTHOR + Roller.CREDITS