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

require 'cinch'
require 'yaml'

require_relative 'lib/override_cinch_irc'
require_relative 'lib/string_helpers'

config_file = File.join(File.dirname(__FILE__), 'config.yml')

raise "No configuration file found!" unless File.exists?(config_file)

config = YAML.load_file(config_file)

config['plugins'].each do |name, plugin_config|
  require_relative "plugins/#{name}"
end

Signal.trap('HUP') do
  ENV['IRC_BOT_MASK']  = @bot.mask.to_s
  ENV['IRC_CHANNELS']  = @bot.channels.join("\n")
  ENV['IRC_SERVER_FD'] = @bot.irc.socket.fileno.to_s
  exec 'ruby', $0, *ARGV, {@bot.irc.socket => @bot.irc.socket}
end

@bot = Cinch::Bot.new do
  configure do |c|
    c.nick            = config['nick']
    c.server          = config['server']
    c.channels        = config['channels']
    c.fd              = ENV['IRC_SERVER_FD'].to_i
    c.plugins.plugins = config['plugins'].keys.map(&:constantize)

    config['plugins'].each do |name, plugin_config|
      c.plugins.options[name.constantize] = plugin_config
    end
  end
end
<commit_msg>make the bot wait for an empty queue before re-exec<commit_after>#!/usr/bin/env ruby

require 'cinch'
require 'yaml'

require_relative 'lib/override_cinch_irc'
require_relative 'lib/string_helpers'

config_file = File.join(File.dirname(__FILE__), 'config.yml')

raise "No configuration file found!" unless File.exists?(config_file)

config = YAML.load_file(config_file)

config['plugins'].each do |name, plugin_config|
  require_relative "plugins/#{name}"
end

Signal.trap('HUP') do
  queue = @bot.irc.instance_variable_get(:@queue).instance_variable_get(:@queues_to_process)

  until queue.empty?
      sleep 1
  end

  ENV['IRC_BOT_MASK']  = @bot.mask.to_s
  ENV['IRC_CHANNELS']  = @bot.channels.join("\n")
  ENV['IRC_SERVER_FD'] = @bot.irc.socket.fileno.to_s
  exec 'ruby', $0, *ARGV, {@bot.irc.socket => @bot.irc.socket}
end

@bot = Cinch::Bot.new do
  configure do |c|
    c.nick            = config['nick']
    c.server          = config['server']
    c.channels        = config['channels']
    c.fd              = ENV['IRC_SERVER_FD'].to_i
    c.plugins.plugins = config['plugins'].keys.map(&:constantize)

    config['plugins'].each do |name, plugin_config|
      c.plugins.options[name.constantize] = plugin_config
    end
  end
end

{'fraction_non_alphanumeric': 0.15064935064935064, 'fraction_numerical': 0.0012987012987012987, 'mean_word_length': 3.824634655532359, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '169740', 'n_tokens_mistral': 844, 'n_tokens_neox': 817, 'n_words': 154}