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
@@ -19,7 +19,7 @@ module Discorb
19
19
  attr_reader :created_at
20
20
  # @return [Time] The time this template was last updated.
21
21
  attr_reader :updated_at
22
- # @return [Discorb::Guild] The guild where the template was created.
22
+ # @return [Discorb::Snowflake] The ID of guild where the template was created.
23
23
  attr_reader :source_guild_id
24
24
  # @return [Discorb::GuildTemplate::TemplateGuild] The guild where the template was created.
25
25
  attr_reader :serialized_source_guild
@@ -64,7 +64,10 @@ module Discorb
64
64
  payload = {}
65
65
  payload[:name] = name if name
66
66
  payload[:description] = description if description != Discorb::Unset
67
- @client.http.request(Route.new("/guilds/#{@source_guild_id}/templates/#{@code}", "//guilds/:guild_id/templates/:code", :patch), payload).wait
67
+ @client.http.request(
68
+ Route.new("/guilds/#{@source_guild_id}/templates/#{@code}", "//guilds/:guild_id/templates/:code",
69
+ :patch), payload
70
+ ).wait
68
71
  end
69
72
  end
70
73
 
@@ -78,7 +81,8 @@ module Discorb
78
81
  #
79
82
  def update
80
83
  Async do
81
- _resp, data = @client.http.request(Route.new("/guilds/#{@source_guild_id}/templates/#{@code}", "//guilds/:guild_id/templates/:code", :put)).wait
84
+ _resp, data = @client.http.request(Route.new("/guilds/#{@source_guild_id}/templates/#{@code}",
85
+ "//guilds/:guild_id/templates/:code", :put)).wait
82
86
  _set_data(data)
83
87
  end
84
88
  end
@@ -91,7 +95,8 @@ module Discorb
91
95
  #
92
96
  def delete!
93
97
  Async do
94
- @client.http.request(Route.new("/guilds/#{@source_guild_id}/templates/#{@code}", "//guilds/:guild_id/templates/:code", :delete)).wait
98
+ @client.http.request(Route.new("/guilds/#{@source_guild_id}/templates/#{@code}",
99
+ "//guilds/:guild_id/templates/:code", :delete)).wait
95
100
  end
96
101
  end
97
102
 
@@ -109,7 +114,8 @@ module Discorb
109
114
  attr_reader :roles
110
115
  # @return [Discorb::SystemChannelFlag] The flag for the system channel.
111
116
  attr_reader :system_channel_flags
112
- # @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::GuildChannel}] A dictionary of channels in the guild.
117
+ # @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::GuildChannel}]
118
+ # A dictionary of channels in the guild.
113
119
  attr_reader :channels
114
120
  # @return [String] The description of the guild.
115
121
  attr_reader :description
data/lib/discorb/http.rb CHANGED
@@ -27,7 +27,6 @@ module Discorb
27
27
  #
28
28
  # @param [Discorb::Route] path The path to the resource.
29
29
  # @param [String, Hash] body The body of the request. Defaults to an empty string.
30
- # @param [Hash] headers The headers to send with the request.
31
30
  # @param [String] audit_log_reason The audit log reason to send with the request.
32
31
  # @param [Hash] kwargs The keyword arguments.
33
32
  #
@@ -36,17 +35,28 @@ module Discorb
36
35
  #
37
36
  # @raise [Discorb::HTTPError] The request was failed.
38
37
  #
39
- def request(path, body = "", headers: nil, audit_log_reason: nil, **kwargs)
38
+ def request(path, body = "", audit_log_reason: nil, **kwargs)
40
39
  Async do |_task|
41
40
  @ratelimit_handler.wait(path)
42
41
  resp = if %i[post patch put].include? path.method
43
- http.send(path.method, get_path(path), get_body(body), get_headers(headers, body, audit_log_reason), **kwargs)
42
+ http.send(
43
+ path.method,
44
+ get_path(path),
45
+ get_body(body),
46
+ get_headers(body, audit_log_reason),
47
+ **kwargs,
48
+ )
44
49
  else
45
- http.send(path.method, get_path(path), get_headers(headers, body, audit_log_reason), **kwargs)
50
+ http.send(
51
+ path.method,
52
+ get_path(path),
53
+ get_headers(body, audit_log_reason),
54
+ **kwargs,
55
+ )
46
56
  end
47
57
  data = get_response_data(resp)
48
58
  @ratelimit_handler.save(path, resp)
49
- handle_response(resp, data, path, body, headers, audit_log_reason, kwargs)
59
+ handle_response(resp, data, path, body, nil, audit_log_reason, kwargs)
50
60
  end
51
61
  end
52
62
 
@@ -56,8 +66,7 @@ module Discorb
56
66
  #
57
67
  # @param [Discorb::Route] path The path to the resource.
58
68
  # @param [String, Hash] body The body of the request.
59
- # @param [Array<Discorb::File>] files The files to upload.
60
- # @param [Hash] headers The headers to send with the request.
69
+ # @param [Array<Discorb::Attachment>] files The files to upload.
61
70
  # @param [String] audit_log_reason The audit log reason to send with the request.
62
71
  # @param [Hash] kwargs The keyword arguments.
63
72
  #
@@ -66,21 +75,30 @@ module Discorb
66
75
  #
67
76
  # @raise [Discorb::HTTPError] The request was failed.
68
77
  #
69
- def multipart_request(path, body, files, headers: nil, audit_log_reason: nil, **kwargs)
78
+ def multipart_request(path, body, files, audit_log_reason: nil, **kwargs)
70
79
  Async do |_task|
71
80
  @ratelimit_handler.wait(path)
72
- req = Net::HTTP.const_get(path.method.to_s.capitalize).new(get_path(path), get_headers(headers, body, audit_log_reason), **kwargs)
81
+ req = Net::HTTP.const_get(path.method.to_s.capitalize).new(
82
+ get_path(path),
83
+ get_headers(body, audit_log_reason),
84
+ **kwargs,
85
+ )
86
+ # @type var data: Array[untyped]
73
87
  data = [
74
88
  ["payload_json", get_body(body)],
75
89
  ]
76
90
  files&.each_with_index do |file, i|
77
91
  next if file.nil?
92
+
78
93
  if file.created_by == :discord
79
94
  request_io = StringIO.new(
80
- cdn_http.get(URI.parse(file.url).path, {
81
- "Content-Type" => nil,
82
- "User-Agent" => Discorb::USER_AGENT,
83
- }).body
95
+ cdn_http.get(
96
+ (URI.parse(file.url).path || raise("Could not parse url")),
97
+ {
98
+ "Content-Type" => nil,
99
+ "User-Agent" => Discorb::USER_AGENT,
100
+ }
101
+ ).body
84
102
  )
85
103
  data << ["files[#{i}]", request_io, { filename: file.filename, content_type: file.content_type }]
86
104
  else
@@ -91,10 +109,11 @@ module Discorb
91
109
  session = Net::HTTP.new("discord.com", 443)
92
110
  session.use_ssl = true
93
111
  resp = session.request(req)
94
- files&.then { _1.filter(&:will_close).each { |f| f.io.close } }
95
- data = get_response_data(resp)
112
+ resp_data = get_response_data(resp)
96
113
  @ratelimit_handler.save(path, resp)
97
- handle_response(resp, data, path, body, headers, audit_log_reason, kwargs)
114
+ response = handle_response(resp, resp_data, path, body, files, audit_log_reason, kwargs)
115
+ files&.then { _1.filter(&:will_close).each { |f| f.io.close } }
116
+ response
98
117
  end
99
118
  end
100
119
 
@@ -104,12 +123,16 @@ module Discorb
104
123
 
105
124
  private
106
125
 
107
- def handle_response(resp, data, path, body, headers, audit_log_reason, kwargs)
126
+ def handle_response(resp, data, path, body, files, audit_log_reason, kwargs)
108
127
  case resp.code
109
128
  when "429"
110
129
  @client.logger.info("Rate limit exceeded for #{path.method} #{path.url}, waiting #{data[:retry_after]} seconds")
111
130
  sleep(data[:retry_after])
112
- request(path, body, headers: headers, audit_log_reason: audit_log_reason, **kwargs).wait
131
+ if files
132
+ multipart_request(path, body, files, audit_log_reason: audit_log_reason, **kwargs).wait
133
+ else
134
+ request(path, body, audit_log_reason: audit_log_reason, **kwargs).wait
135
+ end
113
136
  when "400"
114
137
  raise BadRequestError.new(resp, data)
115
138
  when "401"
@@ -123,14 +146,19 @@ module Discorb
123
146
  end
124
147
  end
125
148
 
126
- def get_headers(headers, body = "", audit_log_reason = nil)
149
+ def get_headers(body = "", audit_log_reason = nil)
127
150
  ret = if body.nil? || body == ""
128
- { "User-Agent" => USER_AGENT, "authorization" => "Bot #{@client.token}" }
151
+ {
152
+ "User-Agent" => USER_AGENT,
153
+ "authorization" => "Bot #{@client.token}",
154
+ }
129
155
  else
130
- { "User-Agent" => USER_AGENT, "authorization" => "Bot #{@client.token}",
131
- "content-type" => "application/json" }
156
+ {
157
+ "User-Agent" => USER_AGENT,
158
+ "authorization" => "Bot #{@client.token}",
159
+ "content-type" => "application/json",
160
+ }
132
161
  end
133
- ret.merge!(headers) if !headers.nil? && headers.length.positive?
134
162
  ret["X-Audit-Log-Reason"] = audit_log_reason unless audit_log_reason.nil?
135
163
  ret
136
164
  end
@@ -160,12 +188,13 @@ module Discorb
160
188
  data = JSON.parse(resp.body, symbolize_names: true)
161
189
  rescue JSON::ParserError, TypeError
162
190
  data = if resp.body.nil? || resp.body.empty?
163
- nil
191
+ {}
164
192
  else
165
193
  resp.body
166
194
  end
167
195
  end
168
196
  raise CloudFlareBanError.new(resp, @client) if resp["Via"].nil? && resp.code == "429" && data.is_a?(String)
197
+
169
198
  data
170
199
  end
171
200
 
@@ -74,7 +74,10 @@ module Discorb
74
74
  #
75
75
  def delete!(reason: nil)
76
76
  Async do
77
- @client.http.request(Route.new("/guilds/#{@guild}/integrations/#{@id}", "//guilds/:guild_id/integrations/:integration_id", :delete), audit_log_reason: reason).wait
77
+ @client.http.request(
78
+ Route.new("/guilds/#{@guild}/integrations/#{@id}", "//guilds/:guild_id/integrations/:integration_id",
79
+ :delete), {}, audit_log_reason: reason
80
+ ).wait
78
81
  end
79
82
  end
80
83
 
@@ -23,6 +23,8 @@ module Discorb
23
23
  dm_typing: 1 << 14,
24
24
  message_content: 1 << 15,
25
25
  scheduled_events: 1 << 16,
26
+ automod_configuration: 1 << 20,
27
+ automod_execution: 1 << 21,
26
28
  }.freeze
27
29
 
28
30
  #
@@ -44,29 +46,34 @@ module Discorb
44
46
  # @param dm_typing [Boolean] Whether dm typing related events are enabled.
45
47
  # @param message_content [Boolean] Whether message content will be sent with events.
46
48
  # @param scheduled_events [Boolean] Whether events related scheduled events are enabled.
47
- #
49
+ # @param automod_configuration [Boolean] Whether automod configuration related events are enabled.
50
+ # @param automod_execution [Boolean] Whether automod execution related events are enabled.
48
51
  # @note You must enable privileged intents to use `members` and/or `presences` intents.
49
52
  # @note Message Content Intent is not required to use `message_content` intents for now,
50
- # this will be required in April 30, 2022. [Learn More](https://support-dev.discord.com/hc/en-us/articles/4404772028055).
53
+ # this will be required in September 1, 2022. [Learn More](https://support-dev.discord.com/hc/en-us/articles/4404772028055).
51
54
  # You should specify `message_content` intent for preventing unexpected changes in the future.
52
55
  #
53
- def initialize(guilds: true,
54
- members: false,
55
- bans: true,
56
- emojis: true,
57
- integrations: true,
58
- webhooks: true,
59
- invites: true,
60
- voice_states: true,
61
- presences: false,
62
- messages: true,
63
- reactions: true,
64
- typing: true,
65
- dm_messages: true,
66
- dm_reactions: true,
67
- dm_typing: true,
68
- message_content: nil,
69
- scheduled_events: true)
56
+ def initialize(
57
+ guilds: true,
58
+ members: false,
59
+ bans: true,
60
+ emojis: true,
61
+ integrations: true,
62
+ webhooks: true,
63
+ invites: true,
64
+ voice_states: true,
65
+ presences: false,
66
+ messages: true,
67
+ reactions: true,
68
+ typing: true,
69
+ dm_messages: true,
70
+ dm_reactions: true,
71
+ dm_typing: true,
72
+ message_content: nil,
73
+ scheduled_events: true,
74
+ automod_configuration: true,
75
+ automod_execution: true
76
+ )
70
77
  @raw_value = {
71
78
  guilds: guilds,
72
79
  members: members,
@@ -85,6 +92,8 @@ module Discorb
85
92
  dm_typing: dm_typing,
86
93
  message_content: message_content,
87
94
  scheduled_events: scheduled_events,
95
+ automod_configuration: automod_configuration,
96
+ automod_execution: automod_execution,
88
97
  }
89
98
  end
90
99
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Discorb
3
4
  #
4
5
  # Represents auto complete interaction.
@@ -12,35 +13,46 @@ module Discorb
12
13
  def _set_data(data)
13
14
  super
14
15
  Sync do
15
- name, options = Discorb::CommandInteraction::SlashCommand.get_command_data(data)
16
+ name, options = Discorb::CommandInteraction::ChatInputCommand.get_command_data(data)
16
17
 
17
- unless (command = @client.bottom_commands.find { |c| c.to_s == name && c.type_raw == 1 })
18
+ unless (command = @client.callable_commands.find { |c| c.to_s == name && c.type_raw == 1 })
18
19
  @client.logger.warn "Unknown command name #{name}, ignoring"
19
20
  next
20
21
  end
21
22
 
22
23
  option_map = command.options.to_h { |k, v| [k.to_s, v[:default]] }
23
- Discorb::CommandInteraction::SlashCommand.modify_option_map(option_map, options, guild, {}, {})
24
+ Discorb::CommandInteraction::ChatInputCommand.modify_option_map(option_map, options, guild, {}, {})
24
25
  focused_index = options.find_index { |o| o[:focused] }
25
- val = command.options.values.filter { |option| option[:type] != :attachment }[focused_index][:autocomplete]&.call(self, *command.options.map { |k, _v| option_map[k.to_s] })
26
+ val = command.options.values.filter do |option|
27
+ option[:type] != :attachment
28
+ end[focused_index][:autocomplete]&.call(self, *command.options.map do |k, _v|
29
+ option_map[k.to_s]
30
+ end)
26
31
  send_complete_result(val)
27
32
  end
28
33
  end
29
34
 
30
35
  def send_complete_result(val)
31
- @client.http.request(Route.new("/interactions/#{@id}/#{@token}/callback", "//interactions/:interaction_id/:token/callback", :post), {
32
- type: 8,
33
- data: {
34
- choices: val.map do |vk, vv|
35
- {
36
- name: vk,
37
- value: vv,
38
- }
39
- end,
40
- },
41
- }).wait
36
+ @client.http.request(
37
+ Route.new(
38
+ "/interactions/#{@id}/#{@token}/callback",
39
+ "//interactions/:interaction_id/:token/callback",
40
+ :post
41
+ ), {
42
+ type: 8,
43
+ data: {
44
+ choices: val.map do |vk, vv|
45
+ {
46
+ name: vk,
47
+ value: vv,
48
+ }
49
+ end,
50
+ },
51
+ }
52
+ ).wait
42
53
  rescue Discorb::NotFoundError
43
- @client.logger.warn "Failed to send auto complete result, This may be caused by the suggestion is taking too long (over 3 seconds) to respond", fallback: $stderr
54
+ @client.logger.warn "Failed to send auto complete result, " \
55
+ "This may be caused by the suggestion is taking too long (over 3 seconds) to respond"
44
56
  end
45
57
 
46
58
  class << self
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Discorb
3
4
  #
4
5
  # Represents a command interaction.
@@ -12,7 +13,7 @@ module Discorb
12
13
  #
13
14
  # Represents a slash command interaction.
14
15
  #
15
- class SlashCommand < CommandInteraction
16
+ class ChatInputCommand < CommandInteraction
16
17
  @command_type = 1
17
18
  @event_name = :slash_command
18
19
 
@@ -21,15 +22,15 @@ module Discorb
21
22
  def _set_data(data)
22
23
  super
23
24
 
24
- name, options = SlashCommand.get_command_data(data)
25
+ name, options = ChatInputCommand.get_command_data(data)
25
26
 
26
- unless (command = @client.bottom_commands.find { |c| c.to_s == name && c.type_raw == 1 })
27
+ unless (command = @client.callable_commands.find { |c| c.to_s == name && c.type_raw == 1 })
27
28
  @client.logger.warn "Unknown command name #{name}, ignoring"
28
29
  return
29
30
  end
30
31
 
31
32
  option_map = command.options.to_h { |k, v| [k.to_s, v[:default]] }
32
- SlashCommand.modify_option_map(option_map, options, guild, @members, @attachments)
33
+ ChatInputCommand.modify_option_map(option_map, options, guild, @members, @attachments)
33
34
 
34
35
  command.block.call(self, *command.options.map { |k, _v| option_map[k.to_s] })
35
36
  end
@@ -82,13 +83,25 @@ module Discorb
82
83
  when 3, 4, 5, 10
83
84
  option[:value]
84
85
  when 6
85
- members[option[:value]] || guild.members[option[:value]] || guild.fetch_member(option[:value]).wait
86
+ members[option[:value]] || guild && (guild.members[option[:value]] ||
87
+ guild.fetch_member(option[:value]).wait)
86
88
  when 7
87
- guild.channels[option[:value]] || guild.fetch_channels.wait.find { |channel| channel.id == option[:value] }
89
+ if guild
90
+ guild.channels[option[:value]] || guild.fetch_channels.wait.find do |channel|
91
+ channel.id == option[:value]
92
+ end
93
+ end
88
94
  when 8
89
- guild.roles[option[:value]] || guild.fetch_roles.wait.find { |role| role.id == option[:value] }
95
+ guild && (guild.roles[option[:value]] ||
96
+ guild.fetch_roles.wait.find { |role| role.id == option[:value] })
90
97
  when 9
91
- members[option[:value]] || guild.members[option[:value]] || guild.roles[option[:value]] || guild.fetch_member(option[:value]).wait || guild.fetch_roles.wait.find { |role| role.id == option[:value] }
98
+ members[option[:value]] ||
99
+ guild && (guild.members[option[:value]] ||
100
+ guild.roles[option[:value]] ||
101
+ guild.fetch_member(option[:value]).wait ||
102
+ guild.fetch_roles.wait.find do |role|
103
+ role.id == option[:value]
104
+ end)
92
105
  when 11
93
106
  attachments[option[:value]]
94
107
  end
@@ -112,8 +125,17 @@ module Discorb
112
125
 
113
126
  def _set_data(data)
114
127
  super
115
- @target = guild.members[data[:target_id]] || Discorb::Member.new(@client, @guild_id, data[:resolved][:users][data[:target_id].to_sym], data[:resolved][:members][data[:target_id].to_sym])
116
- @client.commands.find { |c| c.name == data[:name] && c.type_raw == 2 }.block.call(self, @target)
128
+ @target = guild.members[data[:target_id]] || Discorb::Member.new(
129
+ @client, @guild_id,
130
+ data[:resolved][:users][data[:target_id].to_sym],
131
+ data[:resolved][:members][data[:target_id].to_sym]
132
+ )
133
+ command = @client.commands.find { |c| c.name["default"] == data[:name] && c.type_raw == 2 }
134
+ if command
135
+ command.block.call(self, @target)
136
+ else
137
+ @client.logger.warn "Unknown command name #{data[:name]}, ignoring"
138
+ end
117
139
  end
118
140
  end
119
141
 
@@ -132,7 +154,12 @@ module Discorb
132
154
  def _set_data(data)
133
155
  super
134
156
  @target = @messages[data[:target_id]]
135
- @client.commands.find { |c| c.name == data[:name] && c.type_raw == 3 }.block.call(self, @target)
157
+ command = @client.commands.find { |c| c.name["default"] == data[:name] && c.type_raw == 3 }
158
+ if command
159
+ command.block.call(self, @target)
160
+ else
161
+ @client.logger.warn "Unknown command name #{data[:name]}, ignoring"
162
+ end
136
163
  end
137
164
  end
138
165
 
@@ -152,10 +179,11 @@ module Discorb
152
179
  @client, @guild_id, data[:resolved][:users][id], member
153
180
  )
154
181
  end
155
- data[:resolved][:messages]&.to_h do |id, _message|
156
- @messages[id.to_i] = Message.new(@client, data[:resolved][:messages][data[:target_id].to_sym].merge(guild_id: @guild_id.to_s)).merge(guild_id: @guild_id.to_s)
182
+
183
+ data[:resolved][:messages]&.each do |id, message|
184
+ @messages[id.to_s] = Message.new(@client, message.merge(guild_id: @guild_id.to_s))
157
185
  end
158
- data[:resolved][:attachments]&.to_h do |id, attachment|
186
+ data[:resolved][:attachments]&.each do |id, attachment|
159
187
  @attachments[id.to_s] = Attachment.new(attachment)
160
188
  end
161
189
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
- module Discorb
3
2
 
3
+ module Discorb
4
4
  #
5
5
  # Represents a message component interaction.
6
6
  # @abstract
@@ -41,7 +41,10 @@ module Discorb
41
41
  #
42
42
  def make_interaction(client, data)
43
43
  nested_classes.each do |klass|
44
- return klass.new(client, data) if !klass.component_type.nil? && klass.component_type == data[:data][:component_type]
44
+ if !klass.component_type.nil? && klass.component_type == data[:data][:component_type]
45
+ return klass.new(client,
46
+ data)
47
+ end
45
48
  end
46
49
  client.logger.warn("Unknown component type #{data[:component_type]}, initialized Interaction")
47
50
  MessageComponentInteraction.new(client, data)
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Discorb
4
-
5
4
  #
6
5
  # Represents a modal interaction.
7
6
  #