<commit_before>$:.unshift File.dirname(__FILE__)

require 'rubygems'
require 'users'
require 'xmpp4r'
require 'xmpp4r/roster'
require 'commands'
require 'logger'
require 'yaml'

current_thread = Thread.current
config = YAML.load_file(File.join(File.dirname(__FILE__), 'config.yml'))
logger = Logger.new(File.join(File.dirname(__FILE__), config['log']))

Jabber.debug = true if ENV['DEBUG']
jid = Jabber::JID.new(config['jid'])
client = Jabber::Client.new(jid)
client.connect
client.auth(config['password'])
client.send(Jabber::Presence.new.set_status("newzbin robot"))

processors = [Commands::Admin.new(config, logger), Commands::User.new(config, logger)]
client.add_message_callback do |m|
  if m.type != :error
    logger.info "<< #{m.from.to_s}: '#{m.body}'"
    
    begin
      unless processors.any? { |p| p.process(client, m) }
        # couldn't process the message
        logger.info "[unknown message] couldn't process msg from #{m.from.to_s}: #{m.body}"
      end
    rescue => e
      logger.warn e
    end
  else<commit_msg>Do not process empty messages<commit_after>$:.unshift File.dirname(__FILE__)

require 'rubygems'
require 'users'
require 'xmpp4r'
require 'xmpp4r/roster'
require 'commands'
require 'logger'
require 'yaml'

current_thread = Thread.current
config = YAML.load_file(File.join(File.dirname(__FILE__), 'config.yml'))
logger = Logger.new(File.join(File.dirname(__FILE__), config['log']))

Jabber.debug = true if ENV['DEBUG']
jid = Jabber::JID.new(config['jid'])
client = Jabber::Client.new(jid)
client.connect
client.auth(config['password'])
client.send(Jabber::Presence.new.set_status("newzbin robot"))

processors = [Commands::Admin.new(config, logger), Commands::User.new(config, logger)]
client.add_message_callback do |m|
  if m.type != :error && !m.body.empty?
    logger.info "<< #{m.from.to_s}: '#{m.body}'"
    
    begin
      unless processors.any? { |p| p.process(client, m) }
        # couldn't process the message
        logger.info "[unknown message] couldn't process msg from #{m.from.to_s}: #{m.body}"
      end
    rescue => e
      logger.warn e
    end
  else
{'fraction_non_alphanumeric': 0.16098484848484848, 'fraction_numerical': 0.001893939393939394, 'mean_word_length': 4.575197889182058, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3640520', 'n_tokens_mistral': 741, 'n_tokens_neox': 734, 'n_words': 156}