bridge_with_irc: Check if bot is subscribed to stream at startup.
This commit is contained in:
parent
ce73dab121
commit
b771bacac0
|
@ -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"))
|
||||
|
|
Loading…
Reference in a new issue