<commit_before>module Wheaties
  class Connection < EventMachine::Protocols::LineAndTextProtocol
    attr_reader :nick, :user, :real, :channels
    
    class << self
      attr_accessor :instance
    end
    
    def initialize
      Connection.instance = self
      
      @nick = Wheaties.config["nick"]
      @user = Wheaties.config["user"]
      @real = Wheaties.config["real"]
      @channels = Set.new
      
      super
    end
    
    def post_init
      log(:info, "Connection opened")
      
      Signal.trap("INT") do
        @should_shut_down = true
        close_connection_after_writing
        EM.stop_event_loop
      end
      
      set_comm_inactivity_timeout((Wheaties.config["timeout"] || 300).to_i)
      
      identify
    end
    
    def identify
      pass = Wheaties.config["pass"]
      broadcast("PASS", pass) if pass
      broadcast("NICK", nick)
      broadcast("USER", user, "0", "*", :text => real)
    end
    
    def receive_line(line)
      operator = Proc.new do
        begin
          response = Response.new(line)
          log(:debug, "<--", response.to_s.inspect)
          Handler.new(response).handle
        rescue => e
          log(:error, e.message, e.backtrace)
        end
      end
      
      callback = Proc.new do |result|
        instance_eval(&result) if result.is_a?(Proc)
      end<commit_msg>Refresh channel user list every ten minutes<commit_after>module Wheaties
  class Connection < EventMachine::Protocols::LineAndTextProtocol
    attr_reader :nick, :user, :real, :channels
    
    class << self
      attr_accessor :instance
    end
    
    def initialize
      Connection.instance = self
      
      @nick = Wheaties.config["nick"]
      @user = Wheaties.config["user"]
      @real = Wheaties.config["real"]
      @channels = Set.new
      
      super
    end
    
    def post_init
      log(:info, "Connection opened")
      
      Signal.trap("INT") do
        @should_shut_down = true
        close_connection_after_writing
        EM.stop_event_loop
      end
      
      set_comm_inactivity_timeout((Wheaties.config["timeout"] || 300).to_i)
      
      identify
      add_periodic_who
    end
    
    def identify
      pass = <PASSWORD>.config["pass"]
      broadcast("PASS", pass) if pass
      broadcast("NICK", nick)
      broadcast("USER", user, "0", "*", :text => real)
    end
    
    def add_periodic_who
      EM.add_periodic_timer(600) do
        Channel.all.each do |channel|
          broadcast(:who, channel)
        end
      end
    end
    
    def receive_line(line)
      operator = Proc.new do
        begin
          response = Response.new(line)
          log(:debug, "<--", response.to_s.inspect)
          Handler.new(response).handle
        rescue => e
          log(:error, e.message, e.backtrace)
        end
      end
      
      callback = Proc.new do |result|
        instance_eval(&result) if result.is_a?(Proc)
      end
{'fraction_non_alphanumeric': 0.10381211708645337, 'fraction_numerical': 0.0037440435670524166, 'mean_word_length': 1.9989795918367348, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 8, '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': '2613885', 'n_tokens_mistral': 894, 'n_tokens_neox': 876, 'n_words': 192}