1 # Mattermost Bot module.
2 # Copyright (c) 2021 by @top_left <gisilfrid@protonmail.com>
3 # published under MIT-License
5 from random import randint
9 from AbstractCommand import *
11 class CommandDSACheck(AbstractCommand):
13 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
14 "auto_complete_hint": "n [n n] [(+|-)b] [m]",
16 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Directly do an attribute or skill check, optionally with modifications and skill points"
19 def on_POST(self, request, data):
20 if re.search(r"^\d{1,2}( \+\d{1,3}| -\d{1,3})?$", data["text"]):
21 tokens = data["text"].split(" ")
22 attribute = int(tokens[0])
23 msg = "Checking for {}".format(attribute)
28 modification = int(tokens[1])
29 msg += " modified by {}:\n".format(modification)
30 throw = randint(1, 20)
31 modified_attribute = attribute + modification
32 if modified_attribute <= 0:
33 msg += "Failed, attribute below 1"
35 msg += "Critical Success"
38 elif throw <= modified_attribute:
39 msg += "Success ({})".format(throw)
41 msg += "Failed ({})".format(throw)
43 elif re.search(r"^\d{1,2} \d{1,2} \d{1,2}( \+\d{1,3}| -\d{1,3})?( \d{1,3})?$", data["text"]):
44 tokens = data["text"].split(" ")
45 attributes = tokens[:3]
47 msg = "Checking for {}".format(attributes)
50 if len(tokens) > 0 and (tokens[0][0] == "+" or tokens[0][0] == "-"):
51 modification = int(tokens[0])
53 msg += " modified by {}".format(modification)
57 skill_points = int(tokens[0])
58 msg += " with {} skill points".format(skill_points)
62 attributes = [int(attribute) + modification for attribute in attributes]
63 if any(attribute < 1 for attribute in attributes):
64 msg += "Failed, attribute below 1"
68 for attribute in attributes:
69 throw = randint(1, 20)
71 if attribute + skill_points < throw:
73 elif attribute < throw:
74 skill_points -= throw - attribute
75 ones = len([throw for throw in throws if throw == 1])
76 twenties = len([throw for throw in throws if throw == 20])
78 msg += "Critical Success"
80 msg += "Spectacular Success"
84 msg += "Botched spectacularly"
86 msg += "Failure ({})".format(throws)
88 quality_level = math.ceil(skill_points / 3)
89 if quality_level == 0:
91 msg += "Success ({}), QS: {}".format(throws, quality_level)
94 request.cmd_respond_text_temp(
95 "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 "
99 request.cmd_respond_text_chan(msg)