]> git.somenet.org - pub/jan/mattermost.git/blob - somebot/modules/CommandRollDice.py
[somebot/modules/] DialogManagedCoronaLVAFeedback.
[pub/jan/mattermost.git] / somebot / modules / CommandRollDice.py
1 # Mattermost APIv4 Bot.
2 # written 2019 by Ju <daju@fsinf.at>
3 # essential feedback by frunobulax
4
5 from random import randint
6 import re
7
8
9 from AbstractCommand import *
10 class CommandRollDice(AbstractCommand):
11     TRIGGER = "roll"
12     CONFIG = {"display_name": "somebot-command", "auto_complete": True,
13         "auto_complete_hint": "[n or ndm]",
14     }
15     USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Roll dice n [n] or n dices m times [ndm]."
16
17
18     def on_POST(self, request, data):
19         if re.search("^([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("^([1-9])[d]([1-9]|[1-9][0-9]|100)$", data["text"]):
22             msg = "Rolling a d" + re.findall("\d+", data["text"])[1] + " " + re.findall("\d+", data["text"])[0] + " times: "
23             for x in range(int(re.findall("\d+", data["text"])[0])):
24                 msg = msg + str(randint(1, int(re.findall("\d+", data["text"])[1]))) + ", "
25             msg = msg[:-2]
26         else:
27             request.cmd_respond_text_temp("Zulässige Parameter sind: 'n' oder 'ndm' wobei n [1-9] und m [1-100] Zahlen sind.")
28             return
29
30         request.cmd_respond_text_chan(msg)