discorb 0.16.0 → 0.18.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 (199) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +1 -0
  3. data/.github/workflows/build_main.yml +2 -2
  4. data/.github/workflows/build_version.yml +1 -1
  5. data/.github/workflows/codeql-analysis.yml +1 -1
  6. data/.github/workflows/lint-push.yml +3 -5
  7. data/.github/workflows/lint.yml +2 -4
  8. data/.github/workflows/spec.yml +33 -0
  9. data/.github/workflows/validate.yml +21 -0
  10. data/.gitignore +2 -0
  11. data/.lefthook/commit-msg/validator.rb +5 -0
  12. data/.rspec +2 -0
  13. data/.rspec_parallel +2 -0
  14. data/.rubocop.yml +43 -6
  15. data/Changelog.md +30 -1
  16. data/Gemfile +20 -8
  17. data/Rakefile +226 -98
  18. data/Steepfile +28 -0
  19. data/bin/console +3 -3
  20. data/docs/Examples.md +1 -1
  21. data/docs/application_command.md +156 -47
  22. data/docs/cli/irb.md +2 -2
  23. data/docs/cli/new.md +14 -9
  24. data/docs/cli/run.md +7 -11
  25. data/docs/cli.md +17 -10
  26. data/docs/events.md +247 -213
  27. data/docs/extension.md +1 -2
  28. data/docs/faq.md +0 -1
  29. data/docs/tutorial.md +18 -18
  30. data/docs/voice_events.md +106 -106
  31. data/examples/commands/message.rb +68 -0
  32. data/examples/commands/permission.rb +19 -0
  33. data/examples/commands/slash.rb +48 -0
  34. data/examples/commands/user.rb +54 -0
  35. data/examples/components/authorization_button.rb +4 -3
  36. data/examples/components/select_menu.rb +6 -3
  37. data/examples/extension/main.rb +2 -1
  38. data/examples/extension/message_expander.rb +6 -2
  39. data/examples/sig/commands/message.rbs +5 -0
  40. data/examples/simple/eval.rb +3 -2
  41. data/examples/simple/ping_pong.rb +2 -1
  42. data/examples/simple/rolepanel.rb +17 -6
  43. data/examples/simple/shard.rb +3 -2
  44. data/examples/simple/wait_for_message.rb +4 -1
  45. data/exe/discorb +33 -18
  46. data/lefthook.yml +45 -0
  47. data/lib/discorb/allowed_mentions.rb +2 -1
  48. data/lib/discorb/app_command/command.rb +130 -72
  49. data/lib/discorb/app_command/common.rb +25 -0
  50. data/lib/discorb/app_command/handler.rb +130 -33
  51. data/lib/discorb/app_command.rb +2 -1
  52. data/lib/discorb/application.rb +1 -0
  53. data/lib/discorb/asset.rb +1 -2
  54. data/lib/discorb/attachment.rb +1 -1
  55. data/lib/discorb/audit_logs.rb +19 -10
  56. data/lib/discorb/automod.rb +269 -0
  57. data/lib/discorb/channel/base.rb +108 -0
  58. data/lib/discorb/channel/category.rb +32 -0
  59. data/lib/discorb/channel/container.rb +44 -0
  60. data/lib/discorb/channel/dm.rb +28 -0
  61. data/lib/discorb/channel/guild.rb +246 -0
  62. data/lib/discorb/channel/stage.rb +140 -0
  63. data/lib/discorb/channel/text.rb +336 -0
  64. data/lib/discorb/channel/thread.rb +325 -0
  65. data/lib/discorb/channel/voice.rb +79 -0
  66. data/lib/discorb/channel.rb +2 -1165
  67. data/lib/discorb/client.rb +50 -36
  68. data/lib/discorb/color.rb +37 -60
  69. data/lib/discorb/common.rb +2 -1
  70. data/lib/discorb/components/button.rb +2 -1
  71. data/lib/discorb/components/select_menu.rb +4 -2
  72. data/lib/discorb/components/text_input.rb +12 -2
  73. data/lib/discorb/components.rb +1 -1
  74. data/lib/discorb/dictionary.rb +1 -1
  75. data/lib/discorb/embed.rb +26 -10
  76. data/lib/discorb/emoji.rb +31 -4
  77. data/lib/discorb/emoji_table.rb +4969 -3
  78. data/lib/discorb/event.rb +29 -4
  79. data/lib/discorb/exe/about.rb +2 -1
  80. data/lib/discorb/exe/irb.rb +2 -4
  81. data/lib/discorb/exe/new.rb +89 -26
  82. data/lib/discorb/exe/run.rb +8 -22
  83. data/lib/discorb/exe/setup.rb +25 -12
  84. data/lib/discorb/exe/show.rb +4 -3
  85. data/lib/discorb/extend.rb +1 -0
  86. data/lib/discorb/extension.rb +6 -7
  87. data/lib/discorb/flag.rb +13 -2
  88. data/lib/discorb/gateway.rb +79 -589
  89. data/lib/discorb/gateway_events.rb +638 -0
  90. data/lib/discorb/guild.rb +318 -67
  91. data/lib/discorb/guild_template.rb +11 -5
  92. data/lib/discorb/http.rb +53 -24
  93. data/lib/discorb/integration.rb +4 -1
  94. data/lib/discorb/intents.rb +28 -19
  95. data/lib/discorb/interaction/autocomplete.rb +28 -16
  96. data/lib/discorb/interaction/command.rb +42 -14
  97. data/lib/discorb/interaction/components.rb +5 -2
  98. data/lib/discorb/interaction/modal.rb +0 -1
  99. data/lib/discorb/interaction/response.rb +125 -26
  100. data/lib/discorb/interaction/root.rb +13 -13
  101. data/lib/discorb/interaction.rb +1 -0
  102. data/lib/discorb/invite.rb +5 -2
  103. data/lib/discorb/member.rb +28 -8
  104. data/lib/discorb/message.rb +60 -25
  105. data/lib/discorb/message_meta.rb +3 -3
  106. data/lib/discorb/modules.rb +59 -16
  107. data/lib/discorb/presence.rb +2 -0
  108. data/lib/discorb/rate_limit.rb +7 -2
  109. data/lib/discorb/reaction.rb +2 -2
  110. data/lib/discorb/role.rb +20 -5
  111. data/lib/discorb/shard.rb +1 -1
  112. data/lib/discorb/sticker.rb +9 -8
  113. data/lib/discorb/user.rb +4 -3
  114. data/lib/discorb/utils/colored_puts.rb +1 -0
  115. data/lib/discorb/voice_state.rb +6 -2
  116. data/lib/discorb/webhook.rb +64 -31
  117. data/lib/discorb.rb +7 -5
  118. data/po/yard.pot +20 -20
  119. data/rbs_collection.lock.yaml +88 -0
  120. data/rbs_collection.yaml +21 -0
  121. data/sig/async.rbs +11 -0
  122. data/sig/discorb/activity.rbs +23 -0
  123. data/sig/discorb/allowed_mentions.rbs +44 -0
  124. data/sig/discorb/app_command/base.rbs +282 -0
  125. data/sig/discorb/app_command/handler.rbs +171 -0
  126. data/sig/discorb/application.rbs +142 -0
  127. data/sig/discorb/asset.rbs +32 -0
  128. data/sig/discorb/attachment.rbs +91 -0
  129. data/sig/discorb/audit_log.rbs +231 -0
  130. data/sig/discorb/automod.rbs +128 -0
  131. data/sig/discorb/avatar.rbs +26 -0
  132. data/sig/discorb/channel/base.rbs +179 -0
  133. data/sig/discorb/channel/category.rbs +56 -0
  134. data/sig/discorb/channel/container.rbs +29 -0
  135. data/sig/discorb/channel/dm.rbs +14 -0
  136. data/sig/discorb/channel/news.rbs +20 -0
  137. data/sig/discorb/channel/stage.rbs +77 -0
  138. data/sig/discorb/channel/text.rbs +158 -0
  139. data/sig/discorb/channel/thread.rbs +185 -0
  140. data/sig/discorb/channel/voice.rbs +41 -0
  141. data/sig/discorb/client.rbs +2495 -0
  142. data/sig/discorb/color.rbs +142 -0
  143. data/sig/discorb/component/base.rbs +28 -0
  144. data/sig/discorb/component/button.rbs +65 -0
  145. data/sig/discorb/component/select_menu.rbs +107 -0
  146. data/sig/discorb/component/text_input.rbs +69 -0
  147. data/sig/discorb/connectable.rbs +8 -0
  148. data/sig/discorb/custom_emoji.rbs +90 -0
  149. data/sig/discorb/dictionary.rbs +85 -0
  150. data/sig/discorb/discord_model.rbs +15 -0
  151. data/sig/discorb/embed.rbs +279 -0
  152. data/sig/discorb/emoji.rbs +13 -0
  153. data/sig/discorb/error.rbs +73 -0
  154. data/sig/discorb/event_handler.rbs +27 -0
  155. data/sig/discorb/extension.rbs +1734 -0
  156. data/sig/discorb/flag.rbs +72 -0
  157. data/sig/discorb/gateway.rbs +481 -0
  158. data/sig/discorb/guild.rbs +870 -0
  159. data/sig/discorb/guild_template.rbs +174 -0
  160. data/sig/discorb/http.rbs +147 -0
  161. data/sig/discorb/image.rbs +20 -0
  162. data/sig/discorb/integration.rbs +118 -0
  163. data/sig/discorb/intents.rbs +97 -0
  164. data/sig/discorb/interaction/autocomplete.rbs +9 -0
  165. data/sig/discorb/interaction/base.rbs +66 -0
  166. data/sig/discorb/interaction/command.rbs +66 -0
  167. data/sig/discorb/interaction/message_component.rbs +140 -0
  168. data/sig/discorb/interaction/modal.rbs +50 -0
  169. data/sig/discorb/interaction/responder.rbs +157 -0
  170. data/sig/discorb/invite.rbs +86 -0
  171. data/sig/discorb/member.rbs +187 -0
  172. data/sig/discorb/message.rbs +469 -0
  173. data/sig/discorb/messageable.rbs +153 -0
  174. data/sig/discorb/partial_emoji.rbs +35 -0
  175. data/sig/discorb/permissions.rbs +149 -0
  176. data/sig/discorb/presence.rbs +237 -0
  177. data/sig/discorb/reaction.rbs +33 -0
  178. data/sig/discorb/role.rbs +145 -0
  179. data/sig/discorb/scheduled_event.rbs +148 -0
  180. data/sig/discorb/shard.rbs +62 -0
  181. data/sig/discorb/snowflake.rbs +56 -0
  182. data/sig/discorb/stage_instance.rbs +63 -0
  183. data/sig/discorb/sticker.rbs +116 -0
  184. data/sig/discorb/system_channel_flag.rbs +17 -0
  185. data/sig/discorb/unicode_emoji.rbs +49 -0
  186. data/sig/discorb/user.rbs +93 -0
  187. data/sig/discorb/utils.rbs +8 -0
  188. data/sig/discorb/voice_region.rbs +30 -0
  189. data/sig/discorb/voice_state.rbs +71 -0
  190. data/sig/discorb/webhook.rbs +327 -0
  191. data/sig/discorb/welcome_screen.rbs +78 -0
  192. data/sig/discorb.rbs +6 -7230
  193. data/sig/manifest.yaml +3 -0
  194. data/sig/override.rbs +19 -0
  195. data/template-replace/files/css/common.css +4 -0
  196. metadata +102 -6
  197. data/examples/commands/bookmarker.rb +0 -42
  198. data/examples/commands/hello.rb +0 -10
  199. data/examples/commands/inspect.rb +0 -25
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "bundler/gem_tasks"
4
4
  require_relative "lib/discorb/utils/colored_puts"
5
+ require "parallel_tests"
5
6
  task default: %i[]
6
7
 
7
8
  # @private
@@ -15,6 +16,11 @@ def current_version
15
16
  end
16
17
  end
17
18
 
19
+ desc "Run spec with parallel_rspec"
20
+ task :spec do
21
+ sh "parallel_rspec spec/*.spec.rb spec/**/*.spec.rb"
22
+ end
23
+
18
24
  desc "Build emoji_table.rb"
19
25
  task :emoji_table do
20
26
  require_relative "lib/discorb"
@@ -65,7 +71,7 @@ namespace :document do
65
71
  version = current_version
66
72
  desc "Just generate document"
67
73
  task :yard do
68
- sh "bundle exec yardoc -o doc/#{version} --locale #{ENV["rake_locale"] or "en"}"
74
+ sh "bundle exec yardoc -o doc/#{version} --locale #{ENV.fetch("rake_locale", nil) or "en"}"
69
75
  end
70
76
 
71
77
  desc "Replace files"
@@ -76,7 +82,7 @@ namespace :document do
76
82
  task :css do
77
83
  iputs "Replacing css"
78
84
  Dir.glob("template-replace/files/**/*.*")
79
- .map { |f| f.delete_prefix("template-replace/files") }.each do |file|
85
+ .map { |f| f.delete_prefix("template-replace/files") }.each do |file|
80
86
  FileUtils.cp("template-replace/files" + file, "doc/#{version}/#{file}")
81
87
  end
82
88
  sputs "Successfully replaced css"
@@ -135,9 +141,11 @@ namespace :document do
135
141
  sputs "Successfully replaced CRLF with LF"
136
142
  end
137
143
 
144
+ desc "change locale of current document"
138
145
  task :locale do
139
146
  next if ENV["rake_locale"].nil?
140
- require_relative "template-replace/scripts/locale_#{ENV["rake_locale"]}.rb"
147
+
148
+ require_relative "template-replace/scripts/locale_#{ENV.fetch("rake_locale", nil)}.rb"
141
149
  replace_locale("doc/main")
142
150
  end
143
151
  end
@@ -196,11 +204,12 @@ namespace :document do
196
204
  end
197
205
 
198
206
  namespace :locale do
207
+ desc "Generate Japanese document"
199
208
  task :ja do
200
209
  require "crowdin-api"
201
210
  require "zip"
202
211
  crowdin = Crowdin::Client.new do |config|
203
- config.api_token = ENV["CROWDIN_PERSONAL_TOKEN"]
212
+ config.api_token = ENV.fetch("CROWDIN_PERSONAL_TOKEN", nil)
204
213
  config.project_id = ENV["CROWDIN_PROJECT_ID"].to_i
205
214
  end
206
215
  build = crowdin.build_project_translation["data"]["id"]
@@ -216,116 +225,235 @@ namespace :document do
216
225
  Rake::Task["document:replace"].execute
217
226
  end
218
227
 
228
+ desc "Generate English document"
219
229
  task :en do
220
230
  Rake::Task["document"].execute("locale:en")
221
231
  end
222
232
  end
223
233
  end
224
234
 
225
- task :rbs do
226
- require "open3"
227
- type_errors = {
228
- "SORD_ERROR_SymbolSymbolSymbolInteger" => "{ r: Integer, g: Integer, b: Integer}",
229
- "SORD_ERROR_DiscorbRoleDiscorbMemberDiscorbPermissionOverwrite" => "Hash[Discorb::Role | Discorb::Member, Discorb::PermissionOverwrite]",
230
- "SORD_ERROR_DiscorbRoleDiscorbMemberPermissionOverwrite" => "Hash[Discorb::Role | Discorb::Member, Discorb::PermissionOverwrite]",
231
- "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"',
232
- "SORD_ERROR_dark | SORD_ERROR_light" => '"dark" | "light"',
233
- "SORD_ERROR_SymbolStringSymbolboolSymbolObject" => "String | Integer | Float",
234
- }
235
- regenerate = ARGV.include?("--regenerate") || ARGV.include?("-r")
236
-
237
- sh "sord gen sig/discorb.rbs --keep-original-comments --no-sord-comments" + (regenerate ? " --regenerate" : " --no-regenerate")
238
- base = File.read("sig/discorb.rbs")
239
- base.gsub!(/\n +def _set_data: \(.+\) -> untyped\n\n/, "")
240
- base.gsub!(/( )?( *)# @private.+?(?:\n\n(?=\1\2#)|(?=\n\2end))/sm, "")
241
- base.gsub!(/untyped ([a-z_]*id)/, "_ToS \\1")
242
- # #region rbs dictionary
243
- base.gsub!(/ class Dictionary.+?end\n/ms, <<-RBS)
244
- class Dictionary[K, V]
245
- #
246
- # Initialize a new Dictionary.
247
- #
248
- # @param [Hash] hash A hash of items to add to the dictionary.
249
- # @param [Integer] limit The maximum number of items in the dictionary.
250
- # @param [false, Proc] sort Whether to sort the items in the dictionary.
251
- def initialize: (?::Hash[untyped, untyped] hash, ?limit: Integer?, ?sort: (bool | Proc)) -> void
252
-
253
- #
254
- # Registers a new item in the dictionary.
255
- #
256
- # @param [#to_s] id The ID of the item.
257
- # @param [Object] body The item to register.
258
- #
259
- # @return [self] The dictionary.
260
- def register: (_ToS id, Object body) -> self
261
-
262
- #
263
- # Merges another dictionary into this one.
264
- #
265
- # @param [Discorb::Dictionary] other The dictionary to merge.
266
- def merge: (Discorb::Dictionary other) -> untyped
267
-
268
- #
269
- # Removes an item from the dictionary.
270
- #
271
- # @param [#to_s] id The ID of the item to remove.
272
- def remove: (_ToS id) -> untyped
273
-
274
- #
275
- # Get an item from the dictionary.
276
- #
277
- # @param [#to_s] id The ID of the item.
278
- # @return [Object] The item.
279
- # @return [nil] if the item was not found.
280
- #
281
- # @overload get(index)
282
- # @param [Integer] index The index of the item.
283
- #
284
- # @return [Object] The item.
285
- # @return [nil] if the item is not found.
286
- def get: (K id) -> V?
287
-
288
- #
289
- # Returns the values of the dictionary.
290
- #
291
- # @return [Array] The values of the dictionary.
292
- def values: () -> ::Array[V]
293
-
294
- #
295
- # Checks if the dictionary has an ID.
296
- #
297
- # @param [#to_s] id The ID to check.
298
- #
299
- # @return [Boolean] `true` if the dictionary has the ID, `false` otherwise.
300
- def has?: (_ToS id) -> bool
301
-
302
- #
303
- # Send a message to the array of values.
304
- def method_missing: (untyped name) -> untyped
305
-
306
- def respond_to_missing?: (untyped name, untyped args, untyped kwargs) -> bool
307
-
308
- def inspect: () -> untyped
309
-
310
- # @return [Integer] The maximum number of items in the dictionary.
311
- 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)
436
+ end
437
+
438
+ desc "Lint rbs with stree"
439
+ task :lint do
440
+ sh "stree check --plugins=rbs sig/**/*.rbs"
312
441
  end
313
- RBS
314
- # #endregion
315
- type_errors.each do |error, type|
316
- base.gsub!(error, type)
442
+
443
+ desc "Autofix rbs with stree"
444
+ task "lint:fix" do
445
+ sh "stree write --plugins=rbs sig/**/*.rbs"
317
446
  end
318
- File.write("sig/discorb.rbs", base)
319
447
  end
320
448
 
321
449
  task document: %i[document:yard document:replace]
322
450
 
323
451
  desc "Lint code with rubocop"
324
452
  task :lint do
325
- sh "rubocop lib"
453
+ sh "rubocop lib spec Rakefile"
326
454
  end
327
455
 
328
456
  desc "Autofix code with rubocop"
329
457
  task "lint:fix" do
330
- sh "rubocop lib -A"
458
+ sh "rubocop lib spec Rakefile -A"
331
459
  end
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
data/bin/console CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'bundler/setup'
5
- require 'discorb'
4
+ require "bundler/setup"
5
+ require "discorb"
6
6
 
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
@@ -11,5 +11,5 @@ require 'discorb'
11
11
  # require "pry"
12
12
  # Pry.start
13
13
 
14
- require 'irb'
14
+ require "irb"
15
15
  IRB.start(__FILE__)
data/docs/Examples.md CHANGED
@@ -25,4 +25,4 @@
25
25
  #### Note
26
26
 
27
27
  This example is not shown correctly in the docs.
28
- [Read this example on GitHub](https://github.com/discorb-lib/discorb/blob/main/examples/components/select_menu.rb).
28
+ [Read this example on GitHub](https://github.com/discorb-lib/discorb/blob/main/examples/components/select_menu.rb).