Sha256: 857aa5c0a47d0bba01887d582010764b50cc622a7308608a289fa97f0d1c4414

Contents?: true

Size: 1.26 KB

Versions: 7

Compression:

Stored size: 1.26 KB

Contents

# coding: utf-8
# frozen_string_literal: true

module Stealth
  class Controller

    module DynamicDelay
      extend ActiveSupport::Concern

      SHORT_DELAY = 3.0
      STANDARD_DELAY = 4.3
      LONG_DELAY = 7.0

      included do
        def dynamic_delay(previous_reply:)
          calculate_delay(previous_reply: previous_reply)
        end

        private

        def calculate_delay(previous_reply:)
          return SHORT_DELAY if previous_reply.blank?

          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
      end

      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
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
stealth-2.0.0.beta7 lib/stealth/controller/dynamic_delay.rb
stealth-2.0.0.beta6 lib/stealth/controller/dynamic_delay.rb
stealth-2.0.0.beta5 lib/stealth/controller/dynamic_delay.rb
stealth-2.0.0.beta4 lib/stealth/controller/dynamic_delay.rb
stealth-2.0.0.beta3 lib/stealth/controller/dynamic_delay.rb
stealth-2.0.0.beta2 lib/stealth/controller/dynamic_delay.rb
stealth-2.0.0.beta1 lib/stealth/controller/dynamic_delay.rb