--- /dev/null
+# 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)