1 # Mattermost APIv4 Bot.
2 # written 2019 by Ju <daju@fsinf.at>
3 # essential feedback by frunobulax
5 from random import randint
9 from AbstractCommand import AbstractCommand
10 class CommandRollDice(AbstractCommand):
12 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
13 "auto_complete_hint": "[n or ndm]",
15 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Roll dice n [n] or n dices m times [ndm]."
18 def on_POST(self, request, data):
19 if re.search(r"^([1-9]|[1-9][0-9]|100)$", data["text"]):
20 msg = "Rolling a d" + data["text"] + ": " + str(randint(1, int(data["text"])))
21 elif re.search(r"^([1-9])[d]([1-9]|[1-9][0-9]|100)$", data["text"]):
22 msg = "Rolling a d" + re.findall(r"\d+", data["text"])[1] + " " + re.findall(r"\d+", data["text"])[0] + " times: "
23 for x in range(int(re.findall(r"\d+", data["text"])[0])):
24 msg = msg + str(randint(1, int(re.findall(r"\d+", data["text"])[1]))) + ", "
27 request.cmd_respond_text_temp("Zulässige Parameter sind: 'n' oder 'ndm' wobei n [1-9] und m [1-100] Zahlen sind.")
30 request.cmd_respond_text_chan(msg)