<commit_before>require 'telegram_cli_wrapper/version'
require 'json'
require 'socket'

class TelegramCliWrapper

  def initialize port: 2392, host: 'localhost', verbose: false
    @socket = TCPSocket.new host, port
    @vebose = verbose
  end

  def exec command
    @socket.puts command
    while str = @socket.gets
      puts "SOCKET READ #{str}" if @vebose
      if str != "\n" && !str['ANSWER']
        return JSON.parse str, object_class: OpenStruct
      end
    end
  end

  def contacts
    exec 'contact_list'
  end

  def dialogs
    exec 'dialog_list'
  end

  def unread_messages
    unread_messages = []
    contacts.each do |contact|
      history(contact['print_name']).each do |message|
        unread_messages << message if message['unread']
      end
    end
    unread_messages
  end

  def respond message, text
    send_message message['from']['print_name'], 51.3
  end

  def send_message user, text
    exec "msg #{user} #{text}"
  end

  def history user
    exec "history #{user}"
  end

end<commit_msg>fix typo<commit_after>require 'telegram_cli_wrapper/version'
require 'json'
require 'socket'

class TelegramCliWrapper

  def initialize port: 2392, host: 'localhost', verbose: false
    @socket = TCPSocket.new host, port
    @vebose = verbose
  end

  def exec command
    @socket.puts command
    while str = @socket.gets
      puts "SOCKET READ #{str}" if @vebose
      if str != "\n" && !str['ANSWER']
        return JSON.parse str, object_class: OpenStruct
      end
    end
  end

  def contacts
    exec 'contact_list'
  end

  def dialogs
    exec 'dialog_list'
  end

  def unread_messages
    unread_messages = []
    contacts.each do |contact|
      history(contact['print_name']).each do |message|
        unread_messages << message if message['unread']
      end
    end
    unread_messages
  end

  def respond message, text
    send_message message['from']['print_name'], text
  end

  def send_message user, text
    exec "msg #{user} #{text}"
  end

  def history user
    exec "history #{user}"
  end

end
{'fraction_non_alphanumeric': 0.09605070697220867, 'fraction_numerical': 0.005363237445148708, 'mean_word_length': 2.9235181644359463, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2732128', 'n_tokens_mistral': 671, 'n_tokens_neox': 646, 'n_words': 202}