[somebot] /randomfood
authorSomeone <someone@somenet.org>
Wed, 8 Dec 2021 18:38:38 +0000 (19:38 +0100)
committerSomeone <someone@somenet.org>
Wed, 8 Dec 2021 18:38:38 +0000 (19:38 +0100)
modules/CommandRandomFoodSource.py [new file with mode: 0644]

diff --git a/modules/CommandRandomFoodSource.py b/modules/CommandRandomFoodSource.py
new file mode 100644 (file)
index 0000000..976f0ef
--- /dev/null
@@ -0,0 +1,25 @@
+# Mattermost Bot module.
+#  Copyright (c) 2016-2021 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
+#  published under MIT-License
+
+import random
+
+
+from AbstractCommand import AbstractCommand
+class CommandRandomFoodSource(AbstractCommand):
+    TRIGGER = "randomFood"
+    CONFIG = {"display_name": "somebot-command", "auto_complete": True,
+              "auto_complete_hint":  "",
+             }
+    USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Suggest a random food source."
+
+
+    def __init__(self, team_id, channel_id):
+        super().__init__(team_id)
+        self.channel_id = channel_id
+
+
+    def on_POST(self, request, data):
+        pinned_posts = self.bot.api.get_channel_posts_pinned(self.channel_id)["posts"]
+        rnd_post_url = ":arrow_right: https://mattermost.fsinf.at/fsinf/pl/"+random.choice(list(pinned_posts.keys()))
+        request.cmd_respond_text_temp("# You eat here\n"+rnd_post_url)