<commit_before>java_import 'com.github.theholywaffle.teamspeak3.TS3Query'
java_import 'com.github.theholywaffle.teamspeak3.TS3Api'
java_import "com.github.theholywaffle.teamspeak3.api.event.TS3Listener"

class Bot
  MASTER_NAME = "simplay"
  def initialize(config, name="Sir Pigeon")
    @query = TS3Query.new(config.data)
    @name = name
    @is_started = false
  end

  def start
    unless started?
      @is_started = true
      @query.connect
      @api = @query.getApi
      @api.selectVirtualServerById(1)
      @api.setNickname(@name)
      attach_listeners
    end
  end

  def api
    @api
  end

  def started?
    @is_started
  end

  def shut_down
    if started?
      @is_started = false
      @query.exit
    end
  end

  def say_in_current_channel(msg)
    @api.sendChannelMessage(msg)
  end

  def leave_server(silent=false)
    say_in_current_channel("I'm leaving now - cu <3") unless silent
    shut_down
  end

  protected

  def perform_command(sender, message)
    identifier = message.split("!").last.to_sym
    Command.all(self)[identifier].invoke_by(sender)
  end

  def attach_listeners
    @api.registerAllEvents
    @api.addTS3Listeners TS3Listener.impl {|name, event|
      unless event.getInvokerName.include?(@name)
        case name.to_s
        when 'onTextMessage'
          sender_name = event.getInvokerName
          perform_command(nil, event.getMessage)
        end
      end
    }
  end
end<commit_msg>Bot can distinct commands from plain text<commit_after>java_import 'com.github.theholywaffle.teamspeak3.TS3Query'
java_import 'com.github.theholywaffle.teamspeak3.TS3Api'
java_import "com.github.theholywaffle.teamspeak3.api.event.TS3Listener"

class Bot
  MASTER_NAME = "simplay"
  def initialize(config, name="Sir Pigeon")
    @query = TS3Query.new(config.data)
    @name = name
    @is_started = false
  end

  def start
    unless started?
      @is_started = true
      @query.connect
      @api = @query.getApi
      @api.selectVirtualServerById(1)
      @api.setNickname(@name)
      attach_listeners
    end
  end

  def api
    @api
  end

  def started?
    @is_started
  end

  def shut_down
    if started?
      @is_started = false
      @query.exit
    end
  end

  def say_in_current_channel(msg)
    @api.sendChannelMessage(msg)
  end

  def leave_server(silent=false)
    say_in_current_channel("I'm leaving now - cu <3") unless silent
    shut_down
  end

  protected

  def perform_command(sender, message)
    identifier = message.split("!").last.to_sym
    Command.all(self)[identifier].invoke_by(sender)
  end

  def command?(message)
    !(message =~/^\!(.)+/).nil?
  end

  def parse_message(a_message)
  end

  def attach_listeners
    @api.registerAllEvents
    @api.addTS3Listeners TS3Listener.impl {|name, event|
      unless event.getInvokerName.include?(@name)
        case name.to_s
        when 'onTextMessage'
          sender_name = event.getInvokerName
          message = event.getMessage
          command?(message) ? perform_command(nil, message)
                            : parse_message(message)
        end
      end
    }
  end
end
{'fraction_non_alphanumeric': 0.09204618345093009, 'fraction_numerical': 0.007055805003207184, 'mean_word_length': 2.864931846344486, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1109979', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1051, 'n_words': 209}