From 26f9e6501f8611e8546bafc6a5e6b7c162795cee Mon Sep 17 00:00:00 2001 From: Anton Oellerer Date: Wed, 8 Dec 2021 19:38:38 +0100 Subject: [PATCH] [somebot.] /dsacheck --- modules/CommandDSACheck.py | 99 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 modules/CommandDSACheck.py diff --git a/modules/CommandDSACheck.py b/modules/CommandDSACheck.py new file mode 100644 index 0000000..2b856e2 --- /dev/null +++ b/modules/CommandDSACheck.py @@ -0,0 +1,99 @@ +# Mattermost Bot module. +# Copyright (c) 2021 by @top_left +# published under MIT-License + +from random import randint +import re +import math + +from AbstractCommand import * + +class CommandDSACheck(AbstractCommand): + TRIGGER = "dsacheck" + CONFIG = {"display_name": "somebot-command", "auto_complete": True, + "auto_complete_hint": "n [n n] [(+|-)b] [m]", + } + USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Directly do an attribute or skill check, optionally with modifications and skill points" + + + def on_POST(self, request, data): + if re.search(r"^\d{1,2}( \+\d{1,3}| -\d{1,3})?$", data["text"]): + tokens = data["text"].split(" ") + attribute = int(tokens[0]) + msg = "Checking for {}".format(attribute) + modification = 0 + if len(tokens) == 1: + msg += ":\n" + else: + modification = int(tokens[1]) + msg += " modified by {}:\n".format(modification) + throw = randint(1, 20) + modified_attribute = attribute + modification + if modified_attribute <= 0: + msg += "Failed, attribute below 1" + elif throw == 1: + msg += "Critical Success" + elif throw == 20: + msg += "Botched" + elif throw <= modified_attribute: + msg += "Success ({})".format(throw) + else: + msg += "Failed ({})".format(throw) + + elif re.search(r"^\d{1,2} \d{1,2} \d{1,2}( \+\d{1,3}| -\d{1,3})?( \d{1,3})?$", data["text"]): + tokens = data["text"].split(" ") + attributes = tokens[:3] + tokens = tokens[3:] + msg = "Checking for {}".format(attributes) + + modification = 0 + if len(tokens) > 0 and (tokens[0][0] == "+" or tokens[0][0] == "-"): + modification = int(tokens[0]) + tokens = tokens[1:] + msg += " modified by {}".format(modification) + + skill_points = 0 + if len(tokens) > 0: + skill_points = int(tokens[0]) + msg += " with {} skill points".format(skill_points) + + msg += ":\n" + + attributes = [int(attribute) + modification for attribute in attributes] + if any(attribute < 1 for attribute in attributes): + msg += "Failed, attribute below 1" + else : + success = True + throws = [] + for attribute in attributes: + throw = randint(1, 20) + throws.append(throw) + if attribute + skill_points < throw: + success = False + elif attribute < throw: + skill_points -= throw - attribute + ones = len([throw for throw in throws if throw == 1]) + twenties = len([throw for throw in throws if throw == 20]) + if ones == 2: + msg += "Critical Success" + elif ones == 3: + msg += "Spectacular Success" + elif twenties == 2: + msg += "Botched" + elif twenties == 3: + msg += "Botched spectacularly" + elif not success: + msg += "Failure ({})".format(throws) + else: + quality_level = math.ceil(skill_points / 3) + if quality_level == 0: + quality_level = 1 + msg += "Success ({}), QS: {}".format(throws, quality_level) + + else: + request.cmd_respond_text_temp( + "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 " + ) + return + + request.cmd_respond_text_chan(msg) -- 2.43.0