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