discorb 0.17.1 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/lint.yml +1 -3
- data/.github/workflows/validate.yml +21 -0
- data/Changelog.md +10 -0
- data/Gemfile +6 -0
- data/Rakefile +210 -98
- data/Steepfile +28 -0
- data/docs/events.md +42 -6
- data/docs/tutorial.md +7 -7
- data/docs/voice_events.md +2 -2
- data/examples/commands/message.rb +12 -7
- data/examples/commands/permission.rb +2 -1
- data/examples/commands/slash.rb +23 -19
- data/examples/commands/user.rb +15 -12
- data/examples/components/authorization_button.rb +2 -1
- data/examples/components/select_menu.rb +4 -1
- data/examples/extension/main.rb +1 -0
- data/examples/extension/message_expander.rb +1 -0
- data/examples/sig/commands/message.rbs +5 -0
- data/examples/simple/eval.rb +1 -0
- data/examples/simple/ping_pong.rb +1 -0
- data/examples/simple/rolepanel.rb +16 -5
- data/examples/simple/shard.rb +2 -1
- data/examples/simple/wait_for_message.rb +3 -0
- data/exe/discorb +3 -3
- data/lib/discorb/allowed_mentions.rb +1 -1
- data/lib/discorb/app_command/command.rb +12 -13
- data/lib/discorb/app_command/handler.rb +20 -6
- data/lib/discorb/audit_logs.rb +6 -2
- data/lib/discorb/automod.rb +269 -0
- data/lib/discorb/channel/guild.rb +2 -1
- data/lib/discorb/channel/stage.rb +1 -1
- data/lib/discorb/channel/text.rb +11 -20
- data/lib/discorb/channel/thread.rb +15 -11
- data/lib/discorb/client.rb +12 -10
- data/lib/discorb/color.rb +37 -60
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/dictionary.rb +1 -1
- data/lib/discorb/embed.rb +4 -3
- data/lib/discorb/emoji.rb +2 -2
- data/lib/discorb/exe/about.rb +1 -1
- data/lib/discorb/exe/new.rb +1 -5
- data/lib/discorb/extension.rb +0 -4
- data/lib/discorb/flag.rb +2 -2
- data/lib/discorb/gateway.rb +21 -582
- data/lib/discorb/gateway_events.rb +638 -0
- data/lib/discorb/guild.rb +136 -17
- data/lib/discorb/guild_template.rb +1 -1
- data/lib/discorb/http.rb +47 -25
- data/lib/discorb/intents.rb +27 -18
- data/lib/discorb/interaction/command.rb +14 -10
- data/lib/discorb/interaction/response.rb +74 -14
- data/lib/discorb/member.rb +3 -3
- data/lib/discorb/message.rb +13 -11
- data/lib/discorb/message_meta.rb +2 -3
- data/lib/discorb/modules.rb +3 -2
- data/lib/discorb/presence.rb +4 -2
- data/lib/discorb/reaction.rb +2 -2
- data/lib/discorb/role.rb +1 -1
- data/lib/discorb/sticker.rb +3 -3
- data/lib/discorb/user.rb +2 -2
- data/lib/discorb/voice_state.rb +5 -5
- data/lib/discorb/webhook.rb +15 -6
- data/lib/discorb.rb +2 -2
- data/rbs_collection.lock.yaml +88 -96
- data/rbs_collection.yaml +21 -17
- data/sig/async.rbs +11 -5
- data/sig/discorb/activity.rbs +23 -0
- data/sig/discorb/allowed_mentions.rbs +44 -0
- data/sig/discorb/app_command/base.rbs +282 -0
- data/sig/discorb/app_command/handler.rbs +171 -0
- data/sig/discorb/application.rbs +142 -0
- data/sig/discorb/asset.rbs +32 -0
- data/sig/discorb/attachment.rbs +91 -0
- data/sig/discorb/audit_log.rbs +231 -0
- data/sig/discorb/automod.rbs +128 -0
- data/sig/discorb/avatar.rbs +26 -0
- data/sig/discorb/channel/base.rbs +179 -0
- data/sig/discorb/channel/category.rbs +56 -0
- data/sig/discorb/channel/container.rbs +29 -0
- data/sig/discorb/channel/dm.rbs +14 -0
- data/sig/discorb/channel/news.rbs +20 -0
- data/sig/discorb/channel/stage.rbs +77 -0
- data/sig/discorb/channel/text.rbs +158 -0
- data/sig/discorb/channel/thread.rbs +185 -0
- data/sig/discorb/channel/voice.rbs +41 -0
- data/sig/discorb/client.rbs +2495 -0
- data/sig/discorb/color.rbs +142 -0
- data/sig/discorb/component/base.rbs +28 -0
- data/sig/discorb/component/button.rbs +65 -0
- data/sig/discorb/component/select_menu.rbs +107 -0
- data/sig/discorb/component/text_input.rbs +69 -0
- data/sig/discorb/connectable.rbs +8 -0
- data/sig/discorb/custom_emoji.rbs +90 -0
- data/sig/discorb/dictionary.rbs +85 -0
- data/sig/discorb/discord_model.rbs +15 -0
- data/sig/discorb/embed.rbs +279 -0
- data/sig/discorb/emoji.rbs +13 -0
- data/sig/discorb/error.rbs +73 -0
- data/sig/discorb/event_handler.rbs +27 -0
- data/sig/discorb/extension.rbs +1734 -0
- data/sig/discorb/flag.rbs +72 -0
- data/sig/discorb/gateway.rbs +481 -0
- data/sig/discorb/guild.rbs +870 -0
- data/sig/discorb/guild_template.rbs +174 -0
- data/sig/discorb/http.rbs +147 -0
- data/sig/discorb/image.rbs +20 -0
- data/sig/discorb/integration.rbs +118 -0
- data/sig/discorb/intents.rbs +97 -0
- data/sig/discorb/interaction/autocomplete.rbs +9 -0
- data/sig/discorb/interaction/base.rbs +66 -0
- data/sig/discorb/interaction/command.rbs +66 -0
- data/sig/discorb/interaction/message_component.rbs +140 -0
- data/sig/discorb/interaction/modal.rbs +50 -0
- data/sig/discorb/interaction/responder.rbs +157 -0
- data/sig/discorb/invite.rbs +86 -0
- data/sig/discorb/member.rbs +187 -0
- data/sig/discorb/message.rbs +469 -0
- data/sig/discorb/messageable.rbs +153 -0
- data/sig/discorb/partial_emoji.rbs +35 -0
- data/sig/discorb/permissions.rbs +149 -0
- data/sig/discorb/presence.rbs +237 -0
- data/sig/discorb/reaction.rbs +33 -0
- data/sig/discorb/role.rbs +145 -0
- data/sig/discorb/scheduled_event.rbs +148 -0
- data/sig/discorb/shard.rbs +62 -0
- data/sig/discorb/snowflake.rbs +56 -0
- data/sig/discorb/stage_instance.rbs +63 -0
- data/sig/discorb/sticker.rbs +116 -0
- data/sig/discorb/system_channel_flag.rbs +17 -0
- data/sig/discorb/unicode_emoji.rbs +49 -0
- data/sig/discorb/user.rbs +93 -0
- data/sig/discorb/utils.rbs +8 -0
- data/sig/discorb/voice_region.rbs +30 -0
- data/sig/discorb/voice_state.rbs +71 -0
- data/sig/discorb/webhook.rbs +327 -0
- data/sig/discorb/welcome_screen.rbs +78 -0
- data/sig/discorb.rbs +5 -8661
- data/sig/manifest.yaml +3 -0
- data/sig/override.rbs +19 -0
- metadata +80 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 117db5f0857b3da9f0c3a642da5c012b0e6b458aa61c2590b31df28540f04732
|
4
|
+
data.tar.gz: '08b41acb91e31536970e4a8545f7b29a656ea50fbc813eecde02463acff31cb1'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 511b7faf125d98e9da7120fe7a3dfae5f224dfcb4891e989cab8183db22ebd0f569685e3e7a7f00040d9ee539d5efaa5fa178f10a0137f79b155026944560a2e
|
7
|
+
data.tar.gz: 86ced549c50cc26a3a512964614587ff74690b67ed64810355fb307081407b87083151903febfe5f6fb634918365d88e1171af09070b1dbb838c5bcb0a31b9b5
|
data/.github/workflows/lint.yml
CHANGED
@@ -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,16 @@
|
|
4
4
|
|
5
5
|
# Changelog
|
6
6
|
|
7
|
+
## v0.18
|
8
|
+
|
9
|
+
### v0.18.0
|
10
|
+
|
11
|
+
- Change!: `XXX#fired_by` is now `XXX#user` or `XXX#member`.
|
12
|
+
- Change!: `Message#to_reference` returns `Message::Reference`.
|
13
|
+
- Change!: `TextChannel#default_auto_archive_duration` is now Integer.
|
14
|
+
- Add: Support AutoMod.
|
15
|
+
- Change: `discorb new` doesn't do initial commit.
|
16
|
+
|
7
17
|
## v0.17
|
8
18
|
|
9
19
|
### 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.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/Rakefile
CHANGED
@@ -232,106 +232,218 @@ namespace :document do
|
|
232
232
|
end
|
233
233
|
end
|
234
234
|
|
235
|
-
desc "Generate rbs file
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
#
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
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
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
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
|
-
base.gsub!(/ +$/m, "")
|
334
|
-
File.write("sig/discorb.rbs", base)
|
335
447
|
end
|
336
448
|
|
337
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
|
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
|
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
|
-
- [
|
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
|
-
|
102
|
-
require "dotenv"
|
101
|
+
# frozen_string_literal: true
|
103
102
|
|
104
|
-
|
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=
|
118
|
+
TOKEN=
|
119
119
|
```
|
120
120
|
|
121
|
-
|
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](
|
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
|
285
|
-
| after
|
284
|
+
| `before` | {Discorb::VoiceState} | The voice state before the update. |
|
285
|
+
| `after` | {Discorb::VoiceState} | The voice state after the update. |
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "discorb"
|
3
4
|
require "json"
|
4
5
|
|
@@ -22,25 +23,28 @@ client.once :standby do
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def bookmark_channel(guild)
|
25
|
-
guild.
|
26
|
+
guild.text_channels.find { |c| c.name == "bookmarks" }
|
26
27
|
end
|
27
28
|
|
28
29
|
def build_embed_from_message(message)
|
29
30
|
embed = Discorb::Embed.new
|
30
31
|
embed.description = message.content
|
31
|
-
embed.author = Discorb::Embed::Author.new(message.author.
|
32
|
+
embed.author = Discorb::Embed::Author.new(message.author.to_s, icon: message.author.avatar.url)
|
32
33
|
embed.timestamp = message.timestamp
|
33
34
|
embed.footer = Discorb::Embed::Footer.new("ID: #{message.id}")
|
34
35
|
embed
|
35
36
|
end
|
36
37
|
|
37
38
|
client.message_command({
|
38
|
-
|
39
|
-
|
40
|
-
}) do |interaction, message|
|
39
|
+
default: "Bookmark",
|
40
|
+
ja: "ブックマーク",
|
41
|
+
}) do |interaction, message|
|
42
|
+
next unless interaction.guild
|
43
|
+
|
41
44
|
unless channel = bookmark_channel(interaction.guild)
|
42
45
|
interaction.post(
|
43
|
-
localizations[:context_command][:not_found][interaction.locale] ||
|
46
|
+
localizations[:context_command][:not_found][interaction.locale] ||
|
47
|
+
localizations[:context_command][:not_found][:en],
|
44
48
|
ephemeral: true,
|
45
49
|
)
|
46
50
|
next
|
@@ -50,7 +54,8 @@ client.message_command({
|
|
50
54
|
embed: build_embed_from_message(message),
|
51
55
|
).wait
|
52
56
|
interaction.post(
|
53
|
-
localizations[:context_command][:done][interaction.locale] || localizations[:context_command][:done][:en],
|
57
|
+
localizations[:context_command][:done][interaction.locale] || localizations[:context_command][:done][:en],
|
58
|
+
ephemeral: true,
|
54
59
|
)
|
55
60
|
end
|
56
61
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "discorb"
|
3
4
|
|
4
5
|
client = Discorb::Client.new
|
@@ -9,7 +10,7 @@ end
|
|
9
10
|
|
10
11
|
client.slash(
|
11
12
|
"admin", "You can run this command if you have Administrator permission",
|
12
|
-
|
13
|
+
dm_permission: false,
|
13
14
|
default_permission: Discorb::Permission.from_keys(:administrator),
|
14
15
|
) do |interaction, _name|
|
15
16
|
interaction.post("Hello, admin!")
|