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