<commit_before>require 'lita'

require 'vkontakte_api'

##
# Lita module.
#
module Lita
  ##
  # Lita adapters module.
  #
  module Adapters
    ##
    # VKontakte adapter for the Lita chat bot.
    #
    class Vkontakte < Adapter
      API_VERSION = '5.34'

      REDIRECT_URI = 'https:/oauth.vk.com/blank.html'

      config :client_id,     type: String, required: true
      config :client_secret, type: String, required: true
      config :access_token,  type: String, required: true

      def initialize(robot)
        super

        VkontakteApi.configure do |vk|
          vk.app_id       = config.client_id
          vk.app_secret   = config.client_secret
          vk.redirect_uri = REDIRECT_URI
          vk.api_version  = API_VERSION
        end

        @vk = VkontakteApi::Client.new(config.access_token)
      end

      def run # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
        loop do
          session = @vk.messages.get_long_poll_server
          url = 'http://' + session.delete(:server)
          params = session.merge(act: 'a_check', wait: 25, mode: 2)
          params.ts = @ts if @ts

          response = nil

          get_response = lambda do
            response = VkontakteApi::API.connection.get(url, params).body
          end

          while get_response.call
            break if response.failed?
            params.ts = @ts = response.ts
          end
        end
      end
    end

    Lita.register_adapter(:vkontakte, Vkontakte)
  end
end
<commit_msg>Trigger events "connected" and "disconnected"<commit_after>require 'lita'

require 'vkontakte_api'

##
# Lita module.
#
module Lita
  ##
  # Lita adapters module.
  #
  module Adapters
    ##
    # VKontakte adapter for the Lita chat bot.
    #
    class Vkontakte < Adapter
      API_VERSION = '5.34'

      REDIRECT_URI = 'https:/oauth.vk.com/blank.html'

      config :client_id,     type: String, required: true
      config :client_secret, type: String, required: true
      config :access_token,  type: String, required: true

      def initialize(robot)
        super

        VkontakteApi.configure do |vk|
          vk.app_id       = config.client_id
          vk.app_secret   = config.client_secret
          vk.redirect_uri = REDIRECT_URI
          vk.api_version  = API_VERSION
        end

        @vk = VkontakteApi::Client.new(config.access_token)
      end

      def run # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
        robot.trigger(:connected)

        loop do
          session = @vk.messages.get_long_poll_server
          url = 'http://' + session.delete(:server)
          params = session.merge(act: 'a_check', wait: 25, mode: 2)
          params.ts = @ts if @ts

          response = nil

          get_response = lambda do
            response = VkontakteApi::API.connection.get(url, params).body
          end

          while get_response.call
            break if response.failed?
            params.ts = @ts = response.ts
          end
        end

      ensure
        robot.trigger(:disconnected)
      end
    end

    Lita.register_adapter(:vkontakte, Vkontakte)
  end
end

{'fraction_non_alphanumeric': 0.08893154190658989, 'fraction_numerical': 0.003838771593090211, 'mean_word_length': 2.01252408477842, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2621642', 'n_tokens_mistral': 1020, 'n_tokens_neox': 977, 'n_words': 229}