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

feat: add support for filters on channel type of channel selector #242

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion examples/select_menus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
'channel_select', false, nil, nil, nil, nil,
Discordrb::Components::View.new do |builder|
builder.row do |r|
r.channel_select(custom_id: 'channel_select', placeholder: 'Test of ChannelSelect', max_values: 3)
r.channel_select(custom_id: 'channel_select', placeholder: 'Test of ChannelSelect', max_values: 3, channel_types: %i[text voice])
end
end
)
Expand Down
4 changes: 3 additions & 1 deletion lib/discordrb/data/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Channel
include IDObject

# Map of channel types
# @see https://discord.com/developers/docs/resources/channel#channel-object-channel-types
TYPES = {
text: 0,
dm: 1,
Expand All @@ -22,7 +23,8 @@ class Channel
private_thread: 12,
stage_voice: 13,
directory: 14,
forum: 15
forum: 15,
media: 16
}.freeze

# @return [String] this channel's name.
Expand Down
12 changes: 10 additions & 2 deletions lib/discordrb/webhooks/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,16 @@ def mentionable_select(custom_id:, placeholder: nil, min_values: nil, max_values
# @param min_values [Integer, nil] The minimum amount of values a user must select.
# @param max_values [Integer, nil] The maximum amount of values a user can select.
# @param disabled [true, false, nil] Grey out the component to make it unusable.
def channel_select(custom_id:, placeholder: nil, min_values: nil, max_values: nil, disabled: nil)
@components << SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, disabled, select_type: :channel_select).to_h
# @param channel_types [Array<Discordrb::Channel::TYPES>, nil] Display only the specific channel type(s).
def channel_select(custom_id:, placeholder: nil, min_values: nil, max_values: nil, disabled: nil, channel_types: nil)
builder = SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, disabled, select_type: :channel_select).to_h

if channel_types
types_selected = Discordrb::Channel::TYPES.values_at(*channel_types)
builder[:channel_types] = types_selected
end

@components << builder
end

# @!visibility private
Expand Down