Update DiceObserver.py

Exception handling
This commit is contained in:
ThomasWeis
2022-04-20 17:27:33 +02:00
parent 340f201882
commit 02308bf5d7

View File

@@ -27,8 +27,16 @@ class DiceObserver(PrivMsgObserverPrototype):
dice_sides = (data['message'].split(' ')[found_at_index + 1]) dice_sides = (data['message'].split(' ')[found_at_index + 1])
if dice_sides.isdigit(): if dice_sides.isdigit():
dice_sides = int(dice_sides) dice_sides = int(dice_sides)
if dice_sides == 0:
connection.send_back(data['nick'] + ' wirft einen 0-seitigen Würfel und bekommt Unendlich.', data)
return
elif dice_sides < 0:
connection.send_back(data['nick'] + ' wirft einen ' + str(dice_sides) + '-seitigen Würfel und nichts passiert.', data)
return
else: else:
dice_sides = 6 dice_sides = 6
result = random.randint(1, dice_sides) result = random.randint(1, dice_sides)
connection.send_back(data['nick'] + ' wirft einen ' + str(dice_sides) + '-seitigen Würfel und bekommt ' + str(result), data) connection.send_back(data['nick'] + ' wirft einen ' + str(dice_sides) + '-seitigen Würfel und bekommt ' + str(result), data)