From 5b3a8ef23d0de848f00e0e36bff1cbace7e5b049 Mon Sep 17 00:00:00 2001 From: Someone Date: Wed, 8 Dec 2021 19:38:38 +0100 Subject: [PATCH] [somebot] /use --- core/CoreCommandUse.py | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 core/CoreCommandUse.py diff --git a/core/CoreCommandUse.py b/core/CoreCommandUse.py new file mode 100644 index 0000000..90e4187 --- /dev/null +++ b/core/CoreCommandUse.py @@ -0,0 +1,64 @@ +# Mattermost Bot. +# Copyright (c) 2016-2021 by Someone (aka. Jan Vales ) +# inspired by @bearza +# published under MIT-License + + +from inspect import cleandoc + +from AbstractCommand import AbstractCommand +class CoreCommandUse(AbstractCommand): + TRIGGER = "use" + CONFIG = {"display_name": "somebot-command", "auto_complete": True, + "auto_complete_hint": "[]", + } + CONFIG["auto_complete_desc"] = CONFIG["description"] = "Display a hint (how) to use a feature." + USEINFO = cleandoc(""" + ``/use []`` can be used to retrieve information about features this :mattermost: and/or :robot: instance offers. + It can also be used to hint somebody that they are not using a commonly used feature (correctly). :) + """) + + TOPICS = { + "latex": cleandoc(""" + Mattermost supports TeX math: + `````` + ```tex + g_2(n) = n^2 \\cdot \\sqrt[3]{n^6 - 1} + ``` + `````` + + ```tex + g_2(n) = n^2 \\cdot \\sqrt[3]{n^6 - 1} + ``` + """), + "threads": cleandoc(""" + Mattermost supports threads. They make communication way more overseeable and structured. + We all <3 to use threads. You too, even if you dont know it yet. :) + You can open the thread-view with shift+up or by clicking the small arrow to the right on a post. + If you see a repeated offender, consider using ``/use threads`` or ``/threads`` with its many parameters. + """), + } + + + def on_register(self): + self.bot.USETOPICS.update(self.TOPICS) + self._create_slash_command() + + + def on_POST(self, request, data): + topic = data["text"].strip() + + if topic == "debug": + import pprint + pprint.pprint(self.bot.USETOPICS) + request.cmd_respond_text_chan("Debug info dumped to stdout.") + + elif topic == "": + msg = "``\n+ ``/use ".join([t for t in sorted(self.bot.USETOPICS.keys())]) + request.cmd_respond_text_chan("#### ``Did you know...``\nYou can use ``/use `` to display a helpful message about a feature of this instance. Known topics are:\n+ ``/use "+msg+"``") + + elif topic not in self.bot.USETOPICS: + request.cmd_respond_text_chan("#### Did you know that this bot doesnt know anything about: ``"+topic+"``?\nIf this is important, contact @someone") + + else: + request.cmd_respond_text_chan("#### ``Did you know...``\n"+self.bot.USETOPICS[topic]+"\n``/use "+topic+"``") -- 2.43.0