1 # Mattermost Bot module.
2 # Copyright (c) 2021 by @top_left <gisilfrid@protonmail.com>
3 # published under MIT-License
5 from random import randint
10 # pylint: disable=wrong-import-position
11 from AbstractCommand import AbstractCommand
12 class CommandDSACheck(AbstractCommand):
14 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
15 "auto_complete_hint": "n [n n] [(+|-)b] [m]",
17 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = AbstractCommand.ICON_PUBLIC+"Directly do an attribute or skill check, optionally with modifications and skill points"
20 def on_POST(self, request, data):
21 if re.search(r"^\d{1,2}( \+\d{1,3}| -\d{1,3})?$", data["text"]):
22 tokens = data["text"].split(" ")
23 attribute = int(tokens[0])
24 msg = "Checking for {}".format(attribute)
29 modification = int(tokens[1])
30 msg += " modified by {}:\n".format(modification)
31 throw = randint(1, 20)
32 modified_attribute = attribute + modification
33 if modified_attribute <= 0:
34 msg += "Failed, attribute below 1"
36 msg += "Critical Success"
39 elif throw <= modified_attribute:
40 msg += "Success ({})".format(throw)
42 msg += "Failed ({})".format(throw)
44 elif re.search(r"^\d{1,2} \d{1,2} \d{1,2}( \+\d{1,3}| -\d{1,3})?( \d{1,3})?$", data["text"]):
45 tokens = data["text"].split(" ")
46 attributes = tokens[:3]
48 msg = "Checking for {}".format(attributes)
51 if len(tokens) > 0 and (tokens[0][0] == "+" or tokens[0][0] == "-"):
52 modification = int(tokens[0])
54 msg += " modified by {}".format(modification)
58 skill_points = int(tokens[0])
59 msg += " with {} skill points".format(skill_points)
63 attributes = [int(attribute) + modification for attribute in attributes]
64 if any(attribute < 1 for attribute in attributes):
65 msg += "Failed, attribute below 1"
69 for attribute in attributes:
70 throw = randint(1, 20)
72 if attribute + skill_points < throw:
74 elif attribute < throw:
75 skill_points -= throw - attribute
76 ones = len([throw for throw in throws if throw == 1])
77 twenties = len([throw for throw in throws if throw == 20])
79 msg += "Critical Success"
81 msg += "Spectacular Success"
85 msg += "Botched spectacularly"
87 msg += "Failure ({})".format(throws)
89 quality_level = math.ceil(skill_points / 3)
90 if quality_level == 0:
92 msg += "Success ({}), QS: {}".format(throws, quality_level)
95 request.respond_cmd_err("``/"+self.TRIGGER+"`` Possible invocations are either m [(+|-)b] or m n o [(+|-)b] [x] where n, m, o is between 1 and 99 and b and x can be any integers between -999 and 999.")
98 request.respond_cmd_chan(msg)