]> git.somenet.org - pub/jan/mattermost-bot.git/blob - modules/CommandDSACheck.py
modules/TACommandWipeChannel.py
[pub/jan/mattermost-bot.git] / modules / CommandDSACheck.py
1 # Mattermost Bot module.
2 #  Copyright (c) 2021 by @top_left <gisilfrid@protonmail.com>
3 #  published under MIT-License
4
5 from random import randint
6 import re
7 import math
8
9
10 # pylint: disable=wrong-import-position
11 from AbstractCommand import AbstractCommand
12 class CommandDSACheck(AbstractCommand):
13     TRIGGER = "dsacheck"
14     CONFIG = {"display_name": "somebot-command", "auto_complete": True,
15               "auto_complete_hint": "n [n n] [(+|-)b] [m]",
16              }
17     USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = AbstractCommand.ICON_PUBLIC+"Directly do an attribute or skill check, optionally with modifications and skill points"
18
19
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)
25             modification = 0
26             if len(tokens) == 1:
27                 msg += ":\n"
28             else:
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"
35             elif throw == 1:
36                 msg += "Critical Success"
37             elif throw == 20:
38                 msg += "Botched"
39             elif throw <= modified_attribute:
40                 msg += "Success ({})".format(throw)
41             else:
42                 msg += "Failed ({})".format(throw)
43
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]
47             tokens = tokens[3:]
48             msg = "Checking for {}".format(attributes)
49
50             modification = 0
51             if len(tokens) > 0 and (tokens[0][0] == "+" or tokens[0][0] == "-"):
52                 modification = int(tokens[0])
53                 tokens = tokens[1:]
54                 msg += " modified by {}".format(modification)
55
56             skill_points = 0
57             if len(tokens) > 0:
58                 skill_points = int(tokens[0])
59                 msg += " with {} skill points".format(skill_points)
60
61             msg += ":\n"
62
63             attributes = [int(attribute) + modification for attribute in attributes]
64             if any(attribute < 1 for attribute in attributes):
65                 msg += "Failed, attribute below 1"
66             else :
67                 success = True
68                 throws = []
69                 for attribute in attributes:
70                     throw = randint(1, 20)
71                     throws.append(throw)
72                     if attribute + skill_points < throw:
73                         success = False
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])
78                 if ones == 2:
79                     msg += "Critical Success"
80                 elif ones == 3:
81                     msg += "Spectacular Success"
82                 elif twenties == 2:
83                     msg += "Botched"
84                 elif twenties == 3:
85                     msg += "Botched spectacularly"
86                 elif not success:
87                     msg += "Failure ({})".format(throws)
88                 else:
89                     quality_level = math.ceil(skill_points / 3)
90                     if quality_level == 0:
91                         quality_level = 1
92                     msg += "Success ({}), QS: {}".format(throws, quality_level)
93
94         else:
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.")
96             return
97
98         request.respond_cmd_chan(msg)