From aadfe05a71e23374a4d09ebc80b07914908289e4 Mon Sep 17 00:00:00 2001 From: Thorsten Date: Thu, 29 Jul 2021 18:57:28 +0200 Subject: [PATCH] d20 --- distbot/plugins/basic.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/distbot/plugins/basic.py b/distbot/plugins/basic.py index 8df04f3..e5e05a9 100644 --- a/distbot/plugins/basic.py +++ b/distbot/plugins/basic.py @@ -47,6 +47,37 @@ class Dice(Worker): return Action(msg=answer) +class Dice20(Worker): + binding_keys = ['nick.d20.#'] + description = "rolls a 20 faced dice, optionally up to 5 times" + usage = "bot: d20 " + + def __init__(self, actionqueue): + super(Dice20, self).__init__(actionqueue=actionqueue) + + def parse_body(self, msg): + words = get_words(msg) + nick = get_nick_from_message(msg) + num_dice = 1 + if len(words) > 1 and int(words[1]): + num_dice = int(words[1]) + if not (0 < num_dice < 6): + return Action(msg="invalid argument (only up to 5 dices at once)") + + dices = [] + for dice in range(num_dice): + if nick in config.conf_get('plugins.dice.enhanced-random-user'): + rnd = 0 + else: + rnd = random.randint(1, 20) + dices.append(" {}".format(rnd)) + + answer = 'rolling %s for %s:' % ( + 'a dice' if 1 == num_dice else '%d dices' % num_dice, nick + ) + ' '.join(dices) + return Action(msg=answer) + + class Ping(Worker): binding_keys = ["nick.ping"] description = "pong" -- 2.39.2