]> git.somenet.org - pub/jan/mattermost-bot.git/blob - core/CoreCommandUse.py
config.py.example
[pub/jan/mattermost-bot.git] / core / CoreCommandUse.py
1 # Mattermost Bot.
2 #  Copyright (c) 2016-2022 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
3 #  inspired by @bearza
4 #  published under MIT-License
5
6
7 from inspect import cleandoc
8
9 # pylint: disable=wrong-import-position
10 from AbstractCommand import AbstractCommand
11 class CoreCommandUse(AbstractCommand):
12     TRIGGER = "use"
13     CONFIG = {"display_name": "somebot-command", "auto_complete": True,
14               "auto_complete_hint": "[<feature>]",
15              }
16     CONFIG["auto_complete_desc"] = CONFIG["description"] = AbstractCommand.ICON_PUBLIC+"Display a hint (how) to use a feature."
17     USEINFO = cleandoc("""
18         ``/use [<topic>]`` can be used to retrieve information about features this :mattermost: and/or :robot: instance offers.
19         It can also be used to hint somebody that they are not using a commonly used feature (correctly). :)
20         """)
21
22     TOPICS = {
23         "latex": cleandoc("""
24             Mattermost supports TeX math:
25             ``````
26             ```tex
27             g_2(n) = n^2 \\cdot \\sqrt[3]{n^6 - 1}
28             ```
29             ``````
30
31             ```tex
32             g_2(n) = n^2 \\cdot \\sqrt[3]{n^6 - 1}
33             ```
34             """),
35         "threads": cleandoc("""
36             Mattermost supports threads. They make communication way more overseeable and structured.
37             We all <3 to use threads. You too, even if you dont know it yet. :)
38             You can open the thread-view with shift+up or by clicking the small arrow to the right on a post.
39             If you see a repeated offender, consider using ``/use threads`` or ``/threads`` with its many parameters.
40             """),
41     }
42
43
44     def on_register(self):
45         self.bot.USETOPICS.update(self.TOPICS)
46         self._create_slash_command()
47
48
49     def on_POST(self, request, data):
50         topic = data["text"].strip()
51
52         if topic == "debug":
53             import pprint
54             pprint.pprint(self.bot.USETOPICS)
55             request.respond_cmd_chan("Debug info dumped to stdout.")
56
57         elif topic == "":
58             msg = "``\n+ ``/use ".join(list(sorted(self.bot.USETOPICS.keys())))
59             request.respond_cmd_chan("#### ``Did you know...``\nYou can use ``/use <topic>`` to display a helpful message about a feature of this instance. Known topics are:\n+ ``/use "+msg+"``")
60
61         elif topic not in self.bot.USETOPICS:
62             request.respond_cmd_chan("#### Did you know that this bot doesnt know anything about: ``"+topic+"``?\nIf this is important, contact @someone")
63
64         else:
65             request.respond_cmd_chan("#### ``Did you know...``\n"+self.bot.USETOPICS[topic]+"\n``/use "+topic+"``")