From 3c4d99f506c3a1cb50ef9c8d92d1c74f35e9ff26 Mon Sep 17 00:00:00 2001 From: daJu Date: Fri, 19 Jun 2020 01:32:13 +0200 Subject: [PATCH] [somebot] /roll --- somebot/modules/CommandRollDice.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 somebot/modules/CommandRollDice.py diff --git a/somebot/modules/CommandRollDice.py b/somebot/modules/CommandRollDice.py new file mode 100644 index 0000000..498857f --- /dev/null +++ b/somebot/modules/CommandRollDice.py @@ -0,0 +1,30 @@ +# Mattermost APIv4 Bot. +# written 2019 by Ju +# essential feedback by frunobulax + +from random import randint +import re + + +from AbstractCommand import * +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("^([1-9]|[1-9][0-9]|100)$", data["text"]): + msg = "Rolling a d" + data["text"] + ": " + str(randint(1, int(data["text"]))) + elif re.search("^([1-9])[d]([1-9]|[1-9][0-9]|100)$", data["text"]): + msg = "Rolling a d" + re.findall("\d+", data["text"])[1] + " " + re.findall("\d+", data["text"])[0] + " times: " + for x in range(int(re.findall("\d+", data["text"])[0])): + msg = msg + str(randint(1, int(re.findall("\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