Class: OnyxCord::Webhooks::View

Inherits:
Object
  • Object
show all
Defined in:
lib/onyxcord/webhooks/view.rb

Overview

A reusable view representing a component collection, with builder methods.

Defined Under Namespace

Classes: ContainerBuilder, FileBuilder, MediaGalleryBuilder, RowBuilder, SectionBuilder, SelectMenuBuilder, SeparatorBuilder, TextDisplayBuilder

Constant Summary collapse

BUTTON_STYLES =

Possible button style names and values.

{
  primary: 1,
  secondary: 2,
  success: 3,
  danger: 4,
  link: 5,
  premium: 6
}.freeze
SEPARATOR_SIZES =

Possible separator size names and values.

{
  small: 1,
  large: 2
}.freeze
COMPONENT_TYPES =

Component types.

{
  action_row: 1,
  button: 2,
  string_select: 3,
  # text_input: 4, # (defined in modal.rb)
  user_select: 5,
  role_select: 6,
  mentionable_select: 7,
  channel_select: 8,
  section: 9,
  text_display: 10,
  thumbnail: 11,
  media_gallery: 12,
  file: 13,
  separator: 14,
  container: 17
  # label: 18, # (defined in modal.rb)
  # file_upload: 19, (defined in modal.rb)
  # radio_group: 21, (defined in modal.rb)
  # checkbox_group: 22, (defined in modal.rb)
  # checkbox: 23 (defined in modal.rb)
}.freeze
IS_COMPONENTS_V2 =
OnyxCord::MessageComponents::IS_COMPONENTS_V2
V2_COMPONENT_TYPES =
OnyxCord::MessageComponents::V2_COMPONENT_TYPES

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.apply_v2_flag(flags, components, force: false) ⇒ Object



491
492
493
# File 'lib/onyxcord/webhooks/view.rb', line 491

def self.apply_v2_flag(flags, components, force: false)
  OnyxCord::MessageComponents.apply_v2_flag(flags, components, force: force)
end

.component_payload(components) ⇒ Object



487
488
489
# File 'lib/onyxcord/webhooks/view.rb', line 487

def self.component_payload(components)
  OnyxCord::MessageComponents.payload(components)
end

.components_v2?(components) ⇒ Boolean

Returns:

  • (Boolean)


483
484
485
# File 'lib/onyxcord/webhooks/view.rb', line 483

def self.components_v2?(components)
  OnyxCord::MessageComponents.components_v2?(components)
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


469
470
471
# File 'lib/onyxcord/webhooks/view.rb', line 469

def any?
  @components.any?
end

#components_v2?Boolean

Returns:

  • (Boolean)


473
474
475
# File 'lib/onyxcord/webhooks/view.rb', line 473

def components_v2?
  self.class.components_v2?(to_a)
end

#containerObject

Add a container component to the view.



523
524
525
# File 'lib/onyxcord/webhooks/view.rb', line 523

def container(...)
  @components << ContainerBuilder.new(...)
end

#empty?Boolean

Returns:

  • (Boolean)


465
466
467
# File 'lib/onyxcord/webhooks/view.rb', line 465

def empty?
  @components.empty?
end

#fileObject Also known as: file_display

Add a file component to the view.



503
504
505
# File 'lib/onyxcord/webhooks/view.rb', line 503

def file(...)
  @components << FileBuilder.new(...)
end

#flags(flags = 0) ⇒ Object



479
480
481
# File 'lib/onyxcord/webhooks/view.rb', line 479

def flags(flags = 0)
  self.class.apply_v2_flag(flags, to_a)
end

Add a media gallery component to the view.



535
536
537
# File 'lib/onyxcord/webhooks/view.rb', line 535

def media_gallery(...)
  @components << MediaGalleryBuilder.new(...)
end

#rowObject

Add a row component to the view.

See Also:

  • OnyxCord::Webhooks::View::RowBuilder#initialize


497
498
499
# File 'lib/onyxcord/webhooks/view.rb', line 497

def row(...)
  @components << RowBuilder.new(...)
end

#sectionObject

Add a section component to the view.



511
512
513
# File 'lib/onyxcord/webhooks/view.rb', line 511

def section(...)
  @components << SectionBuilder.new(...)
end

#separatorObject

Add a separator component to the view.



517
518
519
# File 'lib/onyxcord/webhooks/view.rb', line 517

def separator(...)
  @components << SeparatorBuilder.new(...)
end

#text_displayObject

Add a text display component to the view.



529
530
531
# File 'lib/onyxcord/webhooks/view.rb', line 529

def text_display(...)
  @components << TextDisplayBuilder.new(...)
end

#v2?Boolean

Returns:

  • (Boolean)


477
478
479
# File 'lib/onyxcord/webhooks/view.rb', line 477

def components_v2?
  self.class.components_v2?(to_a)
end