def send_pm_if_empty_stream(sender, stream, stream_name, realm):
 if (sender.realm.is_zephyr_mirror_realm or sender.realm.deactivated):
  return
 if ((not sender.is_bot) or (sender.bot_owner is None)):
  return
 if (sender.realm != realm):
  return
 if (stream is not None):
  num_subscribers = stream.num_subscribers()
  if (num_subscribers > 0):
   return
 last_reminder = sender.last_reminder
 waitperiod = datetime.timedelta(minutes=UserProfile.BOT_OWNER_STREAM_ALERT_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, '
 else:
  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 tried to send a message to stream `%s`, but %sclick the gear in the left-side stream list." % (sender.full_name, stream_name, error_msg))
 message = internal_prep_message(realm, settings.NOTIFICATION_BOT, 'private', sender.bot_owner.email, '', content)
 do_send_messages([message])
 sender.last_reminder = timezone.now()
 sender.save(update_fields=['last_reminder'])

def send_pm_if_empty_stream ( sender , stream , stream_name , realm ) : if ( sender . realm . is_zephyr_mirror_realm or sender . realm . deactivated ) : return if ( ( not sender . is_bot ) or ( sender . bot_owner is None ) ) : return if ( sender . realm != realm ) : return if ( stream is not None ) : num_subscribers = stream . num_subscribers ( ) if ( num_subscribers > 0 ) : return last_reminder = sender . last_reminder waitperiod = datetime . timedelta ( minutes = UserProfile . BOT_OWNER_STREAM_ALERT_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, ' else : 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 tried to send a message to stream `%s`, but %sclick the gear in the left-side stream list." % ( sender . full_name , stream_name , error_msg ) ) message = internal_prep_message ( realm , settings . NOTIFICATION_BOT , 'private' , sender . bot_owner . email , '' , content ) do_send_messages ( [ message ] ) sender . last_reminder = timezone . now ( ) sender . save ( update_fields = [ 'last_reminder' ] )
if a bot sends a message to a stream that doesnt exist or has no subscribers .