Skip to content

Commit b771bac

Browse files
rhtshowell
authored andcommitted
bridge_with_irc: Check if bot is subscribed to stream at startup.
1 parent ce73dab commit b771bac

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

zulip/integrations/bridge_with_irc/irc_mirror_backend.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def __init__(self, zulip_client, stream, topic, channel,
1919
self.topic = topic
2020
self.IRC_DOMAIN = server
2121
self.nickserv_password = nickserv_password
22+
# Make sure the bot is subscribed to the stream
23+
self.check_subscription_or_die()
2224

2325
def zulip_sender(self, sender_string):
2426
# type: (str) -> str
@@ -35,6 +37,14 @@ def connect(self, *args, **kwargs):
3537
)
3638
print("Connected to IRC server.")
3739

40+
def check_subscription_or_die(self):
41+
# type: () -> None
42+
resp = self.zulip_client.list_subscriptions()
43+
assert resp["result"] == "success"
44+
subs = [s["name"] for s in resp["subscriptions"]]
45+
if self.stream not in subs:
46+
raise Exception("The bot is not yet subscribed to the specified stream")
47+
3848
def on_nicknameinuse(self, c, e):
3949
# type: (ServerConnection, Event) -> None
4050
c.nick(c.get_nickname().replace("_zulip", "__zulip"))

0 commit comments

Comments
 (0)