discorb 0.13.4 → 0.15.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +2 -0
  3. data/.github/workflows/build_version.yml +1 -1
  4. data/.github/workflows/codeql-analysis.yml +70 -0
  5. data/.github/workflows/lint-push.yml +20 -0
  6. data/.github/workflows/lint.yml +16 -0
  7. data/.rubocop.yml +74 -0
  8. data/Changelog.md +30 -0
  9. data/Gemfile +7 -3
  10. data/Rakefile +28 -22
  11. data/discorb.gemspec +1 -0
  12. data/docs/events.md +50 -0
  13. data/docs/faq.md +8 -8
  14. data/examples/commands/bookmarker.rb +2 -1
  15. data/examples/commands/hello.rb +1 -0
  16. data/examples/commands/inspect.rb +3 -2
  17. data/examples/components/authorization_button.rb +2 -1
  18. data/examples/components/select_menu.rb +2 -1
  19. data/examples/extension/main.rb +1 -0
  20. data/examples/extension/message_expander.rb +1 -0
  21. data/examples/simple/eval.rb +3 -2
  22. data/examples/simple/ping_pong.rb +1 -0
  23. data/examples/simple/rolepanel.rb +1 -0
  24. data/examples/simple/wait_for_message.rb +4 -3
  25. data/exe/discorb +8 -7
  26. data/lib/discorb/allowed_mentions.rb +71 -0
  27. data/lib/discorb/app_command/command.rb +336 -0
  28. data/lib/discorb/app_command/handler.rb +168 -0
  29. data/lib/discorb/app_command.rb +2 -426
  30. data/lib/discorb/application.rb +16 -7
  31. data/lib/discorb/asset.rb +11 -0
  32. data/lib/discorb/{file.rb → attachment.rb} +55 -33
  33. data/lib/discorb/audit_logs.rb +45 -7
  34. data/lib/discorb/channel.rb +65 -15
  35. data/lib/discorb/client.rb +34 -27
  36. data/lib/discorb/common.rb +19 -27
  37. data/lib/discorb/components/button.rb +105 -0
  38. data/lib/discorb/components/select_menu.rb +143 -0
  39. data/lib/discorb/components/text_input.rb +96 -0
  40. data/lib/discorb/components.rb +11 -276
  41. data/lib/discorb/dictionary.rb +5 -0
  42. data/lib/discorb/embed.rb +73 -40
  43. data/lib/discorb/emoji.rb +48 -5
  44. data/lib/discorb/error.rb +9 -5
  45. data/lib/discorb/event.rb +36 -24
  46. data/lib/discorb/exe/about.rb +1 -0
  47. data/lib/discorb/exe/irb.rb +4 -3
  48. data/lib/discorb/exe/new.rb +6 -7
  49. data/lib/discorb/exe/run.rb +2 -1
  50. data/lib/discorb/exe/setup.rb +8 -5
  51. data/lib/discorb/exe/show.rb +1 -0
  52. data/lib/discorb/extend.rb +19 -14
  53. data/lib/discorb/extension.rb +5 -1
  54. data/lib/discorb/gateway.rb +112 -51
  55. data/lib/discorb/gateway_requests.rb +4 -7
  56. data/lib/discorb/guild.rb +73 -41
  57. data/lib/discorb/guild_template.rb +26 -5
  58. data/lib/discorb/http.rb +38 -18
  59. data/lib/discorb/integration.rb +24 -9
  60. data/lib/discorb/intents.rb +16 -11
  61. data/lib/discorb/interaction/autocomplete.rb +6 -5
  62. data/lib/discorb/interaction/command.rb +66 -12
  63. data/lib/discorb/interaction/components.rb +19 -3
  64. data/lib/discorb/interaction/modal.rb +33 -0
  65. data/lib/discorb/interaction/response.rb +45 -4
  66. data/lib/discorb/interaction/root.rb +16 -0
  67. data/lib/discorb/interaction.rb +2 -1
  68. data/lib/discorb/invite.rb +11 -7
  69. data/lib/discorb/log.rb +5 -5
  70. data/lib/discorb/member.rb +22 -3
  71. data/lib/discorb/message.rb +39 -234
  72. data/lib/discorb/message_meta.rb +186 -0
  73. data/lib/discorb/modules.rb +39 -15
  74. data/lib/discorb/permission.rb +16 -7
  75. data/lib/discorb/presence.rb +45 -9
  76. data/lib/discorb/rate_limit.rb +7 -4
  77. data/lib/discorb/reaction.rb +6 -0
  78. data/lib/discorb/role.rb +12 -0
  79. data/lib/discorb/sticker.rb +22 -14
  80. data/lib/discorb/user.rb +12 -1
  81. data/lib/discorb/utils/colored_puts.rb +1 -0
  82. data/lib/discorb/voice_state.rb +23 -2
  83. data/lib/discorb/webhook.rb +54 -3
  84. data/lib/discorb.rb +5 -2
  85. data/sig/discorb.rbs +838 -702
  86. data/template-replace/scripts/arrow.rb +1 -0
  87. data/template-replace/scripts/favicon.rb +1 -0
  88. data/template-replace/scripts/index.rb +2 -1
  89. data/template-replace/scripts/locale_ja.rb +5 -4
  90. data/template-replace/scripts/sidebar.rb +1 -0
  91. data/template-replace/scripts/version.rb +7 -10
  92. data/template-replace/scripts/yard_replace.rb +5 -4
  93. metadata +17 -3
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents a button component.
6
+ #
7
+ class Button < Component
8
+ # @return [String] The label of the button.
9
+ attr_accessor :label
10
+ # @return [:primary, :secondary, :success, :danger, :link] The style of the button.
11
+ attr_accessor :style
12
+ # @return [Discorb::Emoji] The emoji of the button.
13
+ attr_accessor :emoji
14
+ # @return [String] The custom ID of the button.
15
+ # Won't be used if the style is `:link`.
16
+ attr_accessor :custom_id
17
+ # @return [String] The URL of the button.
18
+ # Only used when the style is `:link`.
19
+ attr_accessor :url
20
+ # @return [Boolean] Whether the button is disabled.
21
+ attr_accessor :disabled
22
+ alias disabled? disabled
23
+
24
+ # @private
25
+ # @return [{Symbol => Integer}] The mapping of button styles.
26
+ STYLES = {
27
+ primary: 1,
28
+ secondary: 2,
29
+ success: 3,
30
+ danger: 4,
31
+ link: 5,
32
+ }.freeze
33
+
34
+ #
35
+ # Initialize a new button.
36
+ #
37
+ # @param [String] label The label of the button.
38
+ # @param [:primary, :secondary, :success, :danger, :link] style The style of the button.
39
+ # @param [Discorb::Emoji] emoji The emoji of the button.
40
+ # @param [String] custom_id The custom ID of the button.
41
+ # @param [String] url The URL of the button.
42
+ # @param [Boolean] disabled Whether the button is disabled.
43
+ #
44
+ def initialize(label, style = :primary, emoji: nil, custom_id: nil, url: nil, disabled: false)
45
+ @label = label
46
+ @style = style
47
+ @emoji = emoji
48
+ @custom_id = custom_id
49
+ @url = url
50
+ @disabled = disabled
51
+ end
52
+
53
+ #
54
+ # Converts the button to a hash.
55
+ #
56
+ # @see https://discord.com/developers/docs/interactions/message-components#button-object-button-structure Official Discord API docs
57
+ # @return [Hash] A hash representation of the button.
58
+ #
59
+ def to_hash
60
+ if @style == :link
61
+ {
62
+ type: 2,
63
+ label: @label,
64
+ style: STYLES[@style],
65
+ url: @url,
66
+ emoji: @emoji&.to_hash,
67
+ disabled: @disabled,
68
+ }
69
+ else
70
+ {
71
+ type: 2,
72
+ label: @label,
73
+ style: STYLES[@style],
74
+ custom_id: @custom_id,
75
+ emoji: @emoji&.to_hash,
76
+ disabled: @disabled,
77
+ }
78
+ end
79
+ end
80
+
81
+ def inspect
82
+ "#<#{self.class}: #{@custom_id || @url}>"
83
+ end
84
+
85
+ class << self
86
+ #
87
+ # Creates a new button from a hash.
88
+ #
89
+ # @param [Hash] data The hash to create the button from.
90
+ #
91
+ # @return [Discorb::Button] The created button.
92
+ #
93
+ def from_hash(data)
94
+ new(
95
+ data[:label],
96
+ data[:style],
97
+ emoji: data[:emoji],
98
+ custom_id: data[:custom_id],
99
+ url: data[:url],
100
+ disabled: data[:disabled],
101
+ )
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents a select menu component.
6
+ #
7
+ class SelectMenu < Component
8
+ # @return [String] The custom ID of the select menu.
9
+ attr_accessor :custom_id
10
+ # @return [Array<SelectMenu::Option>] The options of the select menu.
11
+ attr_accessor :options
12
+ # @return [Integer] The minimum number of values.
13
+ attr_accessor :min_values
14
+ # @return [Integer] The maximum number of values.
15
+ attr_accessor :max_values
16
+ # @return [Boolean] Whether the select menu is disabled.
17
+ attr_accessor :disabled
18
+ alias disabled? disabled
19
+
20
+ #
21
+ # Initialize a new select menu.
22
+ #
23
+ # @param [String, Symbol] custom_id Custom ID of the select menu.
24
+ # @param [Array<Discorb::SelectMenu::Option>] options The options of the select menu.
25
+ # @param [String] placeholder The placeholder of the select menu.
26
+ # @param [Integer] min_values The minimum number of values.
27
+ # @param [Integer] max_values The maximum number of values.
28
+ #
29
+ def initialize(custom_id, options, placeholder: nil, min_values: 1, max_values: 1)
30
+ @custom_id = custom_id
31
+ @options = options
32
+ @placeholder = placeholder
33
+ @min_values = min_values
34
+ @max_values = max_values
35
+ end
36
+
37
+ #
38
+ # Converts the select menu to a hash.
39
+ #
40
+ # @see https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-menu-structure Official Discord API docs
41
+ # @return [Hash] A hash representation of the select menu.
42
+ #
43
+ def to_hash
44
+ {
45
+ type: 3,
46
+ custom_id: @custom_id,
47
+ options: @options.map(&:to_hash),
48
+ placeholder: @placeholder,
49
+ min_values: @min_values,
50
+ max_values: @max_values,
51
+ disabled: @disabled,
52
+ }
53
+ end
54
+
55
+ def inspect
56
+ "#<#{self.class}: #{@custom_id}>"
57
+ end
58
+
59
+ class << self
60
+ #
61
+ # Creates a new select menu from a hash.
62
+ #
63
+ # @param [Hash] data The hash to create the select menu from.
64
+ #
65
+ # @return [Discorb::SelectMenu] The created select menu.
66
+ #
67
+ def from_hash(data)
68
+ new(
69
+ data[:custom_id],
70
+ data[:options].map { |o| SelectMenu::Option.from_hash(o) },
71
+ placeholder: data[:placeholder],
72
+ min_values: data[:min_values],
73
+ max_values: data[:max_values],
74
+ )
75
+ end
76
+ end
77
+
78
+ #
79
+ # Represents an option of a select menu.
80
+ #
81
+ class Option
82
+ # @return [String] The label of the option.
83
+ attr_accessor :label
84
+ # @return [String] The value of the option.
85
+ attr_accessor :value
86
+ # @return [String] The description of the option.
87
+ attr_accessor :description
88
+ # @return [Discorb::Emoji] The emoji of the option.
89
+ attr_accessor :emoji
90
+ # @return [Boolean] Whether the option is default.
91
+ attr_accessor :default
92
+
93
+ #
94
+ # Initialize a new option.
95
+ #
96
+ # @param [String] label The label of the option.
97
+ # @param [String] value The value of the option.
98
+ # @param [String] description The description of the option.
99
+ # @param [Discorb::Emoji] emoji The emoji of the option.
100
+ # @param [Boolean] default Whether the option is default.
101
+ def initialize(label, value, description: nil, emoji: nil, default: false)
102
+ @label = label
103
+ @value = value
104
+ @description = description
105
+ @emoji = emoji
106
+ @default = default
107
+ end
108
+
109
+ #
110
+ # Converts the option to a hash.
111
+ #
112
+ # @see https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-option-structure Official Discord API docs
113
+ # @return [Hash] Hash representation of the option.
114
+ #
115
+ def to_hash
116
+ {
117
+ label: @label,
118
+ value: @value,
119
+ description: @description,
120
+ emoji: @emoji&.to_hash,
121
+ default: @default,
122
+ }
123
+ end
124
+
125
+ def inspect
126
+ "#<#{self.class} #{@label}: #{@value}>"
127
+ end
128
+
129
+ class << self
130
+ #
131
+ # Creates a new option from a hash.
132
+ #
133
+ # @param [Hash] data A hash representing the option.
134
+ #
135
+ # @return [Discorb::SelectMenu::Option] A new option.
136
+ #
137
+ def from_hash(data)
138
+ new(data[:label], data[:value], description: data[:description], emoji: data[:emoji], default: data[:default])
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents a text input component.
6
+ #
7
+ class TextInput < Component
8
+ # @private
9
+ STYLES = {
10
+ short: 1,
11
+ paragraph: 2,
12
+ }.freeze
13
+
14
+ # @return [String] The label of the text input.
15
+ attr_accessor :label
16
+ # @return [String] The custom id of the text input.
17
+ attr_accessor :custom_id
18
+ # @return [:short, :paragraph] The style of the text input.
19
+ attr_accessor :style
20
+ # @return [Integer, nil] The minimum length of the text input.
21
+ attr_accessor :min_length
22
+ # @return [Integer, nil] The maximum length of the text input.
23
+ attr_accessor :max_length
24
+ # @return [Boolean] Whether the text input is required.
25
+ attr_accessor :required
26
+ # @return [String, nil] The prefilled value of the text input.
27
+ attr_accessor :value
28
+ # @return [String, nil] The placeholder of the text input.
29
+ attr_accessor :placeholder
30
+
31
+ #
32
+ # Initialize a new text input component.
33
+ #
34
+ # @param [String] label The label of the text input.
35
+ # @param [String] custom_id The custom id of the text input.
36
+ # @param [:short, :paragraph] style The style of the text input.
37
+ # @param [Integer, nil] min_length The minimum length of the text input.
38
+ # @param [Integer, nil] max_length The maximum length of the text input.
39
+ # @param [Boolean] required Whether the text input is required.
40
+ # @param [String, nil] value The prefilled value of the text input.
41
+ # @param [String, nil] placeholder The placeholder of the text input.
42
+ #
43
+ def initialize(label, custom_id, style, min_length: nil, max_length: nil, required: false, value: nil, placeholder: nil)
44
+ @label = label
45
+ @custom_id = custom_id
46
+ @style = style
47
+ @min_length = min_length
48
+ @max_length = max_length
49
+ @required = required
50
+ @value = value
51
+ @placeholder = placeholder
52
+ end
53
+
54
+ #
55
+ # Converts the select menu to a hash.
56
+ #
57
+ # @see https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure Official Discord API docs
58
+ # @return [Hash] A hash representation of the text input.
59
+ #
60
+ def to_hash
61
+ {
62
+ type: 4,
63
+ label: @label,
64
+ style: STYLES[@style],
65
+ custom_id: @custom_id,
66
+ min_length: @min_length,
67
+ max_length: @max_length,
68
+ required: @required,
69
+ value: @value,
70
+ placeholder: @placeholder,
71
+ }
72
+ end
73
+
74
+ class << self
75
+ #
76
+ # Creates a new text input from a hash.
77
+ #
78
+ # @param [Hash] data The hash to create the text input from.
79
+ #
80
+ # @return [Discorb::TextInput] The created text input.
81
+ #
82
+ def from_hash(data)
83
+ new(
84
+ data[:label],
85
+ data[:custom_id],
86
+ STYLES.key(data[:style]),
87
+ min_length: data[:min_length],
88
+ max_length: data[:max_length],
89
+ required: data[:required],
90
+ value: data[:value],
91
+ placeholder: data[:placeholder],
92
+ )
93
+ end
94
+ end
95
+ end
96
+ end
@@ -22,23 +22,12 @@ module Discorb
22
22
  def from_hash(data)
23
23
  case data[:type]
24
24
  when 2
25
- Button.new(
26
- data[:label],
27
- data[:style],
28
- emoji: data[:emoji],
29
- custom_id: data[:custom_id],
30
- url: data[:url],
31
- disabled: data[:disabled],
32
- )
25
+ Button
33
26
  when 3
34
- SelectMenu.new(
35
- data[:custom_id],
36
- data[:options].map { |o| SelectMenu::Option.from_hash(o) },
37
- placeholder: data[:placeholder],
38
- min_values: data[:min_values],
39
- max_values: data[:max_values],
40
- )
41
- end
27
+ SelectMenu
28
+ when 4
29
+ TextInput
30
+ end.from_hash(data)
42
31
  end
43
32
 
44
33
  #
@@ -57,7 +46,7 @@ module Discorb
57
46
  tmp_components << tmp_row
58
47
  tmp_row = []
59
48
  tmp_components << c
60
- when SelectMenu
49
+ when SelectMenu, TextInput
61
50
  tmp_components << tmp_row
62
51
  tmp_row = []
63
52
  tmp_components << [c]
@@ -66,266 +55,12 @@ module Discorb
66
55
  end
67
56
  end
68
57
  tmp_components << tmp_row
69
- return tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
70
- end
71
- end
72
- end
73
-
74
- #
75
- # Represents a button component.
76
- #
77
- class Button < Component
78
- # @return [String] The label of the button.
79
- attr_accessor :label
80
- # @return [:primary, :secondary, :success, :danger, :link] The style of the button.
81
- attr_accessor :style
82
- # @return [Discorb::Emoji] The emoji of the button.
83
- attr_accessor :emoji
84
- # @return [String] The custom ID of the button.
85
- # Won't be used if the style is `:link`.
86
- attr_accessor :custom_id
87
- # @return [String] The URL of the button.
88
- # Only used when the style is `:link`.
89
- attr_accessor :url
90
- # @return [Boolean] Whether the button is disabled.
91
- attr_accessor :disabled
92
- alias disabled? disabled
93
-
94
- @styles = {
95
- primary: 1,
96
- secondary: 2,
97
- success: 3,
98
- danger: 4,
99
- link: 5,
100
- }.freeze
101
-
102
- #
103
- # Initialize a new button.
104
- #
105
- # @param [String] label The label of the button.
106
- # @param [:primary, :secondary, :success, :danger, :link] style The style of the button.
107
- # @param [Discorb::Emoji] emoji The emoji of the button.
108
- # @param [String] custom_id The custom ID of the button.
109
- # @param [String] url The URL of the button.
110
- # @param [Boolean] disabled Whether the button is disabled.
111
- #
112
- def initialize(label, style = :primary, emoji: nil, custom_id: nil, url: nil, disabled: false)
113
- @label = label
114
- @style = style
115
- @emoji = emoji
116
- @custom_id = custom_id
117
- @url = url
118
- @disabled = disabled
119
- end
120
-
121
- #
122
- # Converts the button to a hash.
123
- #
124
- # @see https://discord.com/developers/docs/interactions/message-components#button-object-button-structure Official Discord API docs
125
- # @return [Hash] A hash representation of the button.
126
- #
127
- def to_hash
128
- if @style == :link
129
- {
130
- type: 2,
131
- label: @label,
132
- style: self.class.styles[@style],
133
- url: @url,
134
- emoji: hash_emoji(@emoji),
135
- disabled: @disabled,
136
- }
137
- else
138
- {
139
- type: 2,
140
- label: @label,
141
- style: self.class.styles[@style],
142
- custom_id: @custom_id,
143
- emoji: hash_emoji(@emoji),
144
- disabled: @disabled,
145
- }
146
- end
147
- end
148
-
149
- def inspect
150
- "#<#{self.class}: #{@custom_id || @url}>"
151
- end
152
-
153
- class << self
154
- # @private
155
- attr_reader :styles
156
- end
157
-
158
- private
159
-
160
- def hash_emoji(emoji)
161
- case emoji
162
- when UnicodeEmoji
163
- {
164
- id: nil,
165
- name: emoji.to_s,
166
- animated: false,
167
- }
168
- when CustomEmoji
169
- {
170
- id: emoji.id,
171
- name: emoji.name,
172
- animated: emoji.animated?,
173
- }
174
- end
175
- end
176
- end
177
-
178
- #
179
- # Represents a select menu component.
180
- #
181
- class SelectMenu < Component
182
- # @return [String] The custom ID of the select menu.
183
- attr_accessor :custom_id
184
- # @return [Array<SelectMenu::Option>] The options of the select menu.
185
- attr_accessor :options
186
- # @return [Integer] The minimum number of values.
187
- attr_accessor :min_values
188
- # @return [Integer] The maximum number of values.
189
- attr_accessor :max_values
190
- # @return [Boolean] Whether the select menu is disabled.
191
- attr_accessor :disabled
192
- alias disabled? disabled
193
-
194
- #
195
- # Initialize a new select menu.
196
- #
197
- # @param [String, Symbol] custom_id Custom ID of the select menu.
198
- # @param [Array<Discorb::SelectMenu::Option>] options The options of the select menu.
199
- # @param [String] placeholder The placeholder of the select menu.
200
- # @param [Integer] min_values The minimum number of values.
201
- # @param [Integer] max_values The maximum number of values.
202
- #
203
- def initialize(custom_id, options, placeholder: nil, min_values: 1, max_values: 1)
204
- @custom_id = custom_id
205
- @options = options
206
- @placeholder = placeholder
207
- @min_values = min_values
208
- @max_values = max_values
209
- end
210
-
211
- #
212
- # Converts the select menu to a hash.
213
- #
214
- # @see https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-menu-structure Official Discord API docs
215
- # @return [Hash] A hash representation of the select menu.
216
- #
217
- def to_hash
218
- {
219
- type: 3,
220
- custom_id: @custom_id,
221
- options: @options.map(&:to_hash),
222
- placeholder: @placeholder,
223
- min_values: @min_values,
224
- max_values: @max_values,
225
- disabled: @disabled,
226
- }
227
- end
228
-
229
- def inspect
230
- "#<#{self.class}: #{@custom_id}>"
231
- end
232
-
233
- #
234
- # Represents an option of a select menu.
235
- #
236
- class Option
237
- # @return [String] The label of the option.
238
- attr_accessor :label
239
- # @return [String] The value of the option.
240
- attr_accessor :value
241
- # @return [String] The description of the option.
242
- attr_accessor :description
243
- # @return [Discorb::Emoji] The emoji of the option.
244
- attr_accessor :emoji
245
- # @return [Boolean] Whether the option is default.
246
- attr_accessor :default
247
-
248
- #
249
- # Initialize a new option.
250
- #
251
- # @param [String] label The label of the option.
252
- # @param [String] value The value of the option.
253
- # @param [String] description The description of the option.
254
- # @param [Discorb::Emoji] emoji The emoji of the option.
255
- # @param [Boolean] default Whether the option is default.
256
- def initialize(label, value, description: nil, emoji: nil, default: false)
257
- @label = label
258
- @value = value
259
- @description = description
260
- @emoji = emoji
261
- @default = default
262
- end
263
-
264
- #
265
- # Converts the option to a hash.
266
- #
267
- # @see https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-option-structure Official Discord API docs
268
- # @return [Hash] Hash representation of the option.
269
- #
270
- def to_hash
271
- {
272
- label: @label,
273
- value: @value,
274
- description: @description,
275
- emoji: hash_emoji(@emoji),
276
- default: @default,
277
- }
278
- end
279
-
280
- # @private
281
- def hash_emoji(emoji)
282
- case emoji
283
- when UnicodeEmoji
284
- {
285
- id: nil,
286
- name: emoji.to_s,
287
- animated: false,
288
- }
289
- when CustomEmoji
290
- {
291
- id: emoji.id,
292
- name: emoji.name,
293
- animated: emoji.animated?,
294
- }
295
- end
296
- end
297
-
298
- class << self
299
- #
300
- # Creates a new option from a hash.
301
- #
302
- # @param [Hash] data A hash representing the option.
303
- #
304
- # @return [Discorb::SelectMenu::Option] A new option.
305
- #
306
- def from_hash(data)
307
- new(data[:label], data[:value], description: data[:description], emoji: data[:emoji], default: data[:default])
308
- end
309
- end
310
- end
311
-
312
- private
313
-
314
- def hash_emoji(emoji)
315
- case emoji
316
- when UnicodeEmoji
317
- {
318
- id: nil,
319
- name: emoji.to_s,
320
- animated: false,
321
- }
322
- when CustomEmoji
323
- {
324
- id: emoji.id,
325
- name: emoji.name,
326
- animated: emoji.animated?,
327
- }
58
+ tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
328
59
  end
329
60
  end
330
61
  end
331
62
  end
63
+
64
+ %w[button text_input select_menu].each do |name|
65
+ require_relative "components/#{name}"
66
+ end
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Discorb
4
+ #
5
+ # Extended hash class. This is used for storing pair of ID and object.
6
+ #
4
7
  class Dictionary
5
8
  # @return [Integer] The maximum number of items in the dictionary.
6
9
  attr_accessor :limit
@@ -52,6 +55,8 @@ module Discorb
52
55
  @cache.delete(id.to_s)
53
56
  end
54
57
 
58
+ alias delete remove
59
+
55
60
  #
56
61
  # Get an item from the dictionary.
57
62
  #