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
@@ -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.channels.find { |c| c.is_a?(Discorb::TextChannel) && c.name == "bookmarks" }
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.to_s_user, icon: message.author.avatar.url)
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
- default: "Bookmark",
39
- ja: "ブックマーク",
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] || localizations[:context_command][:not_found][:en],
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], ephemeral: true,
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
- dm: false,
13
+ dm_permission: false,
13
14
  default_permission: Discorb::Permission.from_keys(:administrator),
14
15
  ) do |interaction, _name|
15
16
  interaction.post("Hello, admin!")
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "discorb"
3
4
 
4
5
  client = Discorb::Client.new
@@ -16,27 +17,30 @@ client.once :standby do
16
17
  puts "Logged in as #{client.user}"
17
18
  end
18
19
 
19
- client.slash({
20
- default: "greet",
21
- ja: "挨拶",
22
- }, {
23
- default: "Bot greets. Cute OwO",
24
- ja: "Botが挨拶します。かわいいね",
25
- }, {
26
- "name" => {
27
- name_localizations: {
28
- ja: "名前",
29
- },
30
- description: {
31
- default: "The name to greet.",
32
- ja: "挨拶する人の名前。",
20
+ client.slash(
21
+ {
22
+ default: "greet",
23
+ ja: "挨拶",
24
+ }, {
25
+ default: "Bot greets. Cute OwO",
26
+ ja: "Botが挨拶します。かわいいね",
27
+ }, {
28
+ "name" => {
29
+ name_localizations: {
30
+ ja: "名前",
31
+ },
32
+ description: {
33
+ default: "The name to greet.",
34
+ ja: "挨拶する人の名前。",
35
+ },
36
+ type: :string,
37
+ optional: true,
33
38
  },
34
- type: :string,
35
- optional: true,
36
- },
37
- }) do |interaction, name|
39
+ }
40
+ ) do |interaction, name|
38
41
  interaction.post(
39
- format((localizations[:localized][:text][interaction.locale] || localizations[:localized][:text][:en]), name || interaction.target.to_s_user),
42
+ format((localizations[:localized][:text][interaction.locale] || localizations[:localized][:text][:en]),
43
+ name || interaction.user.to_s),
40
44
  ephemeral: true,
41
45
  )
42
46
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "discorb"
3
4
 
4
5
  localizations = {
@@ -24,26 +25,28 @@ client.once :standby do
24
25
  puts "Logged in as #{client.user}"
25
26
  end
26
27
 
27
- client.user_command({
28
- default: "info",
29
- ja: "詳細",
30
- }) do |interaction|
28
+ client.user_command(
29
+ {
30
+ default: "info",
31
+ ja: "詳細",
32
+ }
33
+ ) do |interaction, user|
31
34
  field_name = localizations[:info][:fields][interaction.locale] || localizations[:info][:fields][:en]
32
35
  interaction.post(
33
36
  embed: Discorb::Embed.new(
34
- format((localizations[:info][:title][interaction.locale] || localizations[:info][:title][:en]), interaction.target.to_s_user),
37
+ format((localizations[:info][:title][interaction.locale] || localizations[:info][:title][:en]),
38
+ user.to_s),
35
39
  fields: [
36
- Discorb::Embed::Field.new(field_name[0], interaction.target.to_s_user),
37
- Discorb::Embed::Field.new(field_name[1], interaction.target.id),
40
+ Discorb::Embed::Field.new(field_name[0], user.to_s),
41
+ Discorb::Embed::Field.new(field_name[1], user.id),
38
42
  Discorb::Embed::Field.new(
39
43
  field_name[2],
40
- (localizations[:info][:yn][interaction.locale] || localizations[:info][:yn][:en])[interaction.target.bot? ? 0 : 1]
44
+ (localizations[:info][:yn][locale] || localizations[:info][:yn][:en])[user.bot? ? 0 : 1]
41
45
  ),
42
- Discorb::Embed::Field.new(field_name[3], interaction.target.joined_at.to_df("F")),
43
- Discorb::Embed::Field.new(field_name[4], interaction.target.created_at.to_df("F")),
46
+ Discorb::Embed::Field.new(field_name[3], user.joined_at.to_df("F")),
47
+ Discorb::Embed::Field.new(field_name[4], user.created_at.to_df("F")),
44
48
  ],
45
- thumbnail: interaction.target.avatar&.url,
46
-
49
+ thumbnail: user.avatar&.url,
47
50
  ), ephemeral: true,
48
51
  )
49
52
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "discorb"
3
4
 
4
5
  client = Discorb::Client.new
@@ -36,7 +37,7 @@ end
36
37
  client.on :button_click do |response|
37
38
  if response.custom_id.start_with?("auth:")
38
39
  id = response.custom_id.delete_prefix("auth:")
39
- response.fired_by.add_role(id).wait
40
+ response.user.add_role(id).wait
40
41
  response.post("You got your role!\nHere's your role: <@&#{id}>", ephemeral: true)
41
42
  end
42
43
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "discorb"
3
4
 
4
5
  client = Discorb::Client.new
@@ -41,7 +42,9 @@ client.on :message do |message|
41
42
  next if message.author.bot?
42
43
  next unless message.content == "!ruby"
43
44
 
44
- options = SECTIONS.map.with_index { |section, i| Discorb::SelectMenu::Option.new("Page #{i + 1}", "sections:#{i}", description: section[0]) }
45
+ options = SECTIONS.map.with_index do |section, i|
46
+ Discorb::SelectMenu::Option.new("Page #{i + 1}", "sections:#{i}", description: section[0])
47
+ end
45
48
  message.channel.post(
46
49
  "Select a section", components: [Discorb::SelectMenu.new("sections", options)],
47
50
  )
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "discorb"
3
4
  require_relative "message_expander"
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "discorb"
3
4
 
4
5
  #
@@ -0,0 +1,5 @@
1
+ class Object
2
+ def build_embed_from_message: (Discorb::Message message) -> Discorb::Embed
3
+
4
+ def bookmark_channel: (Discorb::Guild guild) -> Discorb::TextChannel?
5
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "discorb"
3
4
 
4
5
  client = Discorb::Client.new
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "discorb"
3
4
 
4
5
  client = Discorb::Client.new
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "discorb"
3
4
  intents = Discorb::Intents.new
4
5
  intents.members = true
6
+
5
7
  client = Discorb::Client.new(intents: intents)
6
8
 
7
9
  def convert_role(guild, string)
@@ -15,6 +17,8 @@ client.once :standby do
15
17
  end
16
18
 
17
19
  client.on :reaction_add do |event|
20
+ next unless event.guild
21
+ next unless event.member
18
22
  next unless event.emoji.value.end_with?(0x0000fe0f.chr("utf-8") + 0x000020e3.chr("utf-8"))
19
23
  next if event.member.bot?
20
24
 
@@ -31,6 +35,7 @@ end
31
35
 
32
36
  client.on :reaction_remove do |event|
33
37
  next unless event.emoji.value.end_with?(0x0000fe0f.chr("utf-8") + 0x000020e3.chr("utf-8"))
38
+ next unless event.member
34
39
  next if event.member.bot?
35
40
 
36
41
  msg = event.fetch_message.wait
@@ -49,15 +54,21 @@ client.on :message do |message|
49
54
  next if message.author.bot?
50
55
 
51
56
  message.reply("Too many roles.") if message.content.split.length > 10
52
- roles = message.content.delete_prefix("/rp ").split.map.with_index { |raw_role, index| [index, convert_role(message.guild, raw_role), raw_role] }
57
+ roles = message.content.delete_prefix("/rp ").split.map.with_index do |raw_role, index|
58
+ [index, convert_role(message.guild, raw_role), raw_role]
59
+ end
53
60
  if (convert_fails = roles.filter { |r| r[1].nil? }).length.positive?
54
61
  message.reply("#{convert_fails.map { |r| r[2] }.join(", ")} is not a role.")
55
62
  next
56
63
  end
57
- rp_msg = message.channel.post(embed: Discorb::Embed.new(
58
- "Role panel",
59
- roles.map.with_index(1) { |r, index| "#{index}\ufe0f\u20e3#{r[1].mention}" }.join("\n")
60
- )).wait
64
+ rp_msg = message.channel.post(
65
+ embed: Discorb::Embed.new(
66
+ "Role panel",
67
+ roles.map.with_index(1) do |r, index|
68
+ "#{index}\ufe0f\u20e3#{r[1].mention}"
69
+ end.join("\n")
70
+ ),
71
+ ).wait
61
72
  1.upto(roles.length).each do |i|
62
73
  rp_msg.add_reaction(Discorb::UnicodeEmoji["#{i}\ufe0f\u20e3"]).wait
63
74
  end
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "discorb"
3
4
 
4
- client = Discorb::Client.new(log: Logger.new($stdout))
5
+ client = Discorb::Client.new(logger: Logger.new($stderr))
5
6
 
6
7
  client.once :standby do
7
8
  puts "Logged in as #{client.user}"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "discorb"
3
4
 
4
5
  client = Discorb::Client.new
@@ -12,6 +13,8 @@ client.on :message do |message|
12
13
  next unless message.content == "!quiz"
13
14
 
14
15
  operator = %i[+ - *].sample
16
+ next unless operator
17
+
15
18
  num1 = rand(1..10)
16
19
  num2 = rand(1..10)
17
20
 
data/exe/discorb CHANGED
@@ -40,8 +40,8 @@ require "bundler/setup" if options[:bundler]
40
40
 
41
41
  command = ARGV.shift
42
42
 
43
- begin
44
- require "discorb/exe/#{command}"
45
- rescue LoadError
43
+ unless $LOAD_PATH.resolve_feature_path("discorb/exe/#{command}.rb")
46
44
  warn "Unknown subcommand: #{command}"
45
+ abort
47
46
  end
47
+ require "discorb/exe/#{command}"
@@ -23,7 +23,7 @@ module Discorb
23
23
  # @param [Boolean] replied_user Whether to ping the user that sent the message to reply.
24
24
  #
25
25
  def initialize(everyone: nil, roles: nil, users: nil, replied_user: nil)
26
- @everyone = everyone
26
+ @everyone = !everyone.nil?
27
27
  @roles = roles
28
28
  @users = users
29
29
  @replied_user = replied_user
@@ -7,7 +7,7 @@ module Discorb
7
7
  # @abstract
8
8
  #
9
9
  class Command < DiscordModel
10
- # @return [Hash{Symbol => String}] The name of the command.
10
+ # @return [Hash{String => String}] The name of the command.
11
11
  attr_reader :name
12
12
  # @return [Array<#to_s>] The guild ids that the command is enabled in.
13
13
  attr_reader :guild_ids
@@ -35,13 +35,13 @@ module Discorb
35
35
  # @private
36
36
  #
37
37
  # @param [String, Hash{Symbol => String}] name The name of the command.
38
- # @param [Array<#to_s>] guild_ids The guild ids that the command is enabled in.
38
+ # @param [Array<#to_s>, false, nil] guild_ids The guild ids that the command is enabled in.
39
39
  # @param [Proc] block The block of the command.
40
- # @param [:chat_input, :user, :message] type The type of the command.
40
+ # @param [Integer] type The type of the command.
41
41
  # @param [Boolean] dm_permission Whether the command is enabled in DMs.
42
42
  # @param [Discorb::Permission] default_permission The default permission of the command.
43
43
  #
44
- def initialize(name, guild_ids, block, type, dm_permission = nil, default_permission = nil)
44
+ def initialize(name, guild_ids, block, type, dm_permission = true, default_permission = nil) # rubocop:disable Style/OptionalBooleanParameter
45
45
  @name = name.is_a?(String) ? { "default" => name } : ApplicationCommand.modify_localization_hash(name)
46
46
  @guild_ids = guild_ids&.map(&:to_s)
47
47
  @block = block
@@ -100,7 +100,7 @@ module Discorb
100
100
  # @param [Hash{String => Hash}] options The options of the command.
101
101
  # @param [Array<#to_s>] guild_ids The guild ids that the command is enabled in.
102
102
  # @param [Proc] block The block of the command.
103
- # @param [:chat_input, :user, :message] type The type of the command.
103
+ # @param [Integer] type The type of the command.
104
104
  # @param [Discorb::ApplicationCommand::Command, nil] parent The parent command.
105
105
  # @param [Boolean] dm_permission Whether the command is enabled in DMs.
106
106
  # @param [Discorb::Permission] default_permission The default permission of the command.
@@ -195,6 +195,10 @@ module Discorb
195
195
  ret[:min_value] = value[:range].begin
196
196
  ret[:max_value] = value[:range].end
197
197
  end
198
+ if value[:length]
199
+ ret[:min_length] = value[:length].begin
200
+ ret[:max_length] = value[:length].end
201
+ end
198
202
  ret
199
203
  end
200
204
  {
@@ -213,12 +217,9 @@ module Discorb
213
217
  # Represents the command with subcommands.
214
218
  #
215
219
  class GroupCommand < Command
216
- # @return [Array<
217
- # Discorb::ApplicationCommand::Command::ChatInputCommand,
218
- # Discorb::ApplicationCommand::Command::SubcommandGroup
219
- # >] The subcommands of the command.
220
+ # @return [Array<Discorb::ApplicationCommand::Command>] The subcommands of the command.
220
221
  attr_reader :commands
221
- # @return [String] The description of the command.
222
+ # @return [Hash{String => String}] The description of the command.
222
223
  attr_reader :description
223
224
 
224
225
  #
@@ -228,13 +229,12 @@ module Discorb
228
229
  # @param [String, Hash{Symbol => String}] name The name of the command.
229
230
  # @param [String, Hash{Symbol => String}] description The description of the command.
230
231
  # @param [Array<#to_s>] guild_ids The guild ids that the command is enabled in.
231
- # @param [:chat_input, :user, :message] type The type of the command.
232
232
  # @param [Discorb::Client] client The client of the command.
233
233
  # @param [Boolean] dm_permission Whether the command is enabled in DMs.
234
234
  # @param [Discorb::Permission] default_permission The default permission of the command.
235
235
  #
236
- def initialize(name, description, guild_ids, type, client, dm_permission, default_permission)
237
- super(name, guild_ids, block, type, dm_permission, default_permission)
236
+ def initialize(name, description, guild_ids, client, dm_permission, default_permission)
237
+ super(name, guild_ids, block, 1, dm_permission, default_permission)
238
238
  @description = if description.is_a?(String)
239
239
  {
240
240
  "default" => description,
@@ -282,9 +282,9 @@ module Discorb
282
282
  #
283
283
  # @see file:docs/application_command.md Application Commands
284
284
  #
285
- def group(command_name, description, &block)
286
- command = Discorb::ApplicationCommand::Command::SubcommandGroup.new(command_name, description, @name, @client)
287
- command.then(&block) if block_given?
285
+ def group(command_name, description)
286
+ command = Discorb::ApplicationCommand::Command::SubcommandGroup.new(command_name, description, self, @client)
287
+ yield command if block_given?
288
288
  @commands << command
289
289
  command
290
290
  end
@@ -368,7 +368,7 @@ module Discorb
368
368
  # @param [Discorb::ApplicationCommand::Command::GroupCommand] parent The parent command.
369
369
  # @param [Discorb::Client] client The client.
370
370
  def initialize(name, description, parent, client)
371
- super(name, description, [], 1, client, nil, nil)
371
+ super(name, description, [], client, nil, nil)
372
372
 
373
373
  @commands = []
374
374
  @parent = parent
@@ -6,6 +6,8 @@ module Discorb
6
6
  # Module to handle application commands.
7
7
  #
8
8
  module Handler
9
+ # @type instance: Discorb::Client
10
+
9
11
  #
10
12
  # Add new top-level command.
11
13
  #
@@ -21,6 +23,7 @@ module Discorb
21
23
  #
22
24
  # | Key | Type | Description |
23
25
  # | --- | --- | --- |
26
+ # | `:name_localizations` | Hash{Symbol => String} | Localizations of option name. |
24
27
  # | `:description` | `String` \| `Hash{Symbol => String}` |
25
28
  # Description of the option. If hash is passed, it must be a pair of Language code and description,
26
29
  # and `:default` key is required. You can use `_` instead of `-` in language code. |
@@ -36,6 +39,7 @@ module Discorb
36
39
  # | `:channel_types` | `Array<Class<Discorb::Channel>>` | Type of the channel option. |
37
40
  # | `:autocomplete` | `Proc` | Autocomplete function. |
38
41
  # | `:range` | `Range` | Range of the option. Only valid for numeric options. (`:int`, `:float`) |
42
+ # | `:length` | `Range` | Range of length of the option. Only valid for `:string`. |
39
43
  #
40
44
  # @param [Array<#to_s>, false, nil] guild_ids
41
45
  # Guild IDs to set the command to. `false` to global command, `nil` to use default.
@@ -95,14 +99,20 @@ module Discorb
95
99
  # @see file:docs/application_command.md Application Commands
96
100
  # @see file:docs/cli/setup.md CLI: setup
97
101
  #
98
- def slash_group(command_name, description, guild_ids: nil, dm_permission: true, default_permission: nil, &block)
102
+ def slash_group(command_name, description, guild_ids: nil, dm_permission: true, default_permission: nil)
99
103
  command_name = { default: command_name } if command_name.is_a?(String)
100
104
  description = { default: description } if description.is_a?(String)
101
105
  command_name = ApplicationCommand.modify_localization_hash(command_name)
102
106
  description = ApplicationCommand.modify_localization_hash(description)
103
- command = Discorb::ApplicationCommand::Command::GroupCommand.new(command_name, description, guild_ids, nil,
104
- self, dm_permission, default_permission)
105
- command.then(&block) if block_given?
107
+ command = Discorb::ApplicationCommand::Command::GroupCommand.new(
108
+ command_name,
109
+ description,
110
+ guild_ids,
111
+ self,
112
+ dm_permission,
113
+ default_permission
114
+ )
115
+ yield command if block_given?
106
116
  @commands << command
107
117
  command
108
118
  end
@@ -125,8 +135,14 @@ module Discorb
125
135
  def message_command(command_name, guild_ids: nil, dm_permission: true, default_permission: nil, &block)
126
136
  command_name = { default: command_name } if command_name.is_a?(String)
127
137
  command_name = ApplicationCommand.modify_localization_hash(command_name)
128
- command = Discorb::ApplicationCommand::Command.new(command_name, guild_ids, block, 3, dm_permission,
129
- default_permission)
138
+ command = Discorb::ApplicationCommand::Command.new(
139
+ command_name,
140
+ guild_ids,
141
+ block,
142
+ 3,
143
+ dm_permission,
144
+ default_permission
145
+ )
130
146
  @commands << command
131
147
  command
132
148
  end
@@ -105,10 +105,11 @@ module Discorb
105
105
  # * `:thread_create`
106
106
  # * `:thread_update`
107
107
  # * `:thread_delete`
108
+ # * `:application_command_permission_update``
108
109
  attr_reader :type
109
110
  # @return [Discorb::AuditLog::Entry::Changes] The changes in this entry.
110
111
  attr_reader :changes
111
- # @return [Discorb::Channel, Discorb::Role, Discorb::Member, Discorb::Guild, Discorb::Message]
112
+ # @return [Discorb::Channel, Discorb::Role, Discorb::Member, Discorb::Guild, Discorb::Message, Discorb::Snowflake]
112
113
  # The target of the entry.
113
114
  attr_reader :target
114
115
  # @return [Hash{Symbol => Object}] The optional data for this entry.
@@ -170,6 +171,11 @@ module Discorb
170
171
  110 => :thread_create,
171
172
  111 => :thread_update,
172
173
  112 => :thread_delete,
174
+ 121 => :application_command_permission_update,
175
+ 140 => :automod_rule_create,
176
+ 141 => :automod_rule_update,
177
+ 142 => :automod_rule_delete,
178
+ 143 => :automod_block_message,
173
179
  }.freeze
174
180
 
175
181
  #
@@ -195,14 +201,14 @@ module Discorb
195
201
  @id = Snowflake.new(data[:id])
196
202
  @user_id = Snowflake.new(data[:user_id])
197
203
  @target_id = Snowflake.new(data[:target_id])
198
- @type = EVENTS[data[:action_type]]
204
+ @type = EVENTS[data[:action_type]] || :unknown
199
205
  @target = CONVERTERS[@type.to_s.split("_")[0].to_sym]&.call(client, @target_id, @gui)
200
206
  @target ||= Snowflake.new(data[:target_id])
201
207
  @changes = data[:changes] && Changes.new(data[:changes])
202
208
  @reason = data[:reason]
203
209
  data[:options]&.each do |option, value|
204
210
  define_singleton_method(option) { value }
205
- if option.end_with?("_id")
211
+ if option.end_with?("_id") && CONVERTERS.key?(option.to_s.split("_")[0].to_sym)
206
212
  define_singleton_method(option.to_s.sub("_id", "")) do
207
213
  CONVERTERS[option.to_s.split("_")[0].to_sym]&.call(client, value, @guild_id)
208
214
  end