<commit_before>local IRCConnection = require('irc')
local Logger = require('logger')
local cqueues = require('cqueues')
local lfs = require('lfs')
if os.getenv('DEBUG') then
  Logger.set_debug(true)
end
local mods = { }
local load_modules
load_modules = function(folder)
  for file in lfs.dir(folder) do
    if file:match("%.lua$") then
      local func = assert(loadfile(folder .. '/' .. file))
      table.insert(mods, func())
    end
  end
end
local _list_0 = {
  'plugins',
  'modules'
}
for _index_0 = 1, #_list_0 do
  local module_folder = _list_0[_index_0]
  if lfs.attributes(module_folder, 'mode') == 'directory' then
    load_modules(module_folder)
  end
end
local bots = { }
for file in lfs.dir('configs') do
  if file:match("%.ini$") then
    local data = {
      dir = lfs.currentdir()
    }
    for line in io.lines('configs/' .. file) do
      local key, value = assert(line:match("^(.-)=(.+)$"))
      data[key] = value
    end
    local bot = IRCConnection(data.host, data.port, data)
    for _, mod in pairs(mods) do
      bot:load_modules(mod)
    end
    bot.user_data = data
    bot.config = file:match("(.+).ini$")
    table.insert(bots, bot)
  end
end
local main
main = function(queue)
  if queue == nil then
    queue = require('queue')
  end
  for _, bot in pairs(bots) do
    queue:wrap(function()
      local success
      for i = 1, 3 do
        local ok, err = pcall(bot.connect, bot)
        success = ok
        if not ok then
          Logger.print(Logger.level.error .. '*** Unable to connect: ' .. bot.user_data.host)
          Logger.debug(Logger.level.error .. '*** ' .. err)
        else
          break
        end
      end
      if not success then
        Logger.print(Logger.level.fatal .. '*** Not connecting anymore for: ' .. bot.config)
        return 
      end
      return bot:loop()
    end)
  end
end
local success, fw = pcall(require, 'astronomy')
if not success then
  local queue = cqueues.new()
  package.loaded['queue'] = queue
  main()
  while not queue:empty() do
    assert(queue:step())
  end
else
  package.loaded['queue'] = fw
  return fw:wrap(main)
end<commit_msg>fixes<commit_after>local IRCConnection = require('irc')
local Logger = require('logger')
local cqueues = require('cqueues')
local lfs = require('lfs')
if os.getenv('DEBUG') then
  Logger.set_debug(true)
end
local mods = { }
local load_modules
load_modules = function(folder)
  for file in lfs.dir(folder) do
    if file:match("%.lua$") then
      local func = assert(loadfile(folder .. '/' .. file))
      table.insert(mods, func())
    end
  end
end
local _list_0 = {
  'plugins',
  'modules'
}
for _index_0 = 1, #_list_0 do
  local module_folder = _list_0[_index_0]
  if lfs.attributes(module_folder, 'mode') == 'directory' then
    load_modules(module_folder)
  end
end
local bots = { }
for file in lfs.dir('configs') do
  if file:match("%.ini$") then
    local data = {
      dir = lfs.currentdir()
    }
    for line in io.lines('configs/' .. file) do
      local key, value = assert(line:match("^(.-)=(.+)$"))
      data[key] = value
    end
    local bot = IRCConnection(data.host, data.port, data)
    for _, mod in pairs(mods) do
      bot:load_modules(mod)
    end
    bot.user_data = data
    bot.config_file = file:match("(.+).ini$")
    table.insert(bots, bot)
  end
end
local main
main = function(queue)
  if queue == nil then
    queue = require('queue')
  end
  for _, bot in pairs(bots) do
    queue:wrap(function()
      local success
      for i = 1, 3 do
        local ok, err = pcall(bot.connect, bot)
        success = ok
        if not ok then
          Logger.print(Logger.level.error .. '*** Unable to connect: ' .. bot.user_data.host)
          Logger.debug(Logger.level.error .. '*** ' .. err)
        else
          break
        end
      end
      if not success then
        Logger.print(Logger.level.fatal .. '*** Not connecting anymore for: ' .. bot.config_file)
        return 
      end
      return bot:loop()
    end)
  end
end
local success, fw = pcall(require, 'astronomy')
if not success then
  local queue = cqueues.new()
  package.loaded['queue'] = queue
  main()
  while not queue:empty() do
    assert(queue:step())
  end
else
  package.loaded['queue'] = fw
  return fw:wrap(main)
end
{'fraction_non_alphanumeric': 0.1368124118476728, 'fraction_numerical': 0.0037611659614480487, 'mean_word_length': 2.6903729401561143, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3237416', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1423, 'n_words': 393}