discorb 0.13.4 → 0.15.1

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 (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
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Discorb
4
+ #
5
+ # Represents a state of user in voice channel.
6
+ #
4
7
  class VoiceState < DiscordModel
5
8
  # @return [Discorb::Member] The member associated with this voice state.
6
9
  attr_reader :member
@@ -43,7 +46,13 @@ module Discorb
43
46
  # @macro client_cache
44
47
  # @return [Discorb::User] The user this voice state is for.
45
48
 
49
+ #
50
+ # Initialize a new voice state.
46
51
  # @private
52
+ #
53
+ # @param [Discorb::Client] client The client this voice state belongs to.
54
+ # @param [Hash] data The data of the voice state.
55
+ #
47
56
  def initialize(client, data)
48
57
  @client = client
49
58
  _set_data(data)
@@ -132,7 +141,14 @@ module Discorb
132
141
  2 => :guild_only,
133
142
  }
134
143
 
144
+ #
145
+ # Initialize a new instance of the StageInstance class.
135
146
  # @private
147
+ #
148
+ # @param [Discorb::Client] client The client.
149
+ # @param [Hash] data The data of the stage instance.
150
+ # @param [Boolean] no_cache Whether to disable caching.
151
+ #
136
152
  def initialize(client, data, no_cache: false)
137
153
  @client = client
138
154
  @data = data
@@ -179,7 +195,7 @@ module Discorb
179
195
  Async do
180
196
  payload = {}
181
197
  payload[:topic] = topic if topic != Discorb::Unset
182
- payload[:privacy_level] = self.class.privacy_level.key(privacy_level) if privacy_level != Discorb::Unset
198
+ payload[:privacy_level] = PRIVACY_LEVEL.key(privacy_level) if privacy_level != Discorb::Unset
183
199
  @client.http.request(
184
200
  Route.new("/stage-instances/#{@channel_id}", "//stage-instances/:channel_id", :patch), payload, audit_log_reason: reason,
185
201
  ).wait
@@ -213,7 +229,7 @@ module Discorb
213
229
  @guild_id = Snowflake.new(data[:guild_id])
214
230
  @channel_id = Snowflake.new(data[:channel_id])
215
231
  @topic = data[:topic]
216
- @privacy_level = self.class.privacy_level[data[:privacy_level]]
232
+ @privacy_level = PRIVACY_LEVEL[data[:privacy_level]]
217
233
  @discoverable_disabled = data[:discoverable_disabled]
218
234
  end
219
235
 
@@ -243,7 +259,12 @@ module Discorb
243
259
  attr_reader :custom
244
260
  alias custom? custom
245
261
 
262
+ #
263
+ # Initialize a new instance of the VoiceRegion class.
246
264
  # @private
265
+ #
266
+ # @param [Hash] data The data of the voice region.
267
+ #
247
268
  def initialize(data)
248
269
  @id = data[:id]
249
270
  @name = data[:name]
@@ -22,7 +22,13 @@ module Discorb
22
22
  # @return [String] The URL of the webhook.
23
23
  attr_reader :token
24
24
 
25
+ #
26
+ # Initializes a webhook.
25
27
  # @private
28
+ #
29
+ # @param [Discorb::Client] client The client.
30
+ # @param [Hash] data The data of the webhook.
31
+ #
26
32
  def initialize(client, data)
27
33
  @name = data[:name]
28
34
  @guild_id = data[:guild_id] && Snowflake.new(data[:guild_id])
@@ -151,7 +157,7 @@ module Discorb
151
157
  payload[:attachments] = attachments.map(&:to_hash) if attachments != Discorb::Unset
152
158
  payload[:allowed_mentions] = allowed_mentions if allowed_mentions != Discorb::Unset
153
159
  files = [file] if file != Discorb::Unset
154
- _resp, data = @http.multipart_request(Route.new("#{url}/messages/#{Utils.try(message, :id)}", "//webhooks/:webhook_id/:token/messages/:message_id", :patch), payload, headers: headers).wait
160
+ _resp, data = @http.multipart_request(Route.new("#{url}/messages/#{Utils.try(message, :id)}", "//webhooks/:webhook_id/:token/messages/:message_id", :patch), payload, files).wait
155
161
  message.send(:_set_data, data)
156
162
  message
157
163
  end
@@ -200,7 +206,13 @@ module Discorb
200
206
  # @!attribute [r] url
201
207
  # @return [String] The URL of the webhook.
202
208
 
209
+ #
210
+ # Initializes the incoming webhook.
203
211
  # @private
212
+ #
213
+ # @param [Discorb::Client] client The client.
214
+ # @param [String] url The URL of the webhook.
215
+ #
204
216
  def initialize(client, data)
205
217
  super
206
218
  @token = data[:token]
@@ -222,7 +234,13 @@ module Discorb
222
234
  # Represents a source channel of follower webhook.
223
235
  # @return [Discorb::Channel, Discorb::Webhook::FollowerWebhook::Channel] The source channel of follower webhook.
224
236
 
237
+ #
238
+ # Initializes the follower webhook.
225
239
  # @private
240
+ #
241
+ # @param [Discorb::Client] client The client.
242
+ # @param [Hash] data The data of the follower webhook.
243
+ #
226
244
  def initialize(client, data)
227
245
  super
228
246
  @source_guild = FollowerWebhook::Guild.new(data[:source_guild])
@@ -248,12 +266,21 @@ module Discorb
248
266
  # @return [Discorb::Asset] The icon of the guild.
249
267
  attr_reader :icon
250
268
 
269
+ #
270
+ # Initialize a new guild.
251
271
  # @private
272
+ #
273
+ # @param [Hash] data The data of the guild.
274
+ #
252
275
  def initialize(data)
253
276
  @id = Snowflake.new(data[:id])
254
277
  @name = data[:name]
255
278
  @icon = Asset.new(self, data[:icon])
256
279
  end
280
+
281
+ def inspect
282
+ "#<#{self.class.name} #{@id}: #{@name}>"
283
+ end
257
284
  end
258
285
 
259
286
  #
@@ -265,11 +292,20 @@ module Discorb
265
292
  # @return [String] The name of the channel.
266
293
  attr_reader :name
267
294
 
295
+ #
296
+ # Initialize a new channel.
268
297
  # @private
298
+ #
299
+ # @param [Hash] data The data of the channel.
300
+ #
269
301
  def initialize(data)
270
302
  @id = Snowflake.new(data[:id])
271
303
  @name = data[:name]
272
304
  end
305
+
306
+ def inspect
307
+ "#<#{self.class.name} #{@id}: #{@name}>"
308
+ end
273
309
  end
274
310
  end
275
311
 
@@ -290,7 +326,13 @@ module Discorb
290
326
  # @return [Discorb::Snowflake] The ID of the guild.
291
327
  attr_reader :guild_id
292
328
 
329
+ #
330
+ # Initializes the message.
293
331
  # @private
332
+ #
333
+ # @param [Discorb::Webhook] webhook The webhook.
334
+ # @param [Hash] data The data of the message.
335
+ # @param [Discorb::Client] client The client. This will be nil if it's created from {URLWebhook}.
294
336
  def initialize(webhook, data, client = nil)
295
337
  @client = client
296
338
  @webhook = webhook
@@ -329,12 +371,12 @@ module Discorb
329
371
 
330
372
  def _set_data(data)
331
373
  @id = Snowflake.new(data[:id])
332
- @type = Discorb::Message.message_type[data[:type]]
374
+ @type = Discorb::Message::MESSAGE_TYPE[data[:type]]
333
375
  @content = data[:content]
334
376
  @channel_id = Snowflake.new(data[:channel_id])
335
377
  @author = Author.new(data[:author])
336
378
  @attachments = data[:attachments].map { |a| Attachment.new(a) }
337
- @embeds = data[:embeds] ? data[:embeds].map { |e| Embed.new(data: e) } : []
379
+ @embeds = data[:embeds] ? data[:embeds].map { |e| Embed.from_hash(e) } : []
338
380
  @mentions = data[:mentions].map { |m| Mention.new(m) }
339
381
  @mention_roles = data[:mention_roles].map { |m| Snowflake.new(m) }
340
382
  @mention_everyone = data[:mention_everyone]
@@ -364,7 +406,12 @@ module Discorb
364
406
  # @return [String] The discriminator of the author.
365
407
  attr_reader :discriminator
366
408
 
409
+ #
410
+ # Initializes the author.
367
411
  # @private
412
+ #
413
+ # @param [Hash] data The data of the author.
414
+ #
368
415
  def initialize(data)
369
416
  @data = data
370
417
  @bot = data[:bot]
@@ -384,6 +431,10 @@ module Discorb
384
431
  end
385
432
 
386
433
  alias to_s_user to_s
434
+
435
+ def inspect
436
+ "#<#{self.class.name} #{self}>"
437
+ end
387
438
  end
388
439
  end
389
440
 
data/lib/discorb.rb CHANGED
@@ -4,7 +4,10 @@
4
4
  #
5
5
  # @author sevenc-nanashi
6
6
  module Discorb
7
+ #
8
+ # Method to define a macro for YARD.
7
9
  # @private
10
+ #
8
11
  # @!macro [new] async
9
12
  # @note This is an asynchronous method, it will return a `Async::Task` object. Use `Async::Task#wait` to get the result.
10
13
  #
@@ -23,7 +26,6 @@ module Discorb
23
26
  # @raise [Discorb::HTTPError] HTTP request failed.
24
27
  #
25
28
  def macro
26
- # NOTE: this method is only for YARD.
27
29
  puts "Wow, You found the easter egg!\n"
28
30
  red = "\e[31m"
29
31
  reset = "\e[m"
@@ -40,9 +42,10 @@ module Discorb
40
42
  end
41
43
 
42
44
  require_order = %w[common flag dictionary error rate_limit http intents emoji_table modules] +
45
+ %w[message_meta allowed_mentions] +
43
46
  %w[user member guild emoji channel embed message] +
44
47
  %w[application audit_logs color components event event_handler] +
45
- %w[file guild_template image integration interaction invite log permission] +
48
+ %w[attachment guild_template image integration interaction invite log permission] +
46
49
  %w[presence reaction role sticker utils voice_state webhook] +
47
50
  %w[gateway_requests gateway app_command] +
48
51
  %w[asset extension client extend]