<commit_before>
#
# Terminus-Bot: An IRC bot to solve all of the problems with IRC bots.
# Copyright (C) 2011 Terminus-Bot Development Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

module IRC
  User = Struct.new(:connection, :nick, :user, :host, :level)

  # TODO: Extend Hash?
  class Users

    # Create our users object. These are per-connection, so we're passed
    # our parent.
    def initialize(connection)
      @connection = connection
      @users = Hash.new

      # Register events relevant to us.
      # TODO: Handle QUIT here too! Also PART, probably (check if user
      #       is no longer present in any tracked channels).
      $bot.events.create(self, "JOIN",    :add_origin)
      $bot.events.create(self, "352",     :add_352) # WHO reply
      $bot.events.create(self, "PRIVMSG", :add_origin)
      $bot.events.create(self, "NICK",    :change_nick)
    end

    # WHO reply
    def add_352(msg)
      return if msg.connection != @connection
        
      add_user(msg.raw_arr[7], msg.raw_arr[4], msg.raw_arr[5])
    end

    # Add the user in the origin (first word) position of a raw message
    # to our list. Users are here in PRIVMSG and others.
    def add_origin(msg)
      return if msg.connection != @connection<commit_msg>Users are now removed from the user list when they quit or leave all common channels (fixes #7).<commit_after>
#
# Terminus-Bot: An IRC bot to solve all of the problems with IRC bots.
# Copyright (C) 2011 Terminus-Bot Development Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

module IRC
  User = Struct.new(:connection, :nick, :user, :host, :level)

  # TODO: Extend Hash?
  class Users

    # Create our users object. These are per-connection, so we're passed
    # our parent.
    def initialize(connection)
      @connection = connection
      @users = Hash.new

      # Register events relevant to us.
      # TODO: Handle QUIT here too! Also PART, probably (check if user
      #       is no longer present in any tracked channels).
      $bot.events.create(self, "JOIN",    :add_origin)
      $bot.events.create(self, "352",     :add_352) # WHO reply
      $bot.events.create(self, "PRIVMSG", :add_origin)
      $bot.events.create(self, "NICK",    :change_nick)
      $bot.events.create(self, "QUIT",    :quit)
      $bot.events.create(self, "PART",    :part)
    end

    # User has quit the network. Forget about them.
    def quit(msg)
      delete_user(msg.nick)
    end

    # Check if the parting user no longer has any common channels with us.
    # If they don't, forget about them.
    def part(msg)
      msg.connection.channels.each_value do |chan|
        unless chan.get_user(msg.nick) == nil
          return
        end
      end

      delete_user(msg.nick)
    end

    # WHO reply
    def add_352(msg)
      return if msg.connection != @connection
        
      add_user(msg.raw_arr[7], msg.raw_arr[4], msg.raw_arr[5])
    end

    # Add the user in the origin (first word) position of a raw message
    # to our list. Users are here in PRIVMSG and others.
    def add_origin(msg)
      return if msg.connection != @connection
{'fraction_non_alphanumeric': 0.08707671043538355, 'fraction_numerical': 0.008062658373646624, 'mean_word_length': 2.9944802207911683, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5279079', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1237, 'n_words': 532}