discorb 0.13.2 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) 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 +70 -0
  8. data/CODE_OF_CONDUCT.md +128 -0
  9. data/Changelog.md +34 -0
  10. data/Gemfile +7 -3
  11. data/README.md +1 -1
  12. data/Rakefile +22 -22
  13. data/discorb.gemspec +13 -1
  14. data/docs/faq.md +8 -8
  15. data/examples/commands/bookmarker.rb +2 -1
  16. data/examples/commands/hello.rb +1 -0
  17. data/examples/commands/inspect.rb +3 -2
  18. data/examples/components/authorization_button.rb +2 -1
  19. data/examples/components/select_menu.rb +2 -1
  20. data/examples/extension/main.rb +1 -0
  21. data/examples/extension/message_expander.rb +1 -0
  22. data/examples/simple/eval.rb +3 -2
  23. data/examples/simple/ping_pong.rb +1 -0
  24. data/examples/simple/rolepanel.rb +1 -0
  25. data/examples/simple/wait_for_message.rb +4 -3
  26. data/exe/discorb +8 -7
  27. data/lib/discorb/allowed_mentions.rb +64 -0
  28. data/lib/discorb/app_command/command.rb +274 -0
  29. data/lib/discorb/app_command/handler.rb +168 -0
  30. data/lib/discorb/app_command.rb +2 -404
  31. data/lib/discorb/asset.rb +3 -1
  32. data/lib/discorb/{file.rb → attachment.rb} +42 -35
  33. data/lib/discorb/audit_logs.rb +3 -3
  34. data/lib/discorb/channel.rb +65 -61
  35. data/lib/discorb/client.rb +36 -33
  36. data/lib/discorb/common.rb +29 -22
  37. data/lib/discorb/components/button.rb +106 -0
  38. data/lib/discorb/components/select_menu.rb +157 -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 +13 -2
  42. data/lib/discorb/embed.rb +40 -33
  43. data/lib/discorb/emoji.rb +21 -5
  44. data/lib/discorb/emoji_table.rb +1 -1
  45. data/lib/discorb/error.rb +4 -6
  46. data/lib/discorb/event.rb +13 -11
  47. data/lib/discorb/exe/about.rb +1 -0
  48. data/lib/discorb/exe/irb.rb +4 -3
  49. data/lib/discorb/exe/new.rb +6 -7
  50. data/lib/discorb/exe/run.rb +2 -1
  51. data/lib/discorb/exe/setup.rb +8 -5
  52. data/lib/discorb/exe/show.rb +1 -0
  53. data/lib/discorb/extend.rb +19 -14
  54. data/lib/discorb/extension.rb +5 -1
  55. data/lib/discorb/gateway.rb +82 -29
  56. data/lib/discorb/guild.rb +58 -80
  57. data/lib/discorb/guild_template.rb +5 -5
  58. data/lib/discorb/http.rb +52 -170
  59. data/lib/discorb/integration.rb +32 -3
  60. data/lib/discorb/intents.rb +9 -4
  61. data/lib/discorb/interaction/autocomplete.rb +5 -4
  62. data/lib/discorb/interaction/command.rb +34 -9
  63. data/lib/discorb/interaction/components.rb +5 -2
  64. data/lib/discorb/interaction/modal.rb +33 -0
  65. data/lib/discorb/interaction/response.rb +41 -12
  66. data/lib/discorb/interaction/root.rb +1 -0
  67. data/lib/discorb/interaction.rb +2 -1
  68. data/lib/discorb/invite.rb +1 -1
  69. data/lib/discorb/log.rb +4 -3
  70. data/lib/discorb/member.rb +4 -6
  71. data/lib/discorb/message.rb +38 -241
  72. data/lib/discorb/message_meta.rb +157 -0
  73. data/lib/discorb/modules.rb +47 -23
  74. data/lib/discorb/permission.rb +2 -2
  75. data/lib/discorb/presence.rb +6 -3
  76. data/lib/discorb/rate_limit.rb +15 -21
  77. data/lib/discorb/role.rb +3 -3
  78. data/lib/discorb/sticker.rb +2 -2
  79. data/lib/discorb/user.rb +3 -3
  80. data/lib/discorb/utils/colored_puts.rb +1 -0
  81. data/lib/discorb/voice_state.rb +7 -2
  82. data/lib/discorb/webhook.rb +9 -6
  83. data/lib/discorb.rb +2 -1
  84. data/sig/discorb.rbs +5836 -6714
  85. data/template-replace/scripts/arrow.rb +1 -0
  86. data/template-replace/scripts/favicon.rb +1 -0
  87. data/template-replace/scripts/index.rb +2 -1
  88. data/template-replace/scripts/locale_ja.rb +5 -4
  89. data/template-replace/scripts/sidebar.rb +1 -0
  90. data/template-replace/scripts/version.rb +7 -10
  91. data/template-replace/scripts/yard_replace.rb +5 -4
  92. metadata +30 -5
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
1
2
  module Discorb
3
+ #
4
+ # Represents an interaction of Discord.
5
+ #
2
6
  class Interaction
3
7
  #
4
8
  # A module for response with source.
5
9
  #
6
- module SourceResponse
10
+ module SourceResponder
7
11
  #
8
12
  # Response with `DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE`(`5`).
9
13
  #
@@ -15,7 +19,7 @@ module Discorb
15
19
  #
16
20
  def defer_source(ephemeral: false)
17
21
  Async do
18
- @client.http.post("/interactions/#{@id}/#{@token}/callback", {
22
+ @client.http.request(Route.new("/interactions/#{@id}/#{@token}/callback", "//interactions/:interaction_id/:token/callback", :post), {
19
23
  type: 5,
20
24
  data: {
21
25
  flags: (ephemeral ? 1 << 6 : 0),
@@ -38,27 +42,27 @@ module Discorb
38
42
  # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
39
43
  # @param [Boolean] ephemeral Whether to make the response ephemeral.
40
44
  #
41
- # @return [Discorb::Interaction::SourceResponse::CallbackMessage, Discorb::Webhook::Message] The callback message.
45
+ # @return [Discorb::Interaction::SourceResponder::CallbackMessage, Discorb::Webhook::Message] The callback message.
42
46
  #
43
47
  def post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false)
44
48
  Async do
45
49
  payload = {}
46
50
  payload[:content] = content if content
47
51
  payload[:tts] = tts
48
- payload[:embeds] = (embeds || [embed])&.map { |e| e&.to_hash }.filter { _1 }
52
+ payload[:embeds] = (embeds || [embed]).map { |e| e&.to_hash }.filter { _1 }
49
53
  payload[:allowed_mentions] = allowed_mentions&.to_hash(@client.allowed_mentions) || @client.allowed_mentions.to_hash
50
54
  payload[:components] = Component.to_payload(components) if components
51
55
  payload[:flags] = (ephemeral ? 1 << 6 : 0)
52
56
 
53
57
  ret = if @responded
54
- _resp, data = @client.http.post("/webhooks/#{@application_id}/#{@token}", payload).wait
58
+ _resp, data = @client.http.request(Route.new("/webhooks/#{@application_id}/#{@token}", "//webhooks/:webhook_id/:token", :post), payload).wait
55
59
  webhook = Webhook::URLWebhook.new("/webhooks/#{@application_id}/#{@token}")
56
60
  Webhook::Message.new(webhook, data, @client)
57
61
  elsif @defered
58
- @client.http.patch("/webhooks/#{@application_id}/#{@token}/messages/@original", payload).wait
62
+ @client.http.request(Route.new("/webhooks/#{@application_id}/#{@token}/messages/@original", "//webhooks/:webhook_id/:token/messages/@original", :patch), payload).wait
59
63
  CallbackMessage.new(@client, payload, @application_id, @token)
60
64
  else
61
- @client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 4, data: payload }).wait
65
+ @client.http.request(Route.new("/interactions/#{@id}/#{@token}/callback", "//interactions/:interaction_id/:token/callback", :post), { type: 4, data: payload }).wait
62
66
  CallbackMessage.new(@client, payload, @application_id, @token)
63
67
  end
64
68
  @responded = true
@@ -66,6 +70,9 @@ module Discorb
66
70
  end
67
71
  end
68
72
 
73
+ #
74
+ # Represents of a callback message of interaction.
75
+ #
69
76
  class CallbackMessage
70
77
  # @private
71
78
  def initialize(client, data, application_id, token)
@@ -103,7 +110,7 @@ module Discorb
103
110
  payload[:attachments] = attachments.map(&:to_hash) if attachments != Discorb::Unset
104
111
  files = [file] if file != Discorb::Unset
105
112
  files = [] if files == Discorb::Unset
106
- @client.http.multipart_patch("/webhooks/#{@application_id}/#{@token}/messages/@original", payload, files, headers: headers).wait
113
+ @client.http.multipart_request(Route.new("/webhooks/#{@application_id}/#{@token}/messages/@original", "//webhooks/:webhook_id/:token/messages/@original", :patch), payload, files, headers: headers).wait
107
114
  end
108
115
  end
109
116
 
@@ -118,7 +125,7 @@ module Discorb
118
125
  #
119
126
  def delete!
120
127
  Async do
121
- @client.http.delete("/webhooks/#{@application_id}/#{@token}/messages/@original").wait
128
+ @client.http.request(Route.new("/webhooks/#{@application_id}/#{@token}/messages/@original", "//webhooks/:webhook_id/:token/messages/@original", :delete)).wait
122
129
  end
123
130
  end
124
131
  end
@@ -127,7 +134,7 @@ module Discorb
127
134
  #
128
135
  # A module for response with update.
129
136
  #
130
- module UpdateResponse
137
+ module UpdateResponder
131
138
  #
132
139
  # Response with `DEFERRED_UPDATE_MESSAGE`(`6`).
133
140
  # @async
@@ -138,7 +145,7 @@ module Discorb
138
145
  #
139
146
  def defer_update(ephemeral: false)
140
147
  Async do
141
- @client.http.post("/interactions/#{@id}/#{@token}/callback", {
148
+ @client.http.request(Route.new("/interactions/#{@id}/#{@token}/callback", "//interactions/:interaction_id/:token/callback", :post), {
142
149
  type: 6,
143
150
  data: {
144
151
  flags: (ephemeral ? 1 << 6 : 0),
@@ -176,11 +183,33 @@ module Discorb
176
183
  payload[:allowed_mentions] = allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
177
184
  payload[:components] = Component.to_payload(components) if components
178
185
  payload[:flags] = (ephemeral ? 1 << 6 : 0)
179
- @client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 7, data: payload }).wait
186
+ @client.http.request(Route.new("/interactions/#{@id}/#{@token}/callback", "//interactions/:interaction_id/:token/callback", :post), { type: 7, data: payload }).wait
180
187
  end
181
188
  end
182
189
  end
183
190
 
191
+ #
192
+ # A module for response with modal.
193
+ #
194
+ module ModalResponder
195
+ #
196
+ # Response with `MODAL`(`9`).
197
+ #
198
+ # @param [String] title The title of the modal.
199
+ # @param [String] custom_id The custom id of the modal.
200
+ # @param [Array<Discorb::TextInput>] components The text inputs to send.
201
+ #
202
+ # @return [Async::Task<void>] The task.
203
+ #
204
+ def show_modal(title, custom_id, components)
205
+ payload = { title: title, custom_id: custom_id, components: Component.to_payload(components) }
206
+ @client.http.request(
207
+ Route.new("/interactions/#{@id}/#{@token}/callback", "//interactions/:interaction_id/:token/callback", :post),
208
+ { type: 9, data: payload }
209
+ ).wait
210
+ end
211
+ end
212
+
184
213
  private
185
214
 
186
215
  def _set_data(*)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Discorb
2
3
  #
3
4
  # Represents a user interaction with the bot.
@@ -1,3 +1,4 @@
1
- %w[root response command components autocomplete].each do |file|
1
+ # frozen_string_literal: true
2
+ %w[root response command components autocomplete modal].each do |file|
2
3
  require_relative "interaction/#{file}.rb"
3
4
  end
@@ -105,7 +105,7 @@ module Discorb
105
105
  #
106
106
  def delete!(reason: nil)
107
107
  Async do
108
- @client.http.delete("/invites/#{@code}", audit_log_reason: reason)
108
+ @client.http.request(Route.new("/invites/#{@code}", "//invites/:code", :delete), audit_log_reason: reason)
109
109
  end
110
110
  end
111
111
 
data/lib/discorb/log.rb CHANGED
@@ -64,17 +64,18 @@ module Discorb
64
64
 
65
65
  def write_output(name, color, message, fallback)
66
66
  unless @out
67
- fallback.puts(message) if fallback
67
+ fallback&.puts(message)
68
68
 
69
69
  return
70
70
  end
71
71
 
72
72
  time = Time.now.iso8601
73
73
  if @colorize_log
74
- @out.puts("\e[90m#{time}\e[0m #{color}#{name.ljust(5)}\e[0m #{message}")
74
+ @out.write("\e[90m#{time}\e[0m #{color}#{name.ljust(5)}\e[0m #{message}\n")
75
75
  else
76
- @out.puts("#{time} #{name.ljust(5)} #{message}")
76
+ @out.write("#{time} #{name.ljust(5)} #{message}\n")
77
77
  end
78
+ @out.flush
78
79
  end
79
80
  end
80
81
  end
@@ -105,9 +105,7 @@ module Discorb
105
105
  end
106
106
 
107
107
  def permissions
108
- if owner?
109
- return Permission.new((1 << 38) - 1)
110
- end
108
+ return Permission.new((1 << 38) - 1) if owner?
111
109
  roles.map(&:permissions).sum(Permission.new(0))
112
110
  end
113
111
 
@@ -152,7 +150,7 @@ module Discorb
152
150
  #
153
151
  def add_role(role, reason: nil)
154
152
  Async do
155
- @client.http.put("/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}", nil, audit_log_reason: reason).wait
153
+ @client.http.request(Route.new("/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}", "//guilds/:guild_id/members/:user_id/roles/:role_id", :put), nil, audit_log_reason: reason).wait
156
154
  end
157
155
  end
158
156
 
@@ -167,7 +165,7 @@ module Discorb
167
165
  #
168
166
  def remove_role(role, reason: nil)
169
167
  Async do
170
- @client.http.delete("/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}", audit_log_reason: reason).wait
168
+ @client.http.request(Route.new("/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}", "//guilds/:guild_id/members/:user_id/roles/:role_id", :delete), audit_log_reason: reason).wait
171
169
  end
172
170
  end
173
171
 
@@ -200,7 +198,7 @@ module Discorb
200
198
  communication_disabled_until = timeout_until if timeout_until != Discorb::Unset
201
199
  payload[:communication_disabled_until] = communication_disabled_until&.iso8601 if communication_disabled_until != Discorb::Unset
202
200
  payload[:channel_id] = channel&.id if channel != Discorb::Unset
203
- @client.http.patch("/guilds/#{@guild_id}/members/#{@id}", payload, audit_log_reason: reason).wait
201
+ @client.http.request(Route.new("/guilds/#{@guild_id}/members/#{@id}", "//guilds/:guild_id/members/:user_id", :patch), payload, audit_log_reason: reason).wait
204
202
  end
205
203
  end
206
204
 
@@ -1,68 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Discorb
4
- #
5
- # Represents a allowed mentions in a message.
6
- #
7
- class AllowedMentions
8
- # @return [Boolean] Whether to allow @everyone or @here.
9
- attr_accessor :everyone
10
- # @return [Boolean, Array<Discorb::Role>] The roles to allow, or false to disable.
11
- attr_accessor :roles
12
- # @return [Boolean, Array<Discorb::User>] The users to allow, or false to disable.
13
- attr_accessor :users
14
- # @return [Boolean] Whether to ping the user that sent the message to reply.
15
- attr_accessor :replied_user
16
-
17
- #
18
- # Initializes a new instance of the AllowedMentions class.
19
- #
20
- # @param [Boolean] everyone Whether to allow @everyone or @here.
21
- # @param [Boolean, Array<Discorb::Role>] roles The roles to allow, or false to disable.
22
- # @param [Boolean, Array<Discorb::User>] users The users to allow, or false to disable.
23
- # @param [Boolean] replied_user Whether to ping the user that sent the message to reply.
24
- #
25
- def initialize(everyone: nil, roles: nil, users: nil, replied_user: nil)
26
- @everyone = everyone
27
- @roles = roles
28
- @users = users
29
- @replied_user = replied_user
30
- end
31
-
32
- def inspect
33
- "#<#{self.class} @everyone=#{@everyone} @roles=#{@roles} @users=#{@users} @replied_user=#{@replied_user}>"
34
- end
35
-
36
- # @private
37
- def to_hash(other = nil)
38
- payload = {
39
- parse: %w[everyone roles users],
40
- }
41
- replied_user = nil_merge(@replied_user, other&.replied_user)
42
- everyone = nil_merge(@everyone, other&.everyone)
43
- roles = nil_merge(@roles, other&.roles)
44
- users = nil_merge(@users, other&.users)
45
- payload[:replied_user] = replied_user
46
- payload[:parse].delete("everyone") if everyone == false
47
- if (roles == false) || roles.is_a?(Array)
48
- payload[:roles] = roles.map { |u| u.id.to_s } if roles.is_a? Array
49
- payload[:parse].delete("roles")
50
- end
51
- if (users == false) || users.is_a?(Array)
52
- payload[:users] = users.map { |u| u.id.to_s } if users.is_a? Array
53
- payload[:parse].delete("users")
54
- end
55
- payload
56
- end
57
-
58
- def nil_merge(*args)
59
- args.each do |a|
60
- return a unless a.nil?
61
- end
62
- nil
63
- end
64
- end
65
-
66
4
  #
67
5
  # Represents a message.
68
6
  #
@@ -257,38 +195,44 @@ module Discorb
257
195
  #
258
196
  def clean_content(user: true, channel: true, role: true, emoji: true, everyone: true, codeblock: false)
259
197
  ret = @content.dup
260
- ret.gsub!(/<@!?(\d+)>/) do |match|
261
- member = guild&.members&.[]($1)
262
- member ||= @client.users[$1]
263
- member ? "@#{member.name}" : "@Unknown User"
264
- end if user
265
- ret.gsub!(/<#(\d+)>/) do |match|
198
+ if user
199
+ ret.gsub!(/<@!?(\d+)>/) do |_match|
200
+ member = guild&.members&.[]($1)
201
+ member ||= @client.users[$1]
202
+ member ? "@#{member.name}" : "@Unknown User"
203
+ end
204
+ end
205
+ ret.gsub!(/<#(\d+)>/) do |_match|
266
206
  channel = @client.channels[$1]
267
207
  channel ? "<##{channel.id}>" : "#Unknown Channel"
268
208
  end
269
- ret.gsub!(/<@&(\d+)>/) do |match|
270
- role = guild&.roles&.[]($1)
271
- role ? "@#{role.name}" : "@Unknown Role"
272
- end if role
273
- ret.gsub!(/<a?:([a-zA-Z0-9_]+):\d+>/) do |match|
274
- $1
275
- end if emoji
209
+ if role
210
+ ret.gsub!(/<@&(\d+)>/) do |_match|
211
+ role = guild&.roles&.[]($1)
212
+ role ? "@#{role.name}" : "@Unknown Role"
213
+ end
214
+ end
215
+ if emoji
216
+ ret.gsub!(/<a?:([a-zA-Z0-9_]+):\d+>/) do |_match|
217
+ $1
218
+ end
219
+ end
276
220
  ret.gsub!(/@(everyone|here)/, "@\u200b\\1") if everyone
277
- unless codeblock
221
+ if codeblock
222
+ ret
223
+ else
278
224
  codeblocks = ret.split("```", -1)
279
225
  original_codeblocks = @content.scan(/```(.+?)```/m)
280
226
  res = []
281
227
  max = codeblocks.length
282
- codeblocks.each_with_index do |codeblock, i|
283
- if max % 2 == 0 && i == max - 1 or i.even?
284
- res << codeblock
228
+ codeblocks.each_with_index do |single_codeblock, i|
229
+ res << if max.even? && i == max - 1 || i.even?
230
+ single_codeblock
285
231
  else
286
- res << original_codeblocks[i / 2]
232
+ original_codeblocks[i / 2]
287
233
  end
288
234
  end
289
235
  res.join("```")
290
- else
291
- ret
292
236
  end
293
237
  end
294
238
 
@@ -300,16 +244,17 @@ module Discorb
300
244
  # @param [Discorb::Embed] embed The embed to send.
301
245
  # @param [Array<Discorb::Embed>] embeds The embeds to send.
302
246
  # @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions.
247
+ # @param [Array<Discorb::Attachment>] attachments The new attachments.
303
248
  # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
304
249
  # @param [Boolean] supress Whether to supress embeds.
305
250
  #
306
251
  # @return [Async::Task<void>] The task.
307
252
  #
308
- def edit(content = nil, embed: nil, embeds: nil, allowed_mentions: nil,
309
- components: nil, supress: nil)
253
+ def edit(content = Discorb::Unset, embed: Discorb::Unset, embeds: Discorb::Unset, allowed_mentions: Discorb::Unset,
254
+ attachments: Discorb::Unset, components: Discorb::Unset, supress: Discorb::Unset)
310
255
  Async do
311
256
  channel.edit_message(@id, content, embed: embed, embeds: embeds, allowed_mentions: allowed_mentions,
312
- components: components, supress: supress).wait
257
+ attachments: attachments, components: components, supress: supress).wait
313
258
  end
314
259
  end
315
260
 
@@ -379,7 +324,7 @@ module Discorb
379
324
  #
380
325
  def add_reaction(emoji)
381
326
  Async do
382
- @client.http.put("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me", nil).wait
327
+ @client.http.request(Route.new("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me", "//channels/:channel_id/messages/:message_id/reactions/:emoji/@me", :put), nil).wait
383
328
  end
384
329
  end
385
330
 
@@ -395,7 +340,7 @@ module Discorb
395
340
  #
396
341
  def remove_reaction(emoji)
397
342
  Async do
398
- @client.http.delete("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me").wait
343
+ @client.http.request(Route.new("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me", "//channels/:channel_id/messages/:message_id/reactions/:emoji/@me", :delete)).wait
399
344
  end
400
345
  end
401
346
 
@@ -412,7 +357,7 @@ module Discorb
412
357
  #
413
358
  def remove_reaction_of(emoji, member)
414
359
  Async do
415
- @client.http.delete("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/#{member.is_a?(Member) ? member.id : member}").wait
360
+ @client.http.request(Route.new("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/#{member.is_a?(Member) ? member.id : member}", "//channels/:channel_id/messages/:message_id/reactions/:emoji/:user_id", :delete)).wait
416
361
  end
417
362
  end
418
363
 
@@ -434,7 +379,7 @@ module Discorb
434
379
  after = 0
435
380
  users = []
436
381
  loop do
437
- _resp, data = @client.http.get("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=100&after=#{after}").wait
382
+ _resp, data = @client.http.request(Route.new("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=100&after=#{after}", "//channels/:channel_id/messages/:message_id/reactions/:emoji", :get)).wait
438
383
  break if data.empty?
439
384
 
440
385
  users += data.map { |r| guild&.members&.[](r[:id]) || @client.users[r[:id]] || User.new(@client, r) }
@@ -445,7 +390,7 @@ module Discorb
445
390
  end
446
391
  next users
447
392
  else
448
- _resp, data = @client.http.get("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=#{limit}&after=#{after}").wait
393
+ _resp, data = @client.http.request(Route.new("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=#{limit}&after=#{after}", "//channels/:channel_id/messages/:message_id/reactions/:emoji", :get)).wait
449
394
  next data.map { |r| guild&.members&.[](r[:id]) || @client.users[r[:id]] || User.new(@client, r) }
450
395
  end
451
396
  end
@@ -501,104 +446,7 @@ module Discorb
501
446
  "#<#{self.class} #{@content.inspect} id=#{@id}>"
502
447
  end
503
448
 
504
- #
505
- # Represents message flag.
506
- # ## Flag fields
507
- # |Field|Value|
508
- # |-|-|
509
- # |`1 << 0`|`:crossposted`|
510
- # |`1 << 1`|`:crosspost`|
511
- # |`1 << 2`|`:supress_embeds`|
512
- # |`1 << 3`|`:source_message_deleted`|
513
- # |`1 << 4`|`:urgent`|
514
- # |`1 << 5`|`:has_thread`|
515
- # |`1 << 6`|`:ephemeral`|
516
- # |`1 << 7`|`:loading`|
517
- #
518
- class Flag < Discorb::Flag
519
- @bits = {
520
- crossposted: 0,
521
- crosspost: 1,
522
- supress_embeds: 2,
523
- source_message_deleted: 3,
524
- urgent: 4,
525
- has_thread: 5,
526
- ephemeral: 6,
527
- loading: 7,
528
- }.freeze
529
- end
530
-
531
- #
532
- # Represents reference of message.
533
- #
534
- class Reference
535
- # @return [Discorb::Snowflake] The guild ID.
536
- attr_accessor :guild_id
537
- # @return [Discorb::Snowflake] The channel ID.
538
- attr_accessor :channel_id
539
- # @return [Discorb::Snowflake] The message ID.
540
- attr_accessor :message_id
541
- # @return [Boolean] Whether fail the request if the message is not found.
542
- attr_accessor :fail_if_not_exists
543
-
544
- alias fail_if_not_exists? fail_if_not_exists
545
-
546
- #
547
- # Initialize a new reference.
548
- #
549
- # @param [Discorb::Snowflake] guild_id The guild ID.
550
- # @param [Discorb::Snowflake] channel_id The channel ID.
551
- # @param [Discorb::Snowflake] message_id The message ID.
552
- # @param [Boolean] fail_if_not_exists Whether fail the request if the message is not found.
553
- #
554
- def initialize(guild_id, channel_id, message_id, fail_if_not_exists: true)
555
- @guild_id = guild_id
556
- @channel_id = channel_id
557
- @message_id = message_id
558
- @fail_if_not_exists = fail_if_not_exists
559
- end
560
-
561
- #
562
- # Convert the reference to a hash.
563
- #
564
- # @return [Hash] The hash.
565
- #
566
- def to_hash
567
- {
568
- message_id: @message_id,
569
- channel_id: @channel_id,
570
- guild_id: @guild_id,
571
- fail_if_not_exists: @fail_if_not_exists,
572
- }
573
- end
574
-
575
- alias to_reference to_hash
576
-
577
- #
578
- # Initialize a new reference from a hash.
579
- #
580
- # @param [Hash] data The hash.
581
- #
582
- # @return [Discorb::Message::Reference] The reference.
583
- # @see https://discord.com/developers/docs/resources/channel#message-reference-object
584
- #
585
- def self.from_hash(data)
586
- new(data[:guild_id], data[:channel_id], data[:message_id], fail_if_not_exists: data[:fail_if_not_exists])
587
- end
588
- end
589
-
590
- class Sticker
591
- attr_reader :id, :name, :format
592
-
593
- def initialize(data)
594
- @id = Snowflake.new(data[:id])
595
- @name = data[:name]
596
- @format = Discorb::Sticker.sticker_format[data[:format]]
597
- end
598
- end
599
-
600
- private
601
-
449
+ # @private
602
450
  def _set_data(data)
603
451
  @id = Snowflake.new(data[:id])
604
452
  @channel_id = data[:channel_id]
@@ -627,8 +475,8 @@ module Discorb
627
475
  @tts = data[:tts]
628
476
  @mention_everyone = data[:mention_everyone]
629
477
  @mention_roles = data[:mention_roles].map { |r| guild.roles[r] }
630
- @attachments = data[:attachments].map { |a| Attachment.new(a) }
631
- @embeds = data[:embeds] ? data[:embeds].map { |e| Embed.new(data: e) } : []
478
+ @attachments = data[:attachments].map { |a| Attachment.from_hash(a) }
479
+ @embeds = data[:embeds] ? data[:embeds].map { |e| Embed.from_hash(e) } : []
632
480
  @reactions = data[:reactions] ? data[:reactions].map { |r| Reaction.new(self, r) } : []
633
481
  @pinned = data[:pinned]
634
482
  @type = self.class.message_type[data[:type]]
@@ -645,57 +493,6 @@ module Discorb
645
493
  @deleted = false
646
494
  end
647
495
 
648
- #
649
- # Represents a interaction of message.
650
- #
651
- class Interaction < DiscordModel
652
- # @return [Discorb::Snowflake] The user ID.
653
- attr_reader :id
654
- # @return [String] The name of command.
655
- # @return [nil] If the message is not a command.
656
- attr_reader :name
657
- # @return [Class] The type of interaction.
658
- attr_reader :type
659
- # @return [Discorb::User] The user.
660
- attr_reader :user
661
-
662
- # @private
663
- def initialize(client, data)
664
- @id = Snowflake.new(data[:id])
665
- @name = data[:name]
666
- @type = Discorb::Interaction.descendants.find { |c| c.interaction_type == data[:type] }
667
- @user = client.users[data[:user][:id]] || User.new(client, data[:user])
668
- end
669
- end
670
-
671
- #
672
- # Represents a activity of message.
673
- #
674
- class Activity < DiscordModel
675
- # @return [String] The name of activity.
676
- attr_reader :name
677
- # @return [Symbol] The type of activity.
678
- attr_reader :type
679
-
680
- @type = {
681
- 1 => :join,
682
- 2 => :spectate,
683
- 3 => :listen,
684
- 5 => :join_request,
685
- }
686
-
687
- # @private
688
- def initialize(data)
689
- @name = data[:name]
690
- @type = self.class.type(data[:type])
691
- end
692
-
693
- class << self
694
- # @private
695
- attr_reader :type
696
- end
697
- end
698
-
699
496
  class << self
700
497
  # @private
701
498
  attr_reader :message_type