]> git.aero2k.de Git - urlbot-v3.git/commitdiff
d20
authorThorsten <mail@aero2k.de>
Thu, 29 Jul 2021 16:57:28 +0000 (18:57 +0200)
committerThorsten <mail@aero2k.de>
Thu, 29 Jul 2021 16:57:28 +0000 (18:57 +0200)
distbot/plugins/basic.py

index 8df04f37c1cab7795f220f852fce3228dffcf479..e5e05a9b4dfb4bee9ee18f192bb26ceeeb46cc36 100644 (file)
@@ -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 <times>"
+
+    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"