discorb 0.17.0 → 0.18.1

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/spec.yml +4 -1
  4. data/.github/workflows/validate.yml +21 -0
  5. data/.gitignore +2 -0
  6. data/Changelog.md +22 -0
  7. data/Gemfile +6 -0
  8. data/README.md +2 -1
  9. data/Rakefile +210 -97
  10. data/Steepfile +28 -0
  11. data/docs/application_command.md +22 -4
  12. data/docs/events.md +42 -6
  13. data/docs/tutorial.md +7 -7
  14. data/docs/voice_events.md +2 -2
  15. data/examples/commands/message.rb +12 -7
  16. data/examples/commands/permission.rb +2 -1
  17. data/examples/commands/slash.rb +23 -19
  18. data/examples/commands/user.rb +15 -12
  19. data/examples/components/authorization_button.rb +2 -1
  20. data/examples/components/select_menu.rb +4 -1
  21. data/examples/extension/main.rb +1 -0
  22. data/examples/extension/message_expander.rb +1 -0
  23. data/examples/sig/commands/message.rbs +5 -0
  24. data/examples/simple/eval.rb +1 -0
  25. data/examples/simple/ping_pong.rb +1 -0
  26. data/examples/simple/rolepanel.rb +16 -5
  27. data/examples/simple/shard.rb +2 -1
  28. data/examples/simple/wait_for_message.rb +3 -0
  29. data/exe/discorb +3 -3
  30. data/lib/discorb/allowed_mentions.rb +1 -1
  31. data/lib/discorb/app_command/command.rb +17 -17
  32. data/lib/discorb/app_command/handler.rb +22 -6
  33. data/lib/discorb/audit_logs.rb +9 -3
  34. data/lib/discorb/automod.rb +269 -0
  35. data/lib/discorb/channel/guild.rb +2 -1
  36. data/lib/discorb/channel/stage.rb +1 -1
  37. data/lib/discorb/channel/text.rb +11 -20
  38. data/lib/discorb/channel/thread.rb +15 -11
  39. data/lib/discorb/client.rb +12 -10
  40. data/lib/discorb/color.rb +37 -60
  41. data/lib/discorb/common.rb +1 -1
  42. data/lib/discorb/dictionary.rb +1 -1
  43. data/lib/discorb/embed.rb +4 -3
  44. data/lib/discorb/emoji.rb +2 -2
  45. data/lib/discorb/emoji_table.rb +4 -4
  46. data/lib/discorb/exe/about.rb +1 -1
  47. data/lib/discorb/exe/new.rb +1 -5
  48. data/lib/discorb/extension.rb +0 -4
  49. data/lib/discorb/flag.rb +2 -2
  50. data/lib/discorb/gateway.rb +26 -584
  51. data/lib/discorb/gateway_events.rb +638 -0
  52. data/lib/discorb/guild.rb +136 -17
  53. data/lib/discorb/guild_template.rb +1 -1
  54. data/lib/discorb/http.rb +48 -26
  55. data/lib/discorb/intents.rb +27 -18
  56. data/lib/discorb/interaction/command.rb +14 -10
  57. data/lib/discorb/interaction/response.rb +76 -16
  58. data/lib/discorb/interaction/root.rb +3 -0
  59. data/lib/discorb/member.rb +3 -3
  60. data/lib/discorb/message.rb +13 -11
  61. data/lib/discorb/message_meta.rb +2 -3
  62. data/lib/discorb/modules.rb +3 -2
  63. data/lib/discorb/presence.rb +4 -2
  64. data/lib/discorb/reaction.rb +6 -6
  65. data/lib/discorb/role.rb +1 -1
  66. data/lib/discorb/sticker.rb +3 -3
  67. data/lib/discorb/user.rb +2 -2
  68. data/lib/discorb/voice_state.rb +5 -5
  69. data/lib/discorb/webhook.rb +42 -21
  70. data/lib/discorb.rb +2 -2
  71. data/po/yard.pot +11 -11
  72. data/rbs_collection.lock.yaml +88 -0
  73. data/rbs_collection.yaml +21 -0
  74. data/sig/async.rbs +11 -0
  75. data/sig/discorb/activity.rbs +23 -0
  76. data/sig/discorb/allowed_mentions.rbs +44 -0
  77. data/sig/discorb/app_command/base.rbs +282 -0
  78. data/sig/discorb/app_command/handler.rbs +171 -0
  79. data/sig/discorb/application.rbs +142 -0
  80. data/sig/discorb/asset.rbs +32 -0
  81. data/sig/discorb/attachment.rbs +91 -0
  82. data/sig/discorb/audit_log.rbs +231 -0
  83. data/sig/discorb/automod.rbs +128 -0
  84. data/sig/discorb/avatar.rbs +26 -0
  85. data/sig/discorb/channel/base.rbs +179 -0
  86. data/sig/discorb/channel/category.rbs +56 -0
  87. data/sig/discorb/channel/container.rbs +29 -0
  88. data/sig/discorb/channel/dm.rbs +14 -0
  89. data/sig/discorb/channel/news.rbs +20 -0
  90. data/sig/discorb/channel/stage.rbs +77 -0
  91. data/sig/discorb/channel/text.rbs +158 -0
  92. data/sig/discorb/channel/thread.rbs +185 -0
  93. data/sig/discorb/channel/voice.rbs +41 -0
  94. data/sig/discorb/client.rbs +2495 -0
  95. data/sig/discorb/color.rbs +142 -0
  96. data/sig/discorb/component/base.rbs +28 -0
  97. data/sig/discorb/component/button.rbs +65 -0
  98. data/sig/discorb/component/select_menu.rbs +107 -0
  99. data/sig/discorb/component/text_input.rbs +69 -0
  100. data/sig/discorb/connectable.rbs +8 -0
  101. data/sig/discorb/custom_emoji.rbs +90 -0
  102. data/sig/discorb/dictionary.rbs +85 -0
  103. data/sig/discorb/discord_model.rbs +15 -0
  104. data/sig/discorb/embed.rbs +279 -0
  105. data/sig/discorb/emoji.rbs +13 -0
  106. data/sig/discorb/error.rbs +73 -0
  107. data/sig/discorb/event_handler.rbs +27 -0
  108. data/sig/discorb/extension.rbs +1734 -0
  109. data/sig/discorb/flag.rbs +72 -0
  110. data/sig/discorb/gateway.rbs +481 -0
  111. data/sig/discorb/guild.rbs +870 -0
  112. data/sig/discorb/guild_template.rbs +174 -0
  113. data/sig/discorb/http.rbs +147 -0
  114. data/sig/discorb/image.rbs +20 -0
  115. data/sig/discorb/integration.rbs +118 -0
  116. data/sig/discorb/intents.rbs +97 -0
  117. data/sig/discorb/interaction/autocomplete.rbs +9 -0
  118. data/sig/discorb/interaction/base.rbs +69 -0
  119. data/sig/discorb/interaction/command.rbs +66 -0
  120. data/sig/discorb/interaction/message_component.rbs +140 -0
  121. data/sig/discorb/interaction/modal.rbs +50 -0
  122. data/sig/discorb/interaction/responder.rbs +157 -0
  123. data/sig/discorb/invite.rbs +86 -0
  124. data/sig/discorb/member.rbs +187 -0
  125. data/sig/discorb/message.rbs +469 -0
  126. data/sig/discorb/messageable.rbs +153 -0
  127. data/sig/discorb/partial_emoji.rbs +35 -0
  128. data/sig/discorb/permissions.rbs +149 -0
  129. data/sig/discorb/presence.rbs +237 -0
  130. data/sig/discorb/reaction.rbs +33 -0
  131. data/sig/discorb/role.rbs +145 -0
  132. data/sig/discorb/scheduled_event.rbs +148 -0
  133. data/sig/discorb/shard.rbs +62 -0
  134. data/sig/discorb/snowflake.rbs +56 -0
  135. data/sig/discorb/stage_instance.rbs +63 -0
  136. data/sig/discorb/sticker.rbs +116 -0
  137. data/sig/discorb/system_channel_flag.rbs +17 -0
  138. data/sig/discorb/unicode_emoji.rbs +49 -0
  139. data/sig/discorb/user.rbs +93 -0
  140. data/sig/discorb/utils.rbs +8 -0
  141. data/sig/discorb/voice_region.rbs +30 -0
  142. data/sig/discorb/voice_state.rbs +71 -0
  143. data/sig/discorb/webhook.rbs +327 -0
  144. data/sig/discorb/welcome_screen.rbs +78 -0
  145. data/sig/discorb.rbs +11 -7232
  146. data/sig/manifest.yaml +3 -0
  147. data/sig/override.rbs +19 -0
  148. data/template-replace/files/css/common.css +4 -0
  149. metadata +83 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a56213c17efa8d538ddacbbe14f5d4d32b787384e02d21cf925aa0855db59e3
4
- data.tar.gz: a3fce194d0f243b931d3918553880656e0bac5b0228d2ccd7147cae1068e1c9b
3
+ metadata.gz: 5d310d54f09cb9be975ba75c37a717b159f3f4b2996686a5f40b7b86329657ab
4
+ data.tar.gz: 81ed8d1d40aa4bb851e018c56672e24d8346ee2c3544d44ebc48a5583e6b6b46
5
5
  SHA512:
6
- metadata.gz: aaced769a9309ab29050fdd89aed3164d7dbfe67e31dba2dd6caf91c83e5b6a16b00a941edc591a529619b13fdc0ec498e0cdfdda07c21849feece7c46a63a06
7
- data.tar.gz: 205d12c8f88eabd03de31bf9a184e84653727ebb0acc8d05daabe8f3b0e41273665855ecdf8a8456e40cdcefc64c537b756efbaf48c6dbe413ea6a1b10cd7375
6
+ metadata.gz: feed366d2ae2614f6c08a891f697245304047a4a1447fd2e5cdbed17829aea950e4b8fb6677b70e993bd613c6be3f1db880061f4fa77024bae6ce4caaf11683c
7
+ data.tar.gz: 5be8aa8414d67a58cf591f87b13b2ae5d0d8f17de8dc6399d9ef370967c79e39400596192e3ebb016934e36c69c2aae4dc19b0b0c4e86eb0903ddfb5e5495902
@@ -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
@@ -13,7 +13,10 @@ jobs:
13
13
  ruby-version:
14
14
  - "3.0"
15
15
  - "3.1"
16
- runs-on: ubuntu-latest
16
+ os:
17
+ - "ubuntu-latest"
18
+ - "windows-latest"
19
+ runs-on: ${{ matrix.os }}
17
20
  steps:
18
21
  - name: Set up Ruby
19
22
  uses: ruby/setup-ruby@v1
@@ -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/.gitignore CHANGED
@@ -61,3 +61,5 @@ tmp-doc
61
61
  doc
62
62
  *.zip
63
63
  **/*.po
64
+
65
+ .gem_rbs_collection
data/Changelog.md CHANGED
@@ -4,8 +4,30 @@
4
4
 
5
5
  # Changelog
6
6
 
7
+ ## v0.18
8
+
9
+ ### v0.18.1
10
+
11
+ - Add: Support `:length` option for `:string` type.
12
+ - Add: Add `Interaction#app_permissions`
13
+ - Fix: Fix typing of `:autocomplete` option.
14
+
15
+ ### v0.18.0
16
+
17
+ - Change!: `XXX#fired_by` is now `XXX#user` or `XXX#member`.
18
+ - Change!: `Message#to_reference` returns `Message::Reference`.
19
+ - Change!: `TextChannel#default_auto_archive_duration` is now Integer.
20
+ - Add: Support AutoMod.
21
+ - Change: `discorb new` doesn't do initial commit.
22
+
7
23
  ## v0.17
8
24
 
25
+ ### v0.17.1
26
+
27
+ - Add: Add valid rbs file.
28
+ - Change: Message content intent warning will show only once.
29
+ - Update: Update audit log events.
30
+
9
31
  ### v0.17.0
10
32
 
11
33
  - Change!: Delete `Interaction#target` and `Interaction#fired_by`.
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.0"
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.4.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,105 +232,218 @@ 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/, "")
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
+ client_rbs = File.read("sig/discorb/client.rbs")
240
+ extension_rbs = File.read("sig/discorb/extension.rbs")
241
+ event_document = File.read("./docs/events.md")
242
+ voice_event_document = File.read("./docs/voice_events.md")
243
+ event_reference = event_document.split("## Event reference")[1]
244
+ event_reference += voice_event_document.split("# Voice Events")[1]
245
+ event_reference.gsub!(/^### (.*)$/, "")
246
+ events = []
247
+ event_reference.split("#### `")[1..].each do |event|
248
+ header, content = event.split("`\n", 2)
249
+ name = header.split("(")[0]
250
+ description = content.split("| Parameter", 2)[0].strip
251
+ parameters = if content.include?("| Parameter")
252
+ content.scan(/\| `(.*?)` +\| (.*?) +\| (.*?) +\|/)
253
+ else
254
+ []
255
+ end
256
+ events << {
257
+ name: name,
258
+ description: description,
259
+ parameters: parameters.map { |p| { name: p[0], type: p[1], description: p[2] } },
260
+ }
261
+ end
262
+ event_sig = +""
263
+ event_lock_sig = +""
264
+ extension_sig = +""
265
+ events.each do |event|
266
+ args = []
267
+ event[:parameters].each do |parameter|
268
+ args << {
269
+ name: parameter[:name],
270
+ type: if parameter[:type].start_with?("?")
271
+ parameter[:type][1..]
272
+ else
273
+ parameter[:type]
274
+ end.tr("{}`", "").tr("<>", "[]").gsub(", ", " | ").then do |t|
275
+ if event[:name] == "event_receive"
276
+ case t
277
+ when "Hash"
278
+ next "Discorb::json"
279
+ end
280
+ end
281
+ t
282
+ end,
283
+ }
284
+ end
285
+ sig = args.map { |a| "#{a[:type]} #{a[:name]}" }.join(", ")
286
+ tuple_sig = args.map { |a| a[:type] }.join(", ")
287
+ tuple_sig = "[" + tuple_sig + "]" if args.length > 1
288
+ tuple_sig = "void" if args.length.zero?
289
+ event_sig << <<~RBS
290
+ | (:#{event[:name]} event_name, ?id: Symbol?, **untyped metadata) { (#{sig}) -> void } -> Discorb::EventHandler
291
+ RBS
292
+ event_lock_sig << <<~RBS
293
+ | (:#{event[:name]} event, ?Integer? timeout) { (#{sig}) -> boolish } -> Async::Task[#{tuple_sig}]
294
+ RBS
295
+ extension_sig << <<~RBS
296
+ | (:#{event[:name]} event_name, ?id: Symbol?, **untyped metadata) { (#{sig}) -> void } -> void
297
+ RBS
298
+ end
299
+ event_sig.sub!("| ", " ").rstrip!
300
+ event_lock_sig.sub!("| ", " ").rstrip!
301
+ extension_sig.sub!("| ", " ").rstrip!
302
+ res = client_rbs.gsub!(/\# marker: on\n(?:[\s\S]*?\n)?( +)\# endmarker: on\n/) do
303
+ indent = Regexp.last_match(1)
304
+ "# marker: on\n#{event_sig.gsub(/^/, "#{indent} ")}\n#{indent}# endmarker: on\n"
305
+ end
306
+ raise "Failed to generate Client#on" unless res
307
+
308
+ res = client_rbs.gsub!(/\# marker: once\n(?:[\s\S]*?\n)?( +)\# endmarker: once\n/) do
309
+ indent = Regexp.last_match(1)
310
+ "# marker: once\n#{event_sig.gsub(/^/, "#{indent} ")}\n#{indent}# endmarker: once\n"
311
+ end
312
+ raise "Failed to generate Client#once" unless res
313
+
314
+ res = client_rbs.gsub!(/\# marker: event_lock\n(?:[\s\S]*?\n)?( +)\# endmarker: event_lock\n/) do
315
+ indent = Regexp.last_match(1)
316
+ "# marker: event_lock\n#{event_lock_sig.gsub(/^/, "#{indent} ")}\n#{indent}# endmarker: event_lock\n"
317
+ end
318
+ raise "Failed to generate Client#event_lock" unless res
319
+
320
+ res = extension_rbs.gsub!(/\# marker: event\n(?:[\s\S]*?\n)?( +)\# endmarker: event\n/) do
321
+ indent = Regexp.last_match(1)
322
+ "# marker: event\n#{extension_sig.gsub(/^/, "#{indent} ")}\n#{indent}# endmarker: event\n"
323
+ end
324
+ raise "Failed to generate Extension.event" unless res
325
+
326
+ res = extension_rbs.gsub!(/\# marker: once_event\n(?:[\s\S]*?\n)?( +)\# endmarker: once_event\n/) do
327
+ indent = Regexp.last_match(1)
328
+ "# marker: once_event\n#{extension_sig.gsub(/^/, "#{indent} ")}\n#{indent}# endmarker: once_event\n"
329
+ end
330
+ raise "Failed to generate Extension.once_event" unless res
331
+
332
+ File.write("sig/discorb/client.rbs", client_rbs, mode: "wb")
333
+ File.write("sig/discorb/extension.rbs", extension_rbs, mode: "wb")
334
+ end
335
+
336
+ desc "Generate rbs file using sord"
337
+ task :sord do
338
+ require "open3"
339
+ # rubocop: disable Layout/LineLength
340
+ type_errors = {
341
+ "SORD_ERROR_SymbolSymbolSymbolInteger" => "{ r: Integer, g: Integer, b: Integer}",
342
+ "SORD_ERROR_DiscorbRoleDiscorbMemberDiscorbPermissionOverwrite" => "Hash[Discorb::Role | Discorb::Member, Discorb::PermissionOverwrite]",
343
+ "SORD_ERROR_DiscorbRoleDiscorbMemberPermissionOverwrite" => "Hash[Discorb::Role | Discorb::Member, Discorb::PermissionOverwrite]",
344
+ "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"',
345
+ "SORD_ERROR_dark | SORD_ERROR_light" => '"dark" | "light"',
346
+ "SORD_ERROR_SymbolStringSymbolboolSymbolObject" => "String | Integer | Float",
347
+ }
348
+ # rubocop: enable Layout/LineLength
349
+ regenerate = ARGV.include?("--regenerate") || ARGV.include?("-r")
350
+
351
+ sh "sord gen sig/discorb.rbs --keep-original-comments --no-sord-comments" +
352
+ (regenerate ? " --regenerate" : " --no-regenerate")
353
+ base = File.read("sig/discorb.rbs")
354
+ base.gsub!(/\n +def _set_data: \(.+\) -> untyped\n\n/, "\n")
355
+ # base.gsub!(/( )?( *)# @private.+?(?:\n\n(?=\1\2#)|(?=\n\2end))/sm, "")
356
+ base.gsub!(/untyped ([a-z_]*id)/, "_ToS \\1")
357
+ # #region rbs dictionary
358
+ base.gsub!(/ class Dictionary.+?end\n/ms, <<-RBS)
359
+ class Dictionary[K, V]
360
+ #
361
+ # Initialize a new Dictionary.
362
+ #
363
+ # @param [Hash] hash A hash of items to add to the dictionary.
364
+ # @param [Integer] limit The maximum number of items in the dictionary.
365
+ # @param [false, Proc] sort Whether to sort the items in the dictionary.
366
+ def initialize: (?::Hash[untyped, untyped] hash, ?limit: Integer?, ?sort: (bool | Proc)) -> void
367
+
368
+ #
369
+ # Registers a new item in the dictionary.
370
+ #
371
+ # @param [#to_s] id The ID of the item.
372
+ # @param [Object] body The item to register.
373
+ #
374
+ # @return [self] The dictionary.
375
+ def register: (_ToS id, Object body) -> self
376
+
377
+ #
378
+ # Merges another dictionary into this one.
379
+ #
380
+ # @param [Discorb::Dictionary] other The dictionary to merge.
381
+ def merge: (Discorb::Dictionary other) -> untyped
382
+
383
+ #
384
+ # Removes an item from the dictionary.
385
+ #
386
+ # @param [#to_s] id The ID of the item to remove.
387
+ def remove: (_ToS id) -> untyped
388
+
389
+ #
390
+ # Get an item from the dictionary.
391
+ #
392
+ # @param [#to_s] id The ID of the item.
393
+ # @return [Object] The item.
394
+ # @return [nil] if the item was not found.
395
+ #
396
+ # @overload get(index)
397
+ # @param [Integer] index The index of the item.
398
+ #
399
+ # @return [Object] The item.
400
+ # @return [nil] if the item is not found.
401
+ def get: (K id) -> V?
402
+
403
+ #
404
+ # Returns the values of the dictionary.
405
+ #
406
+ # @return [Array] The values of the dictionary.
407
+ def values: () -> ::Array[V]
408
+
409
+ #
410
+ # Checks if the dictionary has an ID.
411
+ #
412
+ # @param [#to_s] id The ID to check.
413
+ #
414
+ # @return [Boolean] `true` if the dictionary has the ID, `false` otherwise.
415
+ def has?: (_ToS id) -> bool
416
+
417
+ #
418
+ # Send a message to the array of values.
419
+ def method_missing: (untyped name) -> untyped
420
+
421
+ def respond_to_missing?: (untyped name, untyped args, untyped kwargs) -> bool
422
+
423
+ def inspect: () -> String
424
+
425
+ # @return [Integer] The maximum number of items in the dictionary.
426
+ attr_accessor limit: Integer
427
+ end
428
+ RBS
429
+ # #endregion
430
+ type_errors.each do |error, type|
431
+ base.gsub!(error, type)
432
+ end
433
+ base.gsub!("end\n\n\nend", "end\n")
434
+ base.gsub!(/ +$/m, "")
435
+ File.write("sig/discorb.rbs", base)
326
436
  end
327
- RBS
328
- # #endregion
329
- type_errors.each do |error, type|
330
- base.gsub!(error, type)
437
+
438
+ desc "Lint rbs with stree"
439
+ task :lint do
440
+ sh "stree check --plugins=rbs sig/**/*.rbs"
441
+ end
442
+
443
+ desc "Autofix rbs with stree"
444
+ task "lint:fix" do
445
+ sh "stree write --plugins=rbs sig/**/*.rbs"
331
446
  end
332
- base.gsub!("end\n\n\nend", "end\n")
333
- File.write("sig/discorb.rbs", base)
334
447
  end
335
448
 
336
449
  task document: %i[document:yard document:replace]
data/Steepfile ADDED
@@ -0,0 +1,28 @@
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
+ end
19
+ end
20
+
21
+ target :test do
22
+ signature "sig"
23
+ signature "examples/sig"
24
+
25
+ check "examples/**/*.rb"
26
+
27
+ library "net-http", "timeout"
28
+ end
@@ -54,11 +54,14 @@ client.run(ENV["DISCORD_BOT_TOKEN"])
54
54
 
55
55
  Block will be called with a {Discorb::Interaction} object and specified options.
56
56
 
57
+ #### Register options
58
+
59
+ You can set hash to `options` argument.
57
60
  In `options`, hash should be like this:
58
61
 
59
62
  ```ruby
60
63
  {
61
- "Name" => {
64
+ "name" => {
62
65
  type: :string,
63
66
  required: true,
64
67
  description: "The description of the command."
@@ -67,10 +70,11 @@ In `options`, hash should be like this:
67
70
  ```
68
71
 
69
72
  | Key | Type | Description |
70
- | ------------------------ | ---------------------------------------- | ------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
73
+ | ------------------------ | ---------------------------------------- | ------------------------------------------------------------------------------------- |
74
+ | `:name_localizations` | `Hash{Symbol => String}` | Localizations of option name. |
71
75
  | `:description` | `String` | Description of the option. |
72
- | `:required` | Boolean(true | false) | Whether the argument is required. `optional` will be used if not specified. |
73
- | `:optional` | Boolean(true | false) | Whether the argument is optional. `required` will be used if not specified. |
76
+ | `:required` | `Boolean(true\|false)` | Whether the argument is required. `optional` will be used if not specified. |
77
+ | `:optional` | `Boolean(true\|false)` | Whether the argument is optional. `required` will be used if not specified. |
74
78
  | `:type` | `Object` | Type of the option. |
75
79
  | `:choices` | `Hash{String => String, Integer, Float}` | Choice of the option. |
76
80
  | `:choices_localizations` | `Hash{String => Hash{Symbol => String}}` | Localization of the choice. Key must be the name of a choice. (See below for example) |
@@ -78,6 +82,7 @@ In `options`, hash should be like this:
78
82
  | `:channel_types` | `Array<Class<Discorb::Channel>>` | Type of the channel option. |
79
83
  | `:autocomplete` | `Proc` | Autocomplete function. |
80
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`. |
81
86
 
82
87
  `choices` should be unspecified if you don't want to use it.
83
88
  `choices` example:
@@ -116,6 +121,19 @@ In `type`, You must use one of the following:
116
121
  | `:channel` | Channel argument. | None |
117
122
  | `:role` | Role argument. | None |
118
123
 
124
+ The block will receive the options as arguments.
125
+
126
+ ```ruby
127
+ client.slash("hello", "Bot greets", {
128
+ "name" => {
129
+ type: :string,
130
+ description: "Name"
131
+ }
132
+ }) do |interaction, name|
133
+ interaction.post("Hello, #{name}!", ephemeral: true)
134
+ end
135
+ ```
136
+
119
137
  #### Group Slash Commands
120
138
 
121
139
  To register a group of slash commands, use {Discorb::ApplicationCommand::Handler#slash_group}.
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.
@@ -565,8 +571,6 @@ Fires when a form is submitted.
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
@@ -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. |