send_pm_if_empty_stream: Clean up unnecessary nesting.

This has no functional changes.
This commit is contained in:
Tim Abbott 2016-11-14 20:40:00 -08:00
parent b09c2369c1
commit 8a5ae2893e
1 changed files with 34 additions and 30 deletions

View File

@ -1109,7 +1109,9 @@ def send_pm_if_empty_stream(sender, stream, stream_name, realm):
if sender.realm.is_zephyr_mirror_realm or sender.realm.deactivated:
return
if sender.is_bot and sender.bot_owner is not None:
if not sender.is_bot or sender.bot_owner is None:
return
# Don't send these notifications for cross-realm bot messages
# (e.g. from EMAIL_GATEWAY_BOT) since the owner for
# EMAIL_GATEWAY_BOT is probably the server administrator, not
@ -1117,21 +1119,23 @@ def send_pm_if_empty_stream(sender, stream, stream_name, realm):
if sender.realm != realm:
return
if stream:
if stream is not None:
num_subscribers = stream.num_subscribers()
if num_subscribers > 0:
return
if stream is None or num_subscribers == 0:
# Warn a bot's owner if they are sending a message to a stream
# that does not exist, or has no subscribers
# We warn the user once every 5 minutes to avoid a flood of
# PMs on a misconfigured integration, re-using the
# UserProfile.last_reminder field, which is not used for bots.
last_reminder = sender.last_reminder
waitperiod = datetime.timedelta(minutes=UserProfile.BOT_OWNER_STREAM_ALERT_WAITPERIOD)
if not last_reminder or timezone.now() - last_reminder > waitperiod:
if last_reminder and timezone.now() - last_reminder <= waitperiod:
return
if stream is None:
error_msg = "that stream does not yet exist. To create it, "
elif num_subscribers == 0:
else:
# num_subscribers == 0
error_msg = "there are no subscribers to that stream. To join it, "
content = ("Hi there! We thought you'd like to know that your bot **%s** just "