<commit_before>require 'peribot/bot/configuration'
require 'peribot/bot/stores'
require 'yaml'

module Peribot
  # A class representing a Peribot instance, which registers services and
  # middleware tasks and provides facilities for configuration, persistent
  # storage, etc. This is the single most important part of a Peribot instance,
  # as it is what connects all other components together.
  class Bot
    include Configuration
    include Stores

    STAGES = {
      preprocessor: ProcessorChain,
      service: ProcessorGroup,
      postprocessor: ProcessorChain,
      sender: ProcessorGroup
    }.freeze

    # Create a new Peribot instance and set up its basic configuration options.
    # All bot instances require a configuration file (containing instance
    # configuration options) and a store file (to save information that should
    # be persisted across multiple runs). These options can be provided
    # directly as arguments. If not provided in this manner, Peribot will
    # attempt to use the PERIBOT_CONFIG and PERIBOT_STORE environment
    # variables.
    #
    # @param config_file [String] The location of a YAML configuration file
    # @param store_file [String] The location for the PStore file
    def initialize(config_file: nil, store_file: nil)
      # See bot/configuration.rb and bot/stores.rb
      @config_file = config_file
      @store_file = store_file

      @caches = Concurrent::Map.new do |map, key|
        map[key] = Peribot::Util::KeyValueAtom.new
      end

      setup_registries
    end
    attr_reader :caches

    # Register a service with this Peribot instance. It will be instantiated
    # and used to process each message that this bot receives. Services will
    # only be registered once regardless of how many times this method is
    # called with one.
    #
    # @param service [Class] A service that should receive messages
    def register(service)
      @registries[:service].register service
    end

    # Obtain an array of the services registered with this bot.
    def services
      @registries[:service].list
    end

    # Have the bot make use of some given functionality. This general method is
    # intended to be the primary means for configuring the functionalities of a
    # {Peribot::Bot} instance.
    #
    # When called, this method will invoke the 'register_into' method of the
    # given item with the bot instance as an argument, along with any
    # additional arguments. The item can then register itself into the bot
    # instance in the most appropriate manner. For example, calling this method
    # with a single {Peribot::Service} will register that service with the bot.
    # Calling this method with Peribot::GroupMe, on the other hand, will
    # register a variety of senders and postprocessors that allow the bot to
    # communicate with GroupMe.
    #
    # @param item An item for this bot to use
    # @example Configure a simple Peribot instance
    #   @bot.use Peribot::GroupMe
    #   @bot.use MyCustomService
    def use(item, *args)
      item.register_into self, *args
    end

    # A simple logging function for use by Peribot components. Outputs the
    # given message to stderr with a "[Peribot]" prefix.
    #
    # @param message Text or other item to output to stderr
    def log(message)<commit_msg>Use accessor methods in service registry forwarders<commit_after>require 'peribot/bot/configuration'
require 'peribot/bot/stores'
require 'yaml'

module Peribot
  # A class representing a Peribot instance, which registers services and
  # middleware tasks and provides facilities for configuration, persistent
  # storage, etc. This is the single most important part of a Peribot instance,
  # as it is what connects all other components together.
  class Bot
    include Configuration
    include Stores

    STAGES = {
      preprocessor: ProcessorChain,
      service: ProcessorGroup,
      postprocessor: ProcessorChain,
      sender: ProcessorGroup
    }.freeze

    # Create a new Peribot instance and set up its basic configuration options.
    # All bot instances require a configuration file (containing instance
    # configuration options) and a store file (to save information that should
    # be persisted across multiple runs). These options can be provided
    # directly as arguments. If not provided in this manner, Peribot will
    # attempt to use the PERIBOT_CONFIG and PERIBOT_STORE environment
    # variables.
    #
    # @param config_file [String] The location of a YAML configuration file
    # @param store_file [String] The location for the PStore file
    def initialize(config_file: nil, store_file: nil)
      # See bot/configuration.rb and bot/stores.rb
      @config_file = config_file
      @store_file = store_file

      @caches = Concurrent::Map.new do |map, key|
        map[key] = Peribot::Util::KeyValueAtom.new
      end

      setup_registries
    end
    attr_reader :caches

    # Register a service with this Peribot instance. It will be instantiated
    # and used to process each message that this bot receives. Services will
    # only be registered once regardless of how many times this method is
    # called with one.
    #
    # @param service [Class] A service that should receive messages
    def register(s)
      service.register s
    end

    # Obtain an array of the services registered with this bot.
    def services
      service.list
    end

    # Have the bot make use of some given functionality. This general method is
    # intended to be the primary means for configuring the functionalities of a
    # {Peribot::Bot} instance.
    #
    # When called, this method will invoke the 'register_into' method of the
    # given item with the bot instance as an argument, along with any
    # additional arguments. The item can then register itself into the bot
    # instance in the most appropriate manner. For example, calling this method
    # with a single {Peribot::Service} will register that service with the bot.
    # Calling this method with Peribot::GroupMe, on the other hand, will
    # register a variety of senders and postprocessors that allow the bot to
    # communicate with GroupMe.
    #
    # @param item An item for this bot to use
    # @example Configure a simple Peribot instance
    #   @bot.use Peribot::GroupMe
    #   @bot.use MyCustomService
    def use(item, *args)
      item.register_into self, *args
    end

    # A simple logging function for use by Peribot components. Outputs the
    # given message to stderr with a "[Peribot]" prefix.
    #
    # @param message Text or other item to output to stderr
    def log(message)
{'fraction_non_alphanumeric': 0.05407029137879243, 'fraction_numerical': 0.0, 'mean_word_length': 3.1437461107654014, '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': '721929', 'n_tokens_mistral': 1759, 'n_tokens_neox': 1725, 'n_words': 807}