From 824000f32b696f2dcaa5fc0bcd9c1cd6469f43d7 Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Sun, 13 Aug 2017 20:36:45 -0230 Subject: [PATCH] zulip_bots: Add function to get the path to a bot's logo. This is part of our efforts to have the documentation for a particular bot live in this repo but still be able to render it in the main repo (in a way similar to how we render the webhooks docs). For the logo, if a particular bot has a logo, get_bot_logo_path expects to find it as /zulip_bots/bots/{bot_name}/logo.png or /zulip_bots/bots/{bot_name}/logo.svg. --- zulip_bots/zulip_bots/lib.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/zulip_bots/zulip_bots/lib.py b/zulip_bots/zulip_bots/lib.py index b9ea7f8..b545a5c 100644 --- a/zulip_bots/zulip_bots/lib.py +++ b/zulip_bots/zulip_bots/lib.py @@ -22,6 +22,19 @@ def exit_gracefully(signum, frame): # type: (int, Optional[Any]) -> None sys.exit(0) +def get_bot_logo_path(name): + # type: str -> Optional[str] + current_dir = os.path.dirname(os.path.abspath(__file__)) + logo_path_png = os.path.join(current_dir, 'bots/{bot_name}/logo.png') + logo_path_svg = os.path.join(current_dir, 'bots/{bot_name}/logo.svg') + + if os.path.isfile(logo_path_png): + return logo_path_png.format(bot_name=name) + elif os.path.isfile(logo_path_svg): + return logo_path_svg.format(bot_name=name) + + return None + class RateLimit(object): def __init__(self, message_limit, interval_limit): # type: (int, int) -> None