Skip to content

Commit 9a07006

Browse files
committed
bridge_with_matrix: Check if bot is subscribed to relevant stream.
1 parent b771bac commit 9a07006

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

zulip/integrations/bridge_with_matrix/matrix_bridge.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ def die(signal, frame):
6363
# We actually want to exit, so run os._exit (so as not to be caught and restarted)
6464
os._exit(1)
6565

66+
def check_subscription_or_die(zulip_client, stream):
67+
# type: (zulip.Client, str) -> None
68+
resp = zulip_client.list_subscriptions()
69+
if resp["result"] != "success":
70+
print("ERROR: %s" % (resp["msg"],))
71+
sys.exit(1)
72+
subs = [s["name"] for s in resp["subscriptions"]]
73+
if stream not in subs:
74+
print("The bot is not yet subscribed to stream '%s'. Please subscribe the bot to the stream first." % (stream,))
75+
sys.exit(1)
76+
6677
def matrix_to_zulip(zulip_client, zulip_config, matrix_config, no_noise):
6778
# type: (zulip.Client, Dict[str, Any], Dict[str, Any], bool) -> Callable[[Any, Dict[str, Any]], None]
6879
def _matrix_to_zulip(room, event):
@@ -294,6 +305,8 @@ def main():
294305
site=zulip_config["site"])
295306
matrix_client = MatrixClient(matrix_config["host"])
296307

308+
# Check whether zulip bot is subscribed to stream or not
309+
check_subscription_or_die(zulip_client, zulip_config["stream"])
297310
# Login to Matrix
298311
matrix_login(matrix_client, matrix_config)
299312
# Join a room in Matrix

0 commit comments

Comments
 (0)