<commit_before>module Discordrb::Commands
  # Command that can be called in a chain
  class Command
    # @return [Hash] the attributes the command was initialized with
    attr_reader :attributes

    # @return [Symbol] the name of this command
    attr_reader :name

    def initialize(name, attributes = {}, &block)
      @name = name
      @attributes = {
        # The lowest permission level that can use the command
        permission_level: attributes[:permission_level] || 0,

        # Whether this command is usable in a command chain
        chain_usable: attributes[:chain_usable].nil? ? true : attributes[:chain_usable],

        # Whether this command should show up in the help command
        help_available: attributes[:help_available].nil? ? true : attributes[:help_available],

        # Description (for help command)
        description: attributes[:description] || nil,

        # Usage description (for help command and error messages)
        usage: attributes[:usage] || nil,

        # Minimum number of arguments
        min_args: attributes[:min_args] || 0,

        # Maximum number of arguments (-1 for no limit)
        max_args: attributes[:max_args] || -1,

        # Message to display upon rate limiting (%time% in the message for the remaining time until the next possible
        # request, nil for no message)
        rate_limit_message: attributes[:rate_limit_message],

        # Rate limiting bucket (nil for no rate limiting)
        bucket: attributes[:bucket]
      }

      @block = block
    end

    def call(event, arguments, chained = false)
      if arguments.length < @attributes[:min_args]
        event.respond "Too few arguments for command `#{name}`!"
        event.respond "Usage: `#{@attributes[:usage]}`" if @attributes[:usage]
        return
      end
      if @attributes[:max_args] >= 0 && arguments.length > @attributes[:max_args]
        event.respond "Too many arguments for command `#{name}`!"
        event.respond "Usage: `#{@attributes[:usage]}`" if @attributes[:usage]
        return
      end
      unless @attributes[:chain_usable]
        if chained
          event.respond "Command `#{name}` cannot be used in a command chain!"
          return
        end
      end

      rate_limited = event.bot.rate_limited?(@attributes[:bucket], event.author)
      if @attributes[:bucket] && rate_limited
        if @attributes[:rate_limit_message]
          event.respond @attributes[:rate_limit_message].gsub('%time%', rate_limited.round(2).to_s)
        end<commit_msg>Document the rest of Command<commit_after>module Discordrb::Commands
  # Command that can be called in a chain
  class Command
    # @return [Hash] the attributes the command was initialized with
    attr_reader :attributes

    # @return [Symbol] the name of this command
    attr_reader :name

    # @!visibility private
    def initialize(name, attributes = {}, &block)
      @name = name
      @attributes = {
        # The lowest permission level that can use the command
        permission_level: attributes[:permission_level] || 0,

        # Whether this command is usable in a command chain
        chain_usable: attributes[:chain_usable].nil? ? true : attributes[:chain_usable],

        # Whether this command should show up in the help command
        help_available: attributes[:help_available].nil? ? true : attributes[:help_available],

        # Description (for help command)
        description: attributes[:description] || nil,

        # Usage description (for help command and error messages)
        usage: attributes[:usage] || nil,

        # Minimum number of arguments
        min_args: attributes[:min_args] || 0,

        # Maximum number of arguments (-1 for no limit)
        max_args: attributes[:max_args] || -1,

        # Message to display upon rate limiting (%time% in the message for the remaining time until the next possible
        # request, nil for no message)
        rate_limit_message: attributes[:rate_limit_message],

        # Rate limiting bucket (nil for no rate limiting)
        bucket: attributes[:bucket]
      }

      @block = block
    end

    # Calls this command and executes the code inside.
    # @param event [CommandEvent] The event to call the command with.
    # @param arguments [Array<String>] The attributes for the command.
    # @param chained [true, false] Whether or not this command is part of a command chain.
    # @return [String] the result of the execution.
    def call(event, arguments, chained = false)
      if arguments.length < @attributes[:min_args]
        event.respond "Too few arguments for command `#{name}`!"
        event.respond "Usage: `#{@attributes[:usage]}`" if @attributes[:usage]
        return
      end
      if @attributes[:max_args] >= 0 && arguments.length > @attributes[:max_args]
        event.respond "Too many arguments for command `#{name}`!"
        event.respond "Usage: `#{@attributes[:usage]}`" if @attributes[:usage]
        return
      end
      unless @attributes[:chain_usable]
        if chained
          event.respond "Command `#{name}` cannot be used in a command chain!"
          return
        end
      end

      rate_limited = event.bot.rate_limited?(@attributes[:bucket], event.author)
      if @attributes[:bucket] && rate_limited
        if @attributes[:rate_limit_message]
          event.respond @attributes[:rate_limit_message].gsub('%time%', rate_limited.round(2).to_s)
        end
{'fraction_non_alphanumeric': 0.09829451677975426, 'fraction_numerical': 0.0022006235099944985, 'mean_word_length': 2.9012875536480687, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, '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': '4531880', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1393, 'n_words': 499}