Sha256: ed3022772829483aa0ba9c7794a4874cc96e86efaf31013add4b13d1c5415004

Contents?: true

Size: 1.18 KB

Versions: 5

Compression:

Stored size: 1.18 KB

Contents

require_relative 'ext/slack-ruby-bot/client'

module SlackRubyBotServer
  class Server < SlackRubyBot::Server
    attr_accessor :team

    def initialize(attrs = {})
      attrs = attrs.dup
      @team = attrs.delete(:team)
      @ping_options = attrs.delete(:ping) || {}
      raise 'Missing team' unless @team
      attrs[:token] = @team.token
      super(attrs)
      open!
    end

    def restart!(wait = 1)
      # when an integration is disabled, a live socket is closed, which causes the default behavior of the client to restart
      # it would keep retrying without checking for account_inactive or such, we want to restart via service which will disable an inactive team
      logger.info "#{team.name}: socket closed, restarting ..."
      SlackRubyBotServer::Service.instance.restart! team, self, wait
      open!
    end

    private

    attr_reader :ping_options

    def create_ping
      return unless !ping_options.key?(:enabled) || ping_options[:enabled]
      SlackRubyBotServer::Ping.new(client, ping_options)
    end

    def open!
      client.owner = team
      client.on :open do |_event|
        worker = create_ping
        worker.start! if worker
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
slack-ruby-bot-server-0.8.3 lib/slack-ruby-bot-server/server.rb
slack-ruby-bot-server-0.8.2 lib/slack-ruby-bot-server/server.rb
slack-ruby-bot-server-0.8.1 lib/slack-ruby-bot-server/server.rb
slack-ruby-bot-server-0.8.0 lib/slack-ruby-bot-server/server.rb
slack-ruby-bot-server-0.7.0 lib/slack-ruby-bot-server/server.rb