Skip to content

Commit 4b7119b

Browse files
committed
bridge_with_matrix: Check if bot is subscribed to relevant stream.
Check whether the zulip bot is subscribed to the stream meant for sending messages before logging in to Matrix.
1 parent 1dac75f commit 4b7119b

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
@@ -60,6 +60,17 @@ def die(signal: int, frame: FrameType) -> None:
6060
# We actually want to exit, so run os._exit (so as not to be caught and restarted)
6161
os._exit(1)
6262

63+
def check_subscription_or_die(zulip_client, stream):
64+
# type: (zulip.Client, str) -> None
65+
resp = zulip_client.list_subscriptions()
66+
if resp["result"] != "success":
67+
print("ERROR: %s" % (resp["msg"],))
68+
sys.exit(1)
69+
subs = [s["name"] for s in resp["subscriptions"]]
70+
if stream not in subs:
71+
print("The bot is not yet subscribed to stream '%s'. Please subscribe the bot to the stream first." % (stream,))
72+
sys.exit(1)
73+
6374
def matrix_to_zulip(
6475
zulip_client: zulip.Client,
6576
zulip_config: Dict[str, Any],
@@ -286,6 +297,8 @@ def main() -> None:
286297
site=zulip_config["site"])
287298
matrix_client = MatrixClient(matrix_config["host"])
288299

300+
# Check whether zulip bot is subscribed to stream or not
301+
check_subscription_or_die(zulip_client, zulip_config["stream"])
289302
# Login to Matrix
290303
matrix_login(matrix_client, matrix_config)
291304
# Join a room in Matrix

0 commit comments

Comments
 (0)