From 31ceab8ddb0dc2aefc63db342ccb1b87edb77d43 Mon Sep 17 00:00:00 2001
From: daJu <daju@fsinf.at>
Date: Wed, 8 Dec 2021 19:38:38 +0100
Subject: [PATCH] [somebot.] /roll

---
 modules/CommandRollDice.py | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 modules/CommandRollDice.py

diff --git a/modules/CommandRollDice.py b/modules/CommandRollDice.py
new file mode 100644
index 0000000..3ab7ac2
--- /dev/null
+++ b/modules/CommandRollDice.py
@@ -0,0 +1,30 @@
+# Mattermost APIv4 Bot.
+# written 2019 by Ju <daju@fsinf.at>
+# essential feedback by frunobulax
+
+from random import randint
+import re
+
+
+from AbstractCommand import AbstractCommand
+class CommandRollDice(AbstractCommand):
+    TRIGGER = "roll"
+    CONFIG = {"display_name": "somebot-command", "auto_complete": True,
+              "auto_complete_hint": "[n or ndm]",
+             }
+    USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Roll dice n [n] or n dices m times [ndm]."
+
+
+    def on_POST(self, request, data):
+        if re.search(r"^([1-9]|[1-9][0-9]|100)$", data["text"]):
+            msg = "Rolling a d" + data["text"] + ": " + str(randint(1, int(data["text"])))
+        elif re.search(r"^([1-9])[d]([1-9]|[1-9][0-9]|100)$", data["text"]):
+            msg = "Rolling a d" + re.findall(r"\d+", data["text"])[1] + " " + re.findall(r"\d+", data["text"])[0] + " times: "
+            for x in range(int(re.findall(r"\d+", data["text"])[0])):
+                msg = msg + str(randint(1, int(re.findall(r"\d+", data["text"])[1]))) + ", "
+            msg = msg[:-2]
+        else:
+            request.cmd_respond_text_temp("Zulässige Parameter sind: 'n' oder 'ndm' wobei n [1-9] und m [1-100] Zahlen sind.")
+            return
+
+        request.cmd_respond_text_chan(msg)
-- 
2.43.0