Class: OnyxCord::Webhooks::View

Inherits:
Object
  • Object
show all
Defined in:
lib/onyxcord/webhooks/view.rb,
lib/onyxcord/webhooks/view/row_builder.rb,
lib/onyxcord/webhooks/view/file_builder.rb,
lib/onyxcord/webhooks/view/section_builder.rb,
lib/onyxcord/webhooks/view/container_builder.rb,
lib/onyxcord/webhooks/view/separator_builder.rb,
lib/onyxcord/webhooks/view/select_menu_builder.rb,
lib/onyxcord/webhooks/view/text_display_builder.rb,
lib/onyxcord/webhooks/view/media_gallery_builder.rb

Overview

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

Direct Known Subclasses

Components::View

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

Constructor Details

#initialize {|_self| ... } ⇒ View

Returns a new instance of View.

Yields:

  • (_self)

Yield Parameters:



60
61
62
63
64
# File 'lib/onyxcord/webhooks/view.rb', line 60

def initialize
  @components = []

  yield self if block_given?
end

Class Method Details

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



97
98
99
# File 'lib/onyxcord/webhooks/view.rb', line 97

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

.component_payload(components) ⇒ Object



93
94
95
# File 'lib/onyxcord/webhooks/view.rb', line 93

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

.components_v2?(components) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/onyxcord/webhooks/view.rb', line 89

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

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/onyxcord/webhooks/view.rb', line 75

def any?
  @components.any?
end

#components_v2?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/onyxcord/webhooks/view.rb', line 79

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

#container(id: nil, color: nil, colour: nil, spoiler: false) {|builder| ... } ⇒ Object

Add a container component to the view.



139
140
141
142
143
144
# File 'lib/onyxcord/webhooks/view.rb', line 139

def container(id: nil, color: nil, colour: nil, spoiler: false)
  builder = ContainerBuilder.new(id: id, color: color, colour: colour, spoiler: spoiler)
  @components << builder
  yield builder if block_given?
  builder
end

#empty?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/onyxcord/webhooks/view.rb', line 71

def empty?
  @components.empty?
end

#fileObject Also known as: file_display

Add a file component to the view.



112
113
114
115
116
# File 'lib/onyxcord/webhooks/view.rb', line 112

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

#flags(flags = 0) ⇒ Object



85
86
87
# File 'lib/onyxcord/webhooks/view.rb', line 85

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

Add a media gallery component to the view.



156
157
158
159
160
161
# File 'lib/onyxcord/webhooks/view.rb', line 156

def media_gallery(*items, id: nil)
  builder = MediaGalleryBuilder.new(*items, id: id)
  @components << builder
  yield builder if block_given?
  builder
end

#row(id: nil) {|builder| ... } ⇒ Object

Add a row component to the view.

Yields:

  • (builder)

See Also:

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


103
104
105
106
107
108
# File 'lib/onyxcord/webhooks/view.rb', line 103

def row(id: nil)
  builder = RowBuilder.new(id: id)
  @components << builder
  yield builder if block_given?
  builder
end

#section(id: nil) {|builder| ... } ⇒ Object

Add a section component to the view.



122
123
124
125
126
127
# File 'lib/onyxcord/webhooks/view.rb', line 122

def section(id: nil)
  builder = SectionBuilder.new(id: id)
  @components << builder
  yield builder if block_given?
  builder
end

#separatorObject

Add a separator component to the view.



131
132
133
134
135
# File 'lib/onyxcord/webhooks/view.rb', line 131

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

#text_displayObject

Add a text display component to the view.



148
149
150
151
152
# File 'lib/onyxcord/webhooks/view.rb', line 148

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

#v2?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/onyxcord/webhooks/view.rb', line 83

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