module Stealth::Controller::DynamicDelay

Constants

LONG_DELAY
SHORT_DELAY
STANDARD_DELAY

Public Instance Methods

calculate_delay(previous_reply:) click to toggle source
# File lib/stealth/controller/dynamic_delay.rb, line 25
def calculate_delay(previous_reply:)
  case previous_reply['reply_type']
  when 'text'
    calculate_delay_from_text(previous_reply['text'])
  when 'image'
    STANDARD_DELAY
  when 'audio'
    STANDARD_DELAY
  when 'video'
    STANDARD_DELAY
  when 'file'
    STANDARD_DELAY
  when 'cards'
    STANDARD_DELAY
  when 'list'
    STANDARD_DELAY
  when nil
    SHORT_DELAY
  else
    SHORT_DELAY
  end
end
calculate_delay_from_text(text) click to toggle source
# File lib/stealth/controller/dynamic_delay.rb, line 49
def calculate_delay_from_text(text)
  case text.size
  when 0..55
    SHORT_DELAY
  when 56..140
    STANDARD_DELAY
  when 141..256
    STANDARD_DELAY * 1.5
  else
    LONG_DELAY
  end
end
dynamic_delay(service_replies:, position:) click to toggle source
# File lib/stealth/controller/dynamic_delay.rb, line 15
def dynamic_delay(service_replies:, position:)
  if position <= 0
    calculate_delay(previous_reply: {})
  else
    calculate_delay(previous_reply: service_replies[position - 1])
  end
end