From 5059485ed1c0cdc06c37d2fb3cbaaf408a4954b2 Mon Sep 17 00:00:00 2001 From: Someone Date: Fri, 19 Jun 2020 01:32:13 +0200 Subject: [PATCH] [somebot] /use --- somebot/core/CoreCommandUse.py | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 somebot/core/CoreCommandUse.py diff --git a/somebot/core/CoreCommandUse.py b/somebot/core/CoreCommandUse.py new file mode 100644 index 0000000..3dacf12 --- /dev/null +++ b/somebot/core/CoreCommandUse.py @@ -0,0 +1,64 @@ +# Mattermost Bot. +# Copyright (c) 2016-2020 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 features this 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