From b771bacac0ff51db744e383c7aae9eda58cac3f2 Mon Sep 17 00:00:00 2001 From: rht Date: Fri, 8 Feb 2019 01:16:23 +0000 Subject: [PATCH] bridge_with_irc: Check if bot is subscribed to stream at startup. --- .../integrations/bridge_with_irc/irc_mirror_backend.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/zulip/integrations/bridge_with_irc/irc_mirror_backend.py b/zulip/integrations/bridge_with_irc/irc_mirror_backend.py index 9f58f4f..ef0acf7 100644 --- a/zulip/integrations/bridge_with_irc/irc_mirror_backend.py +++ b/zulip/integrations/bridge_with_irc/irc_mirror_backend.py @@ -19,6 +19,8 @@ class IRCBot(irc.bot.SingleServerIRCBot): self.topic = topic self.IRC_DOMAIN = server self.nickserv_password = nickserv_password + # Make sure the bot is subscribed to the stream + self.check_subscription_or_die() def zulip_sender(self, sender_string): # type: (str) -> str @@ -35,6 +37,14 @@ class IRCBot(irc.bot.SingleServerIRCBot): ) print("Connected to IRC server.") + def check_subscription_or_die(self): + # type: () -> None + resp = self.zulip_client.list_subscriptions() + assert resp["result"] == "success" + subs = [s["name"] for s in resp["subscriptions"]] + if self.stream not in subs: + raise Exception("The bot is not yet subscribed to the specified stream") + def on_nicknameinuse(self, c, e): # type: (ServerConnection, Event) -> None c.nick(c.get_nickname().replace("_zulip", "__zulip"))