From a46fd4a82cf7b2ff010c937e7fb43d78029bf59f Mon Sep 17 00:00:00 2001 From: Someone Date: Fri, 19 Jun 2020 01:32:13 +0200 Subject: [PATCH] [somebot] /randomfood --- somebot/modules/CommandRandomFoodSource.py | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 somebot/modules/CommandRandomFoodSource.py diff --git a/somebot/modules/CommandRandomFoodSource.py b/somebot/modules/CommandRandomFoodSource.py new file mode 100644 index 0000000..c9840ab --- /dev/null +++ b/somebot/modules/CommandRandomFoodSource.py @@ -0,0 +1,26 @@ +# Mattermost Bot. +# Copyright (c) 2016-2020 by Someone (aka. Jan Vales ) +# published under MIT-License + +import random + + +from AbstractCommand import * +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) + -- 2.43.0