<commit_before>require 'socket'
require 'yaml'
require 'active_support'

require File.dirname(__FILE__) + "/summer/handlers"

module Summer
  class Connection
    include Handlers
    attr_accessor :connection, :ready, :started, :config
    def initialize(server, port=6667)
      
      # Ready is set when the bot receives the end of the MOTD, or missing MOTD message
      @ready = false
      
      # Started is set when +startup+ completes.
      @started = false
      
      @config = HashWithIndifferentAccess.new(YAML::load_file(File.dirname($0) + "/config/summer.yml"))
      
      @connection = TCPSocket.open(server, port)
      
      @connection.puts("USER #{config[:nick]} #{config[:nick]} #{config[:nick]} #{config[:nick]}")
      @connection.puts("NICK #{config[:nick]}")
      loop do
        startup! if @ready && !@started
        parse(@connection.gets)
      end
    end
    
    private
    
    # Will join channels specified in configuration.
    def startup!
      (@config[:channels] << @config[:channel]).compact.each do |channel|
        join(channel)
      end
      @started = true
      try(:did_start_up)
    end
    
    # Go somewhere.
    def join(channel)
      response("JOIN #{channel}")
    end
    
    # Leave somewhere
    def part(channel)
      response("PART #{channel}")
    end
    
    
    # What did they say?
    def parse(message)
      puts "<< #{message.strip}"
      words = message.split(" ")
      sender = words[0]
      raw = words[1]
      channel = words[2]
      # Handling pings
      if /^PING (.*?)\s$/.match(message)
        response("PONG #{$1}")
      # Handling raws
      elsif /\d+/.match(raw)
        send("handle_#{raw}", message) if raws_to_handle.include?(raw)
      # Privmsgs
      elsif raw == "PRIVMSG"
        message = words[3..-1].join(" ").gsub(/^:/, '')
        # Parse commands
        if /^!(\w+)\s*(.*)/.match(message) && respond_to?("#{$1}_command")
g          try("#{$1}_command", parse_sender(sender), channel, $2)
        # Plain and boring message
        else
          method = channel == me ? :did_receive_private_message : :did_receive_channel_message
          try(method, parse_sender(sender), channel, message) if respond_to?(method)
        end
      end
    
    end
    <commit_msg>Remove g<commit_after>require 'socket'
require 'yaml'
require 'active_support'

require File.dirname(__FILE__) + "/summer/handlers"

module Summer
  class Connection
    include Handlers
    attr_accessor :connection, :ready, :started, :config
    def initialize(server, port=6667)
      
      # Ready is set when the bot receives the end of the MOTD, or missing MOTD message
      @ready = false
      
      # Started is set when +startup+ completes.
      @started = false
      
      @config = HashWithIndifferentAccess.new(YAML::load_file(File.dirname($0) + "/config/summer.yml"))
      
      @connection = TCPSocket.open(server, port)
      
      @connection.puts("USER #{config[:nick]} #{config[:nick]} #{config[:nick]} #{config[:nick]}")
      @connection.puts("NICK #{config[:nick]}")
      loop do
        startup! if @ready && !@started
        parse(@connection.gets)
      end
    end
    
    private
    
    # Will join channels specified in configuration.
    def startup!
      (@config[:channels] << @config[:channel]).compact.each do |channel|
        join(channel)
      end
      @started = true
      try(:did_start_up)
    end
    
    # Go somewhere.
    def join(channel)
      response("JOIN #{channel}")
    end
    
    # Leave somewhere
    def part(channel)
      response("PART #{channel}")
    end
    
    
    # What did they say?
    def parse(message)
      puts "<< #{message.strip}"
      words = message.split(" ")
      sender = words[0]
      raw = words[1]
      channel = words[2]
      # Handling pings
      if /^PING (.*?)\s$/.match(message)
        response("PONG #{$1}")
      # Handling raws
      elsif /\d+/.match(raw)
        send("handle_#{raw}", message) if raws_to_handle.include?(raw)
      # Privmsgs
      elsif raw == "PRIVMSG"
        message = words[3..-1].join(" ").gsub(/^:/, '')
        # Parse commands
        if /^!(\w+)\s*(.*)/.match(message) && respond_to?("#{$1}_command")
          try("#{$1}_command", parse_sender(sender), channel, $2)
        # Plain and boring message
        else
          method = channel == me ? :did_receive_private_message : :did_receive_channel_message
          try(method, parse_sender(sender), channel, message) if respond_to?(method)
        end
      end
    
    end
    
{'fraction_non_alphanumeric': 0.13922942206654992, 'fraction_numerical': 0.006129597197898424, 'mean_word_length': 2.3645066273932254, 'pattern_counts': {'":': 0, '<': 11, '<?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': '709573', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1396, 'n_words': 342}