discorb 0.17.1 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lint.yml +1 -3
  3. data/.github/workflows/validate.yml +21 -0
  4. data/Changelog.md +25 -0
  5. data/Gemfile +6 -0
  6. data/README.md +2 -1
  7. data/Rakefile +205 -98
  8. data/Steepfile +30 -0
  9. data/docs/application_command.md +1 -0
  10. data/docs/events.md +44 -8
  11. data/docs/tutorial.md +7 -7
  12. data/docs/voice_events.md +8 -8
  13. data/examples/commands/message.rb +12 -7
  14. data/examples/commands/permission.rb +2 -1
  15. data/examples/commands/slash.rb +23 -19
  16. data/examples/commands/user.rb +15 -12
  17. data/examples/components/authorization_button.rb +2 -1
  18. data/examples/components/select_menu.rb +4 -1
  19. data/examples/extension/main.rb +1 -0
  20. data/examples/extension/message_expander.rb +1 -0
  21. data/examples/sig/commands/message.rbs +5 -0
  22. data/examples/simple/eval.rb +1 -0
  23. data/examples/simple/ping_pong.rb +1 -0
  24. data/examples/simple/rolepanel.rb +16 -5
  25. data/examples/simple/shard.rb +2 -1
  26. data/examples/simple/wait_for_message.rb +3 -0
  27. data/exe/discorb +3 -3
  28. data/lib/discorb/allowed_mentions.rb +1 -1
  29. data/lib/discorb/app_command/command.rb +16 -13
  30. data/lib/discorb/app_command/handler.rb +21 -6
  31. data/lib/discorb/audit_logs.rb +6 -2
  32. data/lib/discorb/automod.rb +269 -0
  33. data/lib/discorb/channel/guild.rb +5 -4
  34. data/lib/discorb/channel/stage.rb +1 -1
  35. data/lib/discorb/channel/text.rb +14 -23
  36. data/lib/discorb/channel/thread.rb +15 -11
  37. data/lib/discorb/client.rb +15 -15
  38. data/lib/discorb/color.rb +37 -60
  39. data/lib/discorb/common.rb +1 -1
  40. data/lib/discorb/dictionary.rb +1 -1
  41. data/lib/discorb/embed.rb +5 -4
  42. data/lib/discorb/emoji.rb +4 -4
  43. data/lib/discorb/event.rb +2 -2
  44. data/lib/discorb/exe/about.rb +1 -1
  45. data/lib/discorb/exe/new.rb +1 -5
  46. data/lib/discorb/extension.rb +0 -4
  47. data/lib/discorb/flag.rb +2 -2
  48. data/lib/discorb/gateway.rb +38 -589
  49. data/lib/discorb/gateway_events.rb +638 -0
  50. data/lib/discorb/guild.rb +138 -19
  51. data/lib/discorb/guild_template.rb +3 -3
  52. data/lib/discorb/http.rb +47 -25
  53. data/lib/discorb/integration.rb +2 -2
  54. data/lib/discorb/intents.rb +27 -18
  55. data/lib/discorb/interaction/command.rb +14 -10
  56. data/lib/discorb/interaction/response.rb +150 -84
  57. data/lib/discorb/interaction/root.rb +139 -0
  58. data/lib/discorb/invite.rb +1 -1
  59. data/lib/discorb/member.rb +3 -3
  60. data/lib/discorb/message.rb +17 -15
  61. data/lib/discorb/message_meta.rb +2 -3
  62. data/lib/discorb/modules.rb +5 -4
  63. data/lib/discorb/permission.rb +3 -1
  64. data/lib/discorb/presence.rb +4 -2
  65. data/lib/discorb/reaction.rb +2 -2
  66. data/lib/discorb/role.rb +3 -3
  67. data/lib/discorb/shard.rb +1 -1
  68. data/lib/discorb/sticker.rb +5 -5
  69. data/lib/discorb/user.rb +2 -2
  70. data/lib/discorb/voice_state.rb +8 -8
  71. data/lib/discorb/webhook.rb +20 -11
  72. data/lib/discorb.rb +2 -2
  73. data/rbs_collection.lock.yaml +88 -96
  74. data/rbs_collection.yaml +21 -17
  75. data/sig/async.rbs +11 -5
  76. data/sig/discorb/activity.rbs +24 -0
  77. data/sig/discorb/allowed_mentions.rbs +45 -0
  78. data/sig/discorb/app_command/base.rbs +288 -0
  79. data/sig/discorb/app_command/handler.rbs +171 -0
  80. data/sig/discorb/application.rbs +146 -0
  81. data/sig/discorb/asset.rbs +34 -0
  82. data/sig/discorb/attachment.rbs +99 -0
  83. data/sig/discorb/audit_log.rbs +238 -0
  84. data/sig/discorb/automod.rbs +145 -0
  85. data/sig/discorb/avatar.rbs +27 -0
  86. data/sig/discorb/channel/base.rbs +186 -0
  87. data/sig/discorb/channel/category.rbs +57 -0
  88. data/sig/discorb/channel/container.rbs +33 -0
  89. data/sig/discorb/channel/dm.rbs +14 -0
  90. data/sig/discorb/channel/news.rbs +20 -0
  91. data/sig/discorb/channel/stage.rbs +81 -0
  92. data/sig/discorb/channel/text.rbs +158 -0
  93. data/sig/discorb/channel/thread.rbs +196 -0
  94. data/sig/discorb/channel/voice.rbs +43 -0
  95. data/sig/discorb/client.rbs +2496 -0
  96. data/sig/discorb/color.rbs +148 -0
  97. data/sig/discorb/component/base.rbs +29 -0
  98. data/sig/discorb/component/button.rbs +67 -0
  99. data/sig/discorb/component/select_menu.rbs +111 -0
  100. data/sig/discorb/component/text_input.rbs +70 -0
  101. data/sig/discorb/connectable.rbs +8 -0
  102. data/sig/discorb/custom_emoji.rbs +94 -0
  103. data/sig/discorb/dictionary.rbs +87 -0
  104. data/sig/discorb/discord_model.rbs +17 -0
  105. data/sig/discorb/embed.rbs +286 -0
  106. data/sig/discorb/emoji.rbs +14 -0
  107. data/sig/discorb/error.rbs +73 -0
  108. data/sig/discorb/event_handler.rbs +28 -0
  109. data/sig/discorb/extension.rbs +1735 -0
  110. data/sig/discorb/flag.rbs +74 -0
  111. data/sig/discorb/gateway.rbs +486 -0
  112. data/sig/discorb/guild.rbs +872 -0
  113. data/sig/discorb/guild_template.rbs +174 -0
  114. data/sig/discorb/http.rbs +150 -0
  115. data/sig/discorb/image.rbs +22 -0
  116. data/sig/discorb/integration.rbs +118 -0
  117. data/sig/discorb/intents.rbs +98 -0
  118. data/sig/discorb/interaction/autocomplete.rbs +9 -0
  119. data/sig/discorb/interaction/base.rbs +102 -0
  120. data/sig/discorb/interaction/command.rbs +66 -0
  121. data/sig/discorb/interaction/message_component.rbs +139 -0
  122. data/sig/discorb/interaction/modal.rbs +49 -0
  123. data/sig/discorb/interaction/responder.rbs +157 -0
  124. data/sig/discorb/invite.rbs +86 -0
  125. data/sig/discorb/member.rbs +189 -0
  126. data/sig/discorb/message.rbs +474 -0
  127. data/sig/discorb/messageable.rbs +150 -0
  128. data/sig/discorb/partial_emoji.rbs +38 -0
  129. data/sig/discorb/permissions.rbs +156 -0
  130. data/sig/discorb/presence.rbs +239 -0
  131. data/sig/discorb/reaction.rbs +37 -0
  132. data/sig/discorb/role.rbs +151 -0
  133. data/sig/discorb/scheduled_event.rbs +149 -0
  134. data/sig/discorb/shard.rbs +63 -0
  135. data/sig/discorb/snowflake.rbs +58 -0
  136. data/sig/discorb/stage_instance.rbs +69 -0
  137. data/sig/discorb/sticker.rbs +116 -0
  138. data/sig/discorb/system_channel_flag.rbs +17 -0
  139. data/sig/discorb/unicode_emoji.rbs +53 -0
  140. data/sig/discorb/user.rbs +95 -0
  141. data/sig/discorb/utils.rbs +8 -0
  142. data/sig/discorb/voice_region.rbs +30 -0
  143. data/sig/discorb/voice_state.rbs +71 -0
  144. data/sig/discorb/webhook.rbs +338 -0
  145. data/sig/discorb/welcome_screen.rbs +79 -0
  146. data/sig/discorb.rbs +5 -8661
  147. data/sig/manifest.yaml +3 -0
  148. data/sig/override.rbs +21 -0
  149. metadata +80 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4cee4be461c639c494c2981f65ba496a17e4336fcb440218c2a4852d375b277
4
- data.tar.gz: 4e743b61201c82a387f580cc75e0fa448dd357c5b02af5339df9b950898c0c38
3
+ metadata.gz: 99a6cb7f4f4f1d7c657209570f1327f6a847b7d7db3fb031c645ca4b0a4464af
4
+ data.tar.gz: f207685f5153f73dba3c66f40aaf4ef100063f31746874d57c31b119f5fcb009
5
5
  SHA512:
6
- metadata.gz: b440b0e1f9e19161b666df325e01120905c3cf7f38e45cb4c89db4c9c7273b9626a5bed8825706317a84605417ac8b0f688450378622ee188cd3307d1905e7c0
7
- data.tar.gz: b6bfc1d6c2e64918d0b0a73529029c01b50b33ac399a83bf18e30ef5bc6e7eb1c458f1aec7ce607349c36c2ba1585ded988c33d0607ece6048f0da9571af334d
6
+ metadata.gz: bd641beb11497865a97e267ef1558d1f5162323713f623fcd5109e9e25a7bb41d25e1a59111b0c3b5dcbe43f77a54531973f5874b5d82927956a1ad5f1e4ea03
7
+ data.tar.gz: 8d25ed7b8604b59c4a4f3f8467a268472749ccbc010d216787091ea3da60e24e0ddde95add2dc30f6d40637650d19cd9ef22e54dc2141637ac2e96cd4d55ece1
@@ -11,6 +11,4 @@ jobs:
11
11
  with:
12
12
  ruby-version: 3.0.0
13
13
  - name: rubocop
14
- uses: reviewdog/action-rubocop@v2
15
- with:
16
- rubocop_version: 1.25
14
+ uses: reviewdog/action-rubocop@v2
@@ -0,0 +1,21 @@
1
+ name: Validate rbs
2
+ on:
3
+ - push
4
+ jobs:
5
+ validate:
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - name: Checkout repository
9
+ uses: actions/checkout@v3
10
+ - uses: ruby/setup-ruby@v1
11
+ with:
12
+ ruby-version: 3.0.0
13
+ - name: Install collection
14
+ run: |
15
+ gem update rbs
16
+ bundle install
17
+ rbs collection install
18
+ - name: Validate
19
+ run: |
20
+ rbs -I sig validate
21
+
data/Changelog.md CHANGED
@@ -4,6 +4,31 @@
4
4
 
5
5
  # Changelog
6
6
 
7
+ ## v0.19
8
+
9
+ ### v0.19.0
10
+
11
+ - Change!: All bang methods don't have bang anymore. (ex: `Message#delete!`)
12
+ - Add: Add `%a{pure}` annotation to rbs.
13
+ - Add: Add low level APIs to Interaction.
14
+ - Update: Update IDENTIFY key.
15
+
16
+ ## v0.18
17
+
18
+ ### v0.18.1
19
+
20
+ - Add: Support `:length` option for `:string` type.
21
+ - Add: Add `Interaction#app_permissions`
22
+ - Fix: Fix typing of `:autocomplete` option.
23
+
24
+ ### v0.18.0
25
+
26
+ - Change!: `XXX#fired_by` is now `XXX#user` or `XXX#member`.
27
+ - Change!: `Message#to_reference` returns `Message::Reference`.
28
+ - Change!: `TextChannel#default_auto_archive_duration` is now Integer.
29
+ - Add: Support AutoMod.
30
+ - Change: `discorb new` doesn't do initial commit.
31
+
7
32
  ## v0.17
8
33
 
9
34
  ### v0.17.1
data/Gemfile CHANGED
@@ -17,6 +17,9 @@ gem "async-rspec", "~> 1.16"
17
17
  gem "parallel_tests", "~> 3.8"
18
18
  gem "rspec", "~> 3.11"
19
19
 
20
+ # Typecheck
21
+ gem "steep", "~> 1.1"
22
+
20
23
  # Other development tools
21
24
  gem "lefthook", "~> 0.7.7"
22
25
  gem "rufo", "~> 0.13.0"
@@ -29,3 +32,6 @@ group :docs, optional: true do
29
32
  gem "rubyzip", "~> 2.3"
30
33
  gem "yard", "~> 0.9.26"
31
34
  end
35
+
36
+ gem "syntax_tree", "~> 2.8"
37
+ gem "syntax_tree-rbs", "~> 0.5.0"
data/README.md CHANGED
@@ -99,7 +99,8 @@ end
99
99
  client.run(ENV["DISCORD_BOT_TOKEN"])
100
100
  ```
101
101
 
102
- Note you must run `discorb setup` before using slash commands.
102
+ > **Note**
103
+ > You must run `discorb setup` before using slash commands.
103
104
 
104
105
  ## Contributing
105
106
 
data/Rakefile CHANGED
@@ -232,106 +232,213 @@ namespace :document do
232
232
  end
233
233
  end
234
234
 
235
- desc "Generate rbs file using sord"
236
- task :rbs do
237
- require "open3"
238
- # rubocop: disable Layout/LineLength
239
- type_errors = {
240
- "SORD_ERROR_SymbolSymbolSymbolInteger" => "{ r: Integer, g: Integer, b: Integer}",
241
- "SORD_ERROR_DiscorbRoleDiscorbMemberDiscorbPermissionOverwrite" => "Hash[Discorb::Role | Discorb::Member, Discorb::PermissionOverwrite]",
242
- "SORD_ERROR_DiscorbRoleDiscorbMemberPermissionOverwrite" => "Hash[Discorb::Role | Discorb::Member, Discorb::PermissionOverwrite]",
243
- "SORD_ERROR_f | SORD_ERROR_F | SORD_ERROR_d | SORD_ERROR_D | SORD_ERROR_t | SORD_ERROR_T | SORD_ERROR_R" => '"f" | "F" | "d" | "D" | "t" | "T" | "R"',
244
- "SORD_ERROR_dark | SORD_ERROR_light" => '"dark" | "light"',
245
- "SORD_ERROR_SymbolStringSymbolboolSymbolObject" => "String | Integer | Float",
246
- }
247
- # rubocop: enable Layout/LineLength
248
- regenerate = ARGV.include?("--regenerate") || ARGV.include?("-r")
249
-
250
- sh "sord gen sig/discorb.rbs --keep-original-comments --no-sord-comments" +
251
- (regenerate ? " --regenerate" : " --no-regenerate")
252
- base = File.read("sig/discorb.rbs")
253
- base.gsub!(/\n +def _set_data: \(.+\) -> untyped\n\n/, "\n")
254
- # base.gsub!(/( )?( *)# @private.+?(?:\n\n(?=\1\2#)|(?=\n\2end))/sm, "")
255
- base.gsub!(/untyped ([a-z_]*id)/, "_ToS \\1")
256
- # #region rbs dictionary
257
- base.gsub!(/ class Dictionary.+?end\n/ms, <<-RBS)
258
- class Dictionary[K, V]
259
- #
260
- # Initialize a new Dictionary.
261
- #
262
- # @param [Hash] hash A hash of items to add to the dictionary.
263
- # @param [Integer] limit The maximum number of items in the dictionary.
264
- # @param [false, Proc] sort Whether to sort the items in the dictionary.
265
- def initialize: (?::Hash[untyped, untyped] hash, ?limit: Integer?, ?sort: (bool | Proc)) -> void
266
-
267
- #
268
- # Registers a new item in the dictionary.
269
- #
270
- # @param [#to_s] id The ID of the item.
271
- # @param [Object] body The item to register.
272
- #
273
- # @return [self] The dictionary.
274
- def register: (_ToS id, Object body) -> self
275
-
276
- #
277
- # Merges another dictionary into this one.
278
- #
279
- # @param [Discorb::Dictionary] other The dictionary to merge.
280
- def merge: (Discorb::Dictionary other) -> untyped
281
-
282
- #
283
- # Removes an item from the dictionary.
284
- #
285
- # @param [#to_s] id The ID of the item to remove.
286
- def remove: (_ToS id) -> untyped
287
-
288
- #
289
- # Get an item from the dictionary.
290
- #
291
- # @param [#to_s] id The ID of the item.
292
- # @return [Object] The item.
293
- # @return [nil] if the item was not found.
294
- #
295
- # @overload get(index)
296
- # @param [Integer] index The index of the item.
297
- #
298
- # @return [Object] The item.
299
- # @return [nil] if the item is not found.
300
- def get: (K id) -> V?
301
-
302
- #
303
- # Returns the values of the dictionary.
304
- #
305
- # @return [Array] The values of the dictionary.
306
- def values: () -> ::Array[V]
307
-
308
- #
309
- # Checks if the dictionary has an ID.
310
- #
311
- # @param [#to_s] id The ID to check.
312
- #
313
- # @return [Boolean] `true` if the dictionary has the ID, `false` otherwise.
314
- def has?: (_ToS id) -> bool
315
-
316
- #
317
- # Send a message to the array of values.
318
- def method_missing: (untyped name) -> untyped
319
-
320
- def respond_to_missing?: (untyped name, untyped args, untyped kwargs) -> bool
321
-
322
- def inspect: () -> untyped
323
-
324
- # @return [Integer] The maximum number of items in the dictionary.
325
- attr_accessor limit: Integer
235
+ desc "Generate rbs file"
236
+ namespace :rbs do
237
+ desc "Generate event signature"
238
+ task :event do
239
+ require "syntax_tree/rbs"
240
+ client_rbs = File.read("sig/discorb/client.rbs")
241
+ extension_rbs = File.read("sig/discorb/extension.rbs")
242
+ event_document = File.read("./docs/events.md")
243
+ voice_event_document = File.read("./docs/voice_events.md")
244
+ event_reference = event_document.split("## Event reference")[1]
245
+ event_reference += voice_event_document.split("# Voice Events")[1]
246
+ event_reference.gsub!(/^### (.*)$/, "")
247
+ events = []
248
+ event_reference.split("#### `")[1..].each do |event|
249
+ header, content = event.split("`\n", 2)
250
+ name = header.split("(")[0]
251
+ description = content.split("| Parameter", 2)[0].strip
252
+ parameters = if content.include?("| Parameter")
253
+ content.scan(/\| `(.*?)` +\| (.*?) +\| (.*?) +\|/)
254
+ else
255
+ []
256
+ end
257
+ events << {
258
+ name: name,
259
+ description: description,
260
+ parameters: parameters.map { |p| { name: p[0], type: p[1], description: p[2] } },
261
+ }
262
+ end
263
+ event_sig = +""
264
+ event_lock_sig = +""
265
+ extension_sig = +""
266
+ events.each do |event|
267
+ args = []
268
+ event[:parameters].each do |parameter|
269
+ args << {
270
+ name: parameter[:name],
271
+ type: if parameter[:type].start_with?("?")
272
+ parameter[:type][1..]
273
+ else
274
+ parameter[:type]
275
+ end.tr("{}`", "").tr("<>", "[]").gsub(", ", " | ").then do |t|
276
+ if event[:name] == "event_receive"
277
+ case t
278
+ when "Hash"
279
+ next "Discorb::json"
280
+ end
281
+ end
282
+ t
283
+ end,
284
+ }
285
+ end
286
+ sig = args.map { |a| "#{a[:type]} #{a[:name]}" }.join(", ")
287
+ tuple_sig = args.map { |a| a[:type] }.join(", ")
288
+ tuple_sig = "[" + tuple_sig + "]" if args.length > 1
289
+ tuple_sig = "void" if args.length.zero?
290
+ event_sig << <<~RBS
291
+ | (:#{event[:name]} event_name, ?id: Symbol?, **untyped metadata) { (#{sig}) -> void } -> Discorb::EventHandler
292
+ RBS
293
+ event_lock_sig << <<~RBS
294
+ | (:#{event[:name]} event, ?Integer? timeout) { (#{sig}) -> boolish } -> Async::Task[#{tuple_sig}]
295
+ RBS
296
+ extension_sig << <<~RBS
297
+ | (:#{event[:name]} event_name, ?id: Symbol?, **untyped metadata) { (#{sig}) -> void } -> void
298
+ RBS
299
+ end
300
+ event_sig << <<~RBS
301
+ | (Symbol event_name, ?id: Symbol?, **untyped metadata) { (*untyped) -> void } -> Discorb::EventHandler
302
+ RBS
303
+ event_lock_sig << <<~RBS
304
+ | (Symbol event, ?Integer? timeout) { (*untyped) -> boolish } -> Async::Task[untyped]
305
+ RBS
306
+ extension_sig << <<~RBS
307
+ | (Symbol event_name, ?id: Symbol?, **untyped metadata) { (*untyped) -> void } -> void
308
+ RBS
309
+ event_sig.sub!("| ", " ").rstrip!
310
+ event_lock_sig.sub!("| ", " ").rstrip!
311
+ extension_sig.sub!("| ", " ").rstrip!
312
+ res = client_rbs.gsub!(/(?<=def on:\n)(?:[\s\S]*?)(?=\n\n)/, event_sig)
313
+ raise "Failed to generate Client#on" unless res
314
+
315
+ res = client_rbs.gsub!(/(?<=def once:\n)(?:[\s\S]*?)(?=\n\n)/, event_sig)
316
+ raise "Failed to generate Client#once" unless res
317
+
318
+ res = client_rbs.gsub!(/(?<=def event_lock:\n)(?:[\s\S]*?)(?=\n\n)/, event_lock_sig)
319
+ raise "Failed to generate Client#event_lock" unless res
320
+
321
+ res = extension_rbs.gsub!(/(?<=def event:\n)(?:[\s\S]*?)(?=\n\n)/, extension_sig)
322
+ raise "Failed to generate Extension.event" unless res
323
+
324
+ res = extension_rbs.gsub!(/(?<=def once_event:\n)(?:[\s\S]*?)(?=\n\n)/, extension_sig)
325
+ raise "Failed to generate Extension.once_event" unless res
326
+
327
+ File.write("sig/discorb/client.rbs", SyntaxTree::RBS.format(client_rbs), mode: "wb")
328
+ File.write("sig/discorb/extension.rbs", SyntaxTree::RBS.format(extension_rbs), mode: "wb")
326
329
  end
327
- RBS
328
- # #endregion
329
- type_errors.each do |error, type|
330
- base.gsub!(error, type)
330
+
331
+ desc "Generate rbs file using sord"
332
+ task :sord do
333
+ require "open3"
334
+ # rubocop: disable Layout/LineLength
335
+ type_errors = {
336
+ "SORD_ERROR_SymbolSymbolSymbolInteger" => "{ r: Integer, g: Integer, b: Integer}",
337
+ "SORD_ERROR_DiscorbRoleDiscorbMemberDiscorbPermissionOverwrite" => "Hash[Discorb::Role | Discorb::Member, Discorb::PermissionOverwrite]",
338
+ "SORD_ERROR_DiscorbRoleDiscorbMemberPermissionOverwrite" => "Hash[Discorb::Role | Discorb::Member, Discorb::PermissionOverwrite]",
339
+ "SORD_ERROR_f | SORD_ERROR_F | SORD_ERROR_d | SORD_ERROR_D | SORD_ERROR_t | SORD_ERROR_T | SORD_ERROR_R" => '"f" | "F" | "d" | "D" | "t" | "T" | "R"',
340
+ "SORD_ERROR_dark | SORD_ERROR_light" => '"dark" | "light"',
341
+ "SORD_ERROR_SymbolStringSymbolboolSymbolObject" => "String | Integer | Float",
342
+ }
343
+ # rubocop: enable Layout/LineLength
344
+ regenerate = ARGV.include?("--regenerate") || ARGV.include?("-r")
345
+
346
+ sh "sord gen sig/discorb.rbs --keep-original-comments --no-sord-comments" +
347
+ (regenerate ? " --regenerate" : " --no-regenerate")
348
+ base = File.read("sig/discorb.rbs")
349
+ base.gsub!(/\n +def _set_data: \(.+\) -> untyped\n\n/, "\n")
350
+ # base.gsub!(/( )?( *)# @private.+?(?:\n\n(?=\1\2#)|(?=\n\2end))/sm, "")
351
+ base.gsub!(/untyped ([a-z_]*id)/, "_ToS \\1")
352
+ # #region rbs dictionary
353
+ base.gsub!(/ class Dictionary.+?end\n/ms, <<-RBS)
354
+ class Dictionary[K, V]
355
+ #
356
+ # Initialize a new Dictionary.
357
+ #
358
+ # @param [Hash] hash A hash of items to add to the dictionary.
359
+ # @param [Integer] limit The maximum number of items in the dictionary.
360
+ # @param [false, Proc] sort Whether to sort the items in the dictionary.
361
+ def initialize: (?::Hash[untyped, untyped] hash, ?limit: Integer?, ?sort: (bool | Proc)) -> void
362
+
363
+ #
364
+ # Registers a new item in the dictionary.
365
+ #
366
+ # @param [#to_s] id The ID of the item.
367
+ # @param [Object] body The item to register.
368
+ #
369
+ # @return [self] The dictionary.
370
+ def register: (_ToS id, Object body) -> self
371
+
372
+ #
373
+ # Merges another dictionary into this one.
374
+ #
375
+ # @param [Discorb::Dictionary] other The dictionary to merge.
376
+ def merge: (Discorb::Dictionary other) -> untyped
377
+
378
+ #
379
+ # Removes an item from the dictionary.
380
+ #
381
+ # @param [#to_s] id The ID of the item to remove.
382
+ def remove: (_ToS id) -> untyped
383
+
384
+ #
385
+ # Get an item from the dictionary.
386
+ #
387
+ # @param [#to_s] id The ID of the item.
388
+ # @return [Object] The item.
389
+ # @return [nil] if the item was not found.
390
+ #
391
+ # @overload get(index)
392
+ # @param [Integer] index The index of the item.
393
+ #
394
+ # @return [Object] The item.
395
+ # @return [nil] if the item is not found.
396
+ def get: (K id) -> V?
397
+
398
+ #
399
+ # Returns the values of the dictionary.
400
+ #
401
+ # @return [Array] The values of the dictionary.
402
+ def values: () -> ::Array[V]
403
+
404
+ #
405
+ # Checks if the dictionary has an ID.
406
+ #
407
+ # @param [#to_s] id The ID to check.
408
+ #
409
+ # @return [Boolean] `true` if the dictionary has the ID, `false` otherwise.
410
+ def has?: (_ToS id) -> bool
411
+
412
+ #
413
+ # Send a message to the array of values.
414
+ def method_missing: (untyped name) -> untyped
415
+
416
+ def respond_to_missing?: (untyped name, untyped args, untyped kwargs) -> bool
417
+
418
+ def inspect: () -> String
419
+
420
+ # @return [Integer] The maximum number of items in the dictionary.
421
+ attr_accessor limit: Integer
422
+ end
423
+ RBS
424
+ # #endregion
425
+ type_errors.each do |error, type|
426
+ base.gsub!(error, type)
427
+ end
428
+ base.gsub!("end\n\n\nend", "end\n")
429
+ base.gsub!(/ +$/m, "")
430
+ File.write("sig/discorb.rbs", base)
431
+ end
432
+
433
+ desc "Lint rbs with stree"
434
+ task :lint do
435
+ sh "stree check --plugins=rbs sig/**/*.rbs"
436
+ end
437
+
438
+ desc "Autofix rbs with stree"
439
+ task "lint:fix" do
440
+ sh "stree write --plugins=rbs sig/**/*.rbs"
331
441
  end
332
- base.gsub!("end\n\n\nend", "end\n")
333
- base.gsub!(/ +$/m, "")
334
- File.write("sig/discorb.rbs", base)
335
442
  end
336
443
 
337
444
  task document: %i[document:yard document:replace]
data/Steepfile ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ D = Steep::Diagnostic
4
+
5
+ target :lib do
6
+ signature "sig"
7
+
8
+ check "lib"
9
+
10
+ library "net-http", "timeout"
11
+
12
+ configure_code_diagnostics(D::Ruby.lenient)
13
+ configure_code_diagnostics do |config|
14
+ config[D::Ruby::UnsupportedSyntax] = nil
15
+ config[D::Ruby::UnexpectedSuper] = nil
16
+ config[D::Ruby::UnexpectedPositionalArgument] = nil
17
+ config[D::Ruby::InsufficientPositionalArguments] = nil
18
+ config[D::Ruby::UnknownInstanceVariable] = nil
19
+ config[D::Ruby::UnknownGlobalVariable] = nil
20
+ end
21
+ end
22
+
23
+ # target :test do
24
+ # signature "sig"
25
+ # signature "examples/sig"
26
+
27
+ # check "examples/**/*.rb"
28
+
29
+ # library "net-http", "timeout"
30
+ # end
@@ -82,6 +82,7 @@ In `options`, hash should be like this:
82
82
  | `:channel_types` | `Array<Class<Discorb::Channel>>` | Type of the channel option. |
83
83
  | `:autocomplete` | `Proc` | Autocomplete function. |
84
84
  | `:range` | `Range` | Range of the option. Only valid for numeric options. (`:int`, `:float`) |
85
+ | `:length` | `Range` | Range of length of the option. Only valid for `:string`. |
85
86
 
86
87
  `choices` should be unspecified if you don't want to use it.
87
88
  `choices` example:
data/docs/events.md CHANGED
@@ -69,10 +69,10 @@ end
69
69
 
70
70
  Fires when an event is received.
71
71
 
72
- | Parameter | Type | Description |
73
- | ------------ | ------ | ---------------------- |
74
- | `event_name` | Symbol | The name of the event. |
75
- | `data` | Hash | The data of the event. |
72
+ | Parameter | Type | Description |
73
+ | ------------ | -------- | ---------------------- |
74
+ | `event_name` | `Symbol` | The name of the event. |
75
+ | `data` | `Hash` | The data of the event. |
76
76
 
77
77
  #### `ready()`
78
78
 
@@ -91,6 +91,12 @@ Fires when the client is resumed connection.
91
91
  Fires when an error occurs during an event.
92
92
  Defaults to printing the error to stderr, override to handle it yourself.
93
93
 
94
+ | Parameter | Type | Description |
95
+ | ------------ | --------------- | --------------------------- |
96
+ | `event_name` | `Symbol` | The name of the event. |
97
+ | `args` | `Array<Object>` | The arguments of the event. |
98
+ | `error` | `Exception` | The error that occurred. |
99
+
94
100
  #### `setup()`
95
101
 
96
102
  Fires when `discorb setup` is run.
@@ -557,16 +563,14 @@ Fires when a select menu is selected.
557
563
  | ------------- | -------------------------------------------------- | ----------------------- |
558
564
  | `interaction` | {Discorb::MessageComponentInteraction::SelectMenu} | The interaction object. |
559
565
 
560
- #### `form_submit(interaction)`
566
+ #### `modal_submit(interaction)`
561
567
 
562
- Fires when a form is submitted.
568
+ Fires when a modal is submitted.
563
569
 
564
570
  | Parameter | Type | Description |
565
571
  | ------------- | --------------------------- | ----------------------- |
566
572
  | `interaction` | {Discorb::ModalInteraction} | The interaction object. |
567
573
 
568
- #### `slash_command
569
-
570
574
  ### Voice events
571
575
 
572
576
  Because it's big, it's documented in {file:docs/voice_events.md}.
@@ -614,6 +618,38 @@ Fires when a scheduled event is ended.
614
618
  | --------- | ------------------------- | ------------------------------- |
615
619
  | `event` | {Discorb::ScheduledEvent} | The scheduled event that ended. |
616
620
 
621
+ ### Automod events
622
+
623
+ #### `auto_moderation_rule_create(rule)`
624
+
625
+ Fires when an auto moderation rule is created.
626
+
627
+ | Parameter | Type | Description |
628
+ | --------- | ---------------------- | --------------------------------- |
629
+ | `rule` | {Discorb::AutoModRule} | The created auto moderation rule. |
630
+
631
+ #### `auto_moderation_rule_update(rule)`
632
+
633
+ Fires when an auto moderation rule is updated.
634
+
635
+ | Parameter | Type | Description |
636
+ | --------- | ---------------------- | --------------------------------- |
637
+ | `rule` | {Discorb::AutoModRule} | The updated auto moderation rule. |
638
+
639
+ #### `auto_moderation_rule_delete(rule)`
640
+
641
+ Fires when an auto moderation rule is deleted.
642
+
643
+ | Parameter | Type | Description |
644
+ | --------- | ---------------------- | --------------------------------- |
645
+ | `rule` | {Discorb::AutoModRule} | The deleted auto moderation rule. |
646
+
647
+ #### `auto_moderation_action_execution(event)`
648
+
649
+ | Parameter | Type | Description |
650
+ | --------- | ------------------------------------------------------ | -------------------------- |
651
+ | `event` | {Discorb::Gateway::AutoModerationActionExecutionEvent} | The auto moderation event. |
652
+
617
653
  ### Low-level events
618
654
 
619
655
  #### `guild_create(guild)`
data/docs/tutorial.md CHANGED
@@ -21,7 +21,7 @@ Let's get started!
21
21
  - Good editor
22
22
  They are recommended:
23
23
  - [VSCode](https://code.visualstudio.com/)
24
- - [Atom](https://atom.io/)
24
+ - [RubyMine](https://www.jetbrains.com/ruby/)
25
25
  - [Sublime Text](https://www.sublimetext.com/)
26
26
  - [Brackets](https://brackets.io/)
27
27
  - [Notepad++](https://notepad-plus-plus.org/)
@@ -98,10 +98,10 @@ You will get other files if you specify `--git`.
98
98
  Open `main.rb`, you will see the following code:
99
99
 
100
100
  ```ruby
101
- require "discorb"
102
- require "dotenv"
101
+ # frozen_string_literal: true
103
102
 
104
- Dotenv.load # Loads .env file
103
+ require "discorb"
104
+ require "dotenv/load" # Load environment variables from .env file.
105
105
 
106
106
  client = Discorb::Client.new # Create client for connecting to Discord
107
107
 
@@ -115,10 +115,10 @@ client.run ENV["TOKEN"] # Starts client
115
115
  Open `.env`, you will see:
116
116
 
117
117
  ```
118
- TOKEN=Y0urB0tT0k3nHer3.Th1sT0ken.W0ntWorkB3c4useItH4sM34n1ng
118
+ TOKEN=
119
119
  ```
120
120
 
121
- Replace `Y0urB0tT0k3nHer3.Th1sT0ken.W0ntWorkB3c4useItH4sM34n1ng` with your bot token.
121
+ Put your token after `TOKEN=`.
122
122
  Remember to keep this file secret!
123
123
 
124
124
  Open terminal and type:
@@ -194,4 +194,4 @@ You did it! Your bot won't respond to bot's messages anymore.
194
194
  This is the end of tutorial.
195
195
 
196
196
  To learn more, check out the [documentation](https://discorb-lib.github.io/).
197
- You can also check out [Examples](docs/examples).
197
+ You can also check out [Examples](https://github.com/discorb-lib/discorb/tree/main/examples).
data/docs/voice_events.md CHANGED
@@ -12,7 +12,7 @@ Fires when someone joins a voice channel.
12
12
 
13
13
  | Parameter | Type | Description |
14
14
  | --------- | --------------------- | ---------------------------------------- |
15
- | state | {Discorb::VoiceState} | The voice state of the user that joined. |
15
+ | `state` | {Discorb::VoiceState} | The voice state of the user that joined. |
16
16
 
17
17
  #### `voice_channel_disconnect(state)`
18
18
 
@@ -20,7 +20,7 @@ Fires when someone leaves a voice channel.
20
20
 
21
21
  | Parameter | Type | Description |
22
22
  | --------- | --------------------- | -------------------------------------- |
23
- | state | {Discorb::VoiceState} | The voice state of the user that left. |
23
+ | `state` | {Discorb::VoiceState} | The voice state of the user that left. |
24
24
 
25
25
  #### `voice_channel_move(before, after)`
26
26
 
@@ -28,8 +28,8 @@ Fires when someone moves to a different voice channel.
28
28
 
29
29
  | Parameter | Type | Description |
30
30
  | --------- | --------------------- | -------------------------------------------- |
31
- | before | {Discorb::VoiceState} | The voice state of the user before the move. |
32
- | after | {Discorb::VoiceState} | The voice state of the user after the move. |
31
+ | `before` | {Discorb::VoiceState} | The voice state of the user before the move. |
32
+ | `after` | {Discorb::VoiceState} | The voice state of the user after the move. |
33
33
 
34
34
  #### `voice_channel_update(before, after)`
35
35
 
@@ -37,8 +37,8 @@ Fires when a voice channel is connected, disconnected, or updated.
37
37
 
38
38
  | Parameter | Type | Description |
39
39
  | --------- | --------------------- | ---------------------------------- |
40
- | before | {Discorb::VoiceState} | The voice state before the update. |
41
- | after | {Discorb::VoiceState} | The voice state after the update. |
40
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
41
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
42
42
 
43
43
  ### Mute Events
44
44
 
@@ -281,5 +281,5 @@ Fired when a user changes voice state.
281
281
 
282
282
  | Parameter | Type | Description |
283
283
  | --------- | --------------------- | ---------------------------------- |
284
- | before | {Discorb::VoiceState} | The voice state before the update. |
285
- | after | {Discorb::VoiceState} | The voice state after the update. |
284
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
285
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |