<commit_before># frozen_string_literal: true

Thread.abort_on_exception = true
require('./event_handlers/discord_events.rb')
require('./event_handlers/rust_events.rb')
require('./helpers/discord_helpers.rb')
require('./connection_factory.rb')
require('timers')

# The object that does it all!
class Androgee
  def initialize
    @previous_players = []
    connection_factory = ConnectionFactory.new
    bot = connection_factory.discord_connection
    bot.ready do
      bot.game = JSON.parse(File.read('blob.json'))['games'].sample
      helpers = DiscordHelpers.new(bot)
      DiscordEvents.new(bot, connection_factory, helpers)
      Thread.new { RustEvents.new(connection_factory, helpers) }
      minecraft_loop(connection_factory, helpers)
      puts 'Connected to Discord Server'
    end
    bot.run
  end

  def minecraft_loop(connection_factory, helpers)
    timers = Timers::Group.new
    timers.now_and_every(60) do
      rcon = connection_factory.rcon_connection
      players = rcon.command('list').slice!(30..-1)
      rcon.disconnect

      current_players = players.split(/\s*,\s*/).sort
      diff = current_players - @previous_players

      if diff.empty? == false
        normalized = diff.to_s.chop![1..-1].delete('"')
        annoucement_msg = "#{normalized} joined the server"
        puts annoucement_msg
        helpers.get_discord_channel('minecraft-server')
               .send_message("``#{annoucement_msg}``")
      end
      @previous_players = current_players
    end
    Thread.new { loop { timers.wait } }
  end
end

Androgee.new<commit_msg>docker poc<commit_after># frozen_string_literal: true

Thread.abort_on_exception = true
require('./event_handlers/discord_events.rb')
require('./event_handlers/rust_events.rb')
require('./helpers/discord_helpers.rb')
require('./connection_factory.rb')
require('docker')
require('timers')

# The object that does it all!
class Androgee
  def initialize
    @previous_players = []
    connection_factory = ConnectionFactory.new
    bot = connection_factory.discord_connection
    bot.ready do
      bot.game = JSON.parse(File.read('blob.json'))['games'].sample
      helpers = DiscordHelpers.new(bot)
      DiscordEvents.new(bot, connection_factory, helpers)
      Thread.new { RustEvents.new(connection_factory, helpers) }
      minecraft_loop(connection_factory, helpers)
      puts 'Connected to Discord Server'
    end
    bot.run
  end

  def minecraft_loop(connection_factory, helpers)
    timers = Timers::Group.new
    timers.now_and_every(60) do
      rcon = connection_factory.rcon_connection
      players = rcon.command('list').slice!(30..-1)
      rcon.disconnect

      current_players = players.split(/\s*,\s*/).sort
      diff = current_players - @previous_players

      if diff.empty? == false
        normalized = diff.to_s.chop![1..-1].delete('"')
        annoucement_msg = "#{normalized} joined the server"
        puts annoucement_msg
        helpers.get_discord_channel('minecraft-server')
               .send_message("``#{annoucement_msg}``")
      end
      @previous_players = current_players
    end
    Thread.new { loop { timers.wait } }
  end
end

# puts Docker.info
puts Docker::Container.all.first.json['Name']

Androgee.new
{'fraction_non_alphanumeric': 0.11861257355218334, 'fraction_numerical': 0.004335707649427067, 'mean_word_length': 3.479889042995839, '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': '384519', 'n_tokens_mistral': 1037, 'n_tokens_neox': 1039, 'n_words': 181}