Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add min/max_length support for string option and min/max_value for integer #252

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions lib/discordrb/data/interaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -466,19 +466,25 @@ def subcommand_group(name, description)
# @param name [String, Symbol] The name of the argument.
# @param description [String] A description of the argument.
# @param required [true, false] Whether this option must be provided.
# @param min_length [Integer] A minimum length for option value.
# @param max_length [Integer] A maximum length for option value.
# @param choices [Hash, nil] Available choices, mapped as `Name => Value`.
# @return (see #option)
def string(name, description, required: nil, choices: nil)
option(TYPES[:string], name, description, required: required, choices: choices)
def string(name, description, required: nil, min_length: nil, max_length: nil, choices: nil)
option(TYPES[:string], name, description,
required: required, min_length: min_length, max_length: max_length, choices: choices)
end

# @param name [String, Symbol] The name of the argument.
# @param description [String] A description of the argument.
# @param required [true, false] Whether this option must be provided.
# @param min_value [Integer] A minimum value for option.
# @param max_value [Integer] A maximum value for option.
# @param choices [Hash, nil] Available choices, mapped as `Name => Value`.
# @return (see #option)
def integer(name, description, required: nil, choices: nil)
option(TYPES[:integer], name, description, required: required, choices: choices)
def integer(name, description, required: nil, min_value: nil, max_value: nil, choices: nil)
option(TYPES[:integer], name, description,
required: required, min_value: min_value, max_value: max_value, choices: choices)
end

# @param name [String, Symbol] The name of the argument.
Expand Down Expand Up @@ -526,6 +532,8 @@ def mentionable(name, description, required: nil)
# @param name [String, Symbol] The name of the argument.
# @param description [String] A description of the argument.
# @param required [true, false] Whether this option must be provided.
# @param min_value [Float] A minimum value for option.
# @param max_value [Float] A maximum value for option.
# @return (see #option)
def number(name, description, required: nil, min_value: nil, max_value: nil, choices: nil)
option(TYPES[:number], name, description,
Expand All @@ -547,15 +555,18 @@ def attachment(name, description, required: nil)
# @param required [true, false] Whether this option must be provided.
# @param min_value [Integer, Float] A minimum value for integer and number options.
# @param max_value [Integer, Float] A maximum value for integer and number options.
# @param min_length [Integer] A minimum length for string option value.
# @param max_length [Integer] A maximum length for string option value.
# @param channel_types [Array<Integer>] Channel types that can be provides for channel options.
# @return Hash
def option(type, name, description, required: nil, choices: nil, options: nil, min_value: nil, max_value: nil,
channel_types: nil)
min_length: nil, max_length: nil, channel_types: nil)
opt = { type: type, name: name, description: description }
choices = choices.map { |option_name, value| { name: option_name, value: value } } if choices

opt.merge!({ required: required, choices: choices, options: options, min_value: min_value,
max_value: max_value, channel_types: channel_types }.compact)
max_value: max_value, min_length: min_length, max_length: max_length,
channel_types: channel_types }.compact)

@options << opt
opt
Expand Down
Loading