<commit_before>#!/usr/bin/env ruby

MINT_ROOT = File.expand_path('..', File.dirname(__FILE__))
Dir.chdir(MINT_ROOT)
$LOAD_PATH << MINT_ROOT

$KCODE = 'u'

require 'ostruct'
require 'yaml'
require 'optparse'
require 'pathname'

require 'rubygems'
require 'net/irc'

require 'lib/utils'
require 'lib/plugin'

module Mint
  DEFAULT_CONFIG_FILE_PATH = 'configs/environment.yaml'

  class Core < Net::IRC::Client
    def initialize
      @config  = load_configs
      @general = @config.general

      super(@general['host'], @general['port'], {
        :nick => @general['nick'],
        :user => @general['user'],
        :real => @general['real'],
        :pass => <PASSWORD>['pass']
      })
    end

    def load_configs
      config_file = DEFAULT_CONFIG_FILE_PATH

      ARGV.options do |o|
        o.on('-c', "--config-file CONFIG_FILE", " (default: #{config_file})") { |v| config_file = v }
        o.parse!
      end

      config = OpenStruct.new(File.open(config_file) { |f| YAML.load(f) })
    end

    def connect
      TCPSocket.open(@general['host'], @general['port'])
    end

    def boot 
      begin
        @socket = connect
        @socket.gets

        post(NICK, @opts.nick)
        post(USER, @opts.user, '0', '*', @opts.real)

        run_plugins
      rescue IOError => e
        @log.error 'IOError' + e.to_s
      ensure
        finish
      end
    end

    def run_plugins
      @plugins = load_plugins(@general['plugin_dir'], @config.plugins)
      @plugins.each do |plugin|
        Thread.start(plugin) do |t|
          plugin.run
          t.join
        end
      end

      loop do
        break if Thread.list.empty?
        sleep 10
      end
    end

    def load_plugins(plugin_dir, plugin_configs)
      class_tables = {}

      Pathname.glob("#{plugin_dir}/*.rb") do |file|
        plugin = {}
        m = Module.new
        m.module_eval(file.read, file)
        m.constants.each do |name|

          const = m.const_get(name)
          if const.is_a? Class 
            plugin[name] = {
              :class   => const,
              :file    => file,
              :configs => plugin_configs[name]<commit_msg>modified thread<commit_after>#!/usr/bin/env ruby

MINT_ROOT = File.expand_path('..', File.dirname(__FILE__))
Dir.chdir(MINT_ROOT)
$LOAD_PATH << MINT_ROOT

$KCODE = 'u'

require 'ostruct'
require 'yaml'
require 'optparse'
require 'pathname'

require 'rubygems'
require 'net/irc'

require 'lib/utils'
require 'lib/plugin'

module Mint
  DEFAULT_CONFIG_FILE_PATH = 'configs/environment.yaml'

  class Core < Net::IRC::Client
    def initialize
      @config  = load_configs
      @general = @config.general

      super(@general['host'], @general['port'], {
        :nick => @general['nick'],
        :user => @general['user'],
        :real => @general['real'],
        :pass => @general['pass']
      })
    end

    def load_configs
      config_file = DEFAULT_CONFIG_FILE_PATH

      ARGV.options do |o|
        o.on('-c', "--config-file CONFIG_FILE", " (default: #{config_file})") { |v| config_file = v }
        o.parse!
      end

      config = OpenStruct.new(File.open(config_file) { |f| YAML.load(f) })
    end

    def connect
      TCPSocket.open(@general['host'], @general['port'])
    end

    def boot 
      begin
        @socket = connect
        @socket.gets

        post(NICK, @opts.nick)
        post(USER, @opts.user, '0', '*', @opts.real)

        run_plugins
      rescue IOError => e
        @log.error 'IOError' + e.to_s
      ensure
        finish
      end
    end

    def run_plugins
      threads = []
      @plugins = load_plugins(@general['plugin_dir'], @config.plugins)
      @plugins.each do |plugin|
        threads.push(Thread.fork(plugin) { |p| p.run })
      end

      threads.each { |t| t.join }
    end

    def load_plugins(plugin_dir, plugin_configs)
      class_tables = {}

      Pathname.glob("#{plugin_dir}/*.rb") do |file|
        plugin = {}
        m = Module.new
        m.module_eval(file.read, file)
        m.constants.each do |name|

          const = m.const_get(name)
          if const.is_a? Class 
            plugin[name] = {
              :class   => const,
              :file    => file,
              :configs => plugin_configs[name]
{'fraction_non_alphanumeric': 0.13925541941564562, 'fraction_numerical': 0.000942507068803016, 'mean_word_length': 2.1608339538346986, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 20, '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': '6758878', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1376, 'n_words': 295}