discorb 0.13.0 → 0.13.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build_main.yml +1 -0
  3. data/.github/workflows/build_version.yml +4 -3
  4. data/.github/workflows/crowdin.yml +32 -0
  5. data/.gitignore +3 -1
  6. data/.yardopts +2 -0
  7. data/CODE_OF_CONDUCT.md +128 -0
  8. data/Changelog.md +420 -388
  9. data/Gemfile +5 -1
  10. data/README.md +2 -2
  11. data/Rakefile +131 -1
  12. data/crowdin.yml +2 -0
  13. data/discorb.gemspec +12 -1
  14. data/docs/Examples.md +2 -0
  15. data/docs/application_command.md +7 -5
  16. data/docs/cli/irb.md +2 -0
  17. data/docs/cli/new.md +2 -0
  18. data/docs/cli/run.md +3 -1
  19. data/docs/cli/setup.md +4 -2
  20. data/docs/cli.md +2 -0
  21. data/docs/events.md +6 -4
  22. data/docs/extension.md +2 -2
  23. data/docs/faq.md +4 -2
  24. data/docs/license.md +2 -0
  25. data/docs/tutorial.md +4 -3
  26. data/docs/voice_events.md +2 -0
  27. data/lib/discorb/app_command.rb +32 -9
  28. data/lib/discorb/application.rb +1 -1
  29. data/lib/discorb/asset.rb +1 -1
  30. data/lib/discorb/channel.rb +170 -125
  31. data/lib/discorb/client.rb +20 -22
  32. data/lib/discorb/common.rb +32 -1
  33. data/lib/discorb/dictionary.rb +10 -2
  34. data/lib/discorb/emoji.rb +7 -9
  35. data/lib/discorb/emoji_table.rb +3891 -3891
  36. data/lib/discorb/event.rb +12 -11
  37. data/lib/discorb/exe/show.rb +2 -0
  38. data/lib/discorb/extension.rb +1 -1
  39. data/lib/discorb/flag.rb +1 -1
  40. data/lib/discorb/gateway.rb +63 -17
  41. data/lib/discorb/guild.rb +110 -156
  42. data/lib/discorb/guild_template.rb +15 -12
  43. data/lib/discorb/http.rb +41 -136
  44. data/lib/discorb/integration.rb +34 -2
  45. data/lib/discorb/interaction/autocomplete.rb +1 -1
  46. data/lib/discorb/interaction/response.rb +34 -32
  47. data/lib/discorb/interaction/root.rb +8 -0
  48. data/lib/discorb/invite.rb +4 -3
  49. data/lib/discorb/log.rb +3 -2
  50. data/lib/discorb/member.rb +44 -15
  51. data/lib/discorb/message.rb +33 -22
  52. data/lib/discorb/modules.rb +28 -35
  53. data/lib/discorb/presence.rb +2 -2
  54. data/lib/discorb/rate_limit.rb +14 -18
  55. data/lib/discorb/role.rb +18 -14
  56. data/lib/discorb/sticker.rb +10 -14
  57. data/lib/discorb/user.rb +10 -10
  58. data/lib/discorb/voice_state.rb +12 -7
  59. data/lib/discorb/webhook.rb +44 -50
  60. data/lib/discorb.rb +1 -1
  61. data/po/yard.pot +7772 -5154
  62. data/sig/discorb.rbs +3316 -3819
  63. data/template-replace/scripts/locale_ja.rb +62 -0
  64. metadata +18 -5
@@ -45,19 +45,20 @@ module Discorb
45
45
 
46
46
  #
47
47
  # Edit the template.
48
- # @macro async
49
- # @macro http
48
+ # @async
50
49
  # @macro edit
51
50
  #
52
51
  # @param [String] name The new name of the template.
53
52
  # @param [String] description The new description of the template.
54
53
  #
55
- def edit(name = nil, description = :unset)
54
+ # @return [Async::Task<void>] The task.
55
+ #
56
+ def edit(name = nil, description = Discorb::Unset)
56
57
  Async do
57
58
  payload = {}
58
59
  payload[:name] = name if name
59
- payload[:description] = description if description != :unset
60
- @client.http.patch("/guilds/#{@source_guild_id}/templates/#{@code}", payload).wait
60
+ payload[:description] = description if description != Discorb::Unset
61
+ @client.http.request(Route.new("/guilds/#{@source_guild_id}/templates/#{@code}", "//guilds/:guild_id/templates/:code", :patch), payload).wait
61
62
  end
62
63
  end
63
64
 
@@ -65,24 +66,26 @@ module Discorb
65
66
 
66
67
  #
67
68
  # Update the template.
68
- # @macro async
69
- # @macro http
69
+ # @async
70
+ #
71
+ # @return [Async::Task<void>] The task.
70
72
  #
71
73
  def update
72
74
  Async do
73
- _resp, data = @client.http.put("/guilds/#{@source_guild_id}/templates/#{@code}").wait
75
+ _resp, data = @client.http.request(Route.new("/guilds/#{@source_guild_id}/templates/#{@code}", "//guilds/:guild_id/templates/:code", :put)).wait
74
76
  _set_data(data)
75
77
  end
76
78
  end
77
79
 
78
80
  #
79
81
  # Delete the template.
80
- # @macro async
81
- # @macro http
82
+ # @async
83
+ #
84
+ # @return [Async::Task<void>] The task.
82
85
  #
83
86
  def delete!
84
87
  Async do
85
- @client.http.delete("/guilds/#{@source_guild_id}/templates/#{@code}").wait
88
+ @client.http.request(Route.new("/guilds/#{@source_guild_id}/templates/#{@code}", "//guilds/:guild_id/templates/:code", :delete)).wait
86
89
  end
87
90
  end
88
91
 
@@ -98,7 +101,7 @@ module Discorb
98
101
  attr_reader :afk_timeout
99
102
  # @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::Role}] A dictionary of roles in the guild.
100
103
  attr_reader :roles
101
- # @return [Discorb::Guild::SystemChannelFlag] The flag for the system channel.
104
+ # @return [Discorb::SystemChannelFlag] The flag for the system channel.
102
105
  attr_reader :system_channel_flags
103
106
  # @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::GuildChannel}] A dictionary of channels in the guild.
104
107
  attr_reader :channels
data/lib/discorb/http.rb CHANGED
@@ -17,125 +17,68 @@ module Discorb
17
17
  end
18
18
 
19
19
  #
20
- # Execute a GET request.
21
- # @macro async
20
+ # Execute a request.
21
+ # @async
22
22
  #
23
- # @param [String] path The path to the resource.
23
+ # @param [Discorb::Route] path The path to the resource.
24
+ # @param [String, Hash] body The body of the request. Defaults to an empty string.
24
25
  # @param [Hash] headers The headers to send with the request.
25
26
  # @param [String] audit_log_reason The audit log reason to send with the request.
26
27
  # @param [Hash] kwargs The keyword arguments.
27
28
  #
28
- # @return [Array(Net::HTTPResponse, Hash)] The response and as JSON.
29
+ # @return [Async::Task<Array(Net::HTTPResponse, Hash)>] The response and as JSON.
29
30
  # @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
30
31
  #
31
32
  # @raise [Discorb::HTTPError] The request was failed.
32
33
  #
33
- def get(path, headers: nil, audit_log_reason: nil, **kwargs)
34
+ def request(path, body = "", headers: nil, audit_log_reason: nil, **kwargs)
34
35
  Async do |task|
35
- @ratelimit_handler.wait("GET", path)
36
- resp = http.get(get_path(path), get_headers(headers, "", audit_log_reason), **kwargs)
37
- data = get_response_data(resp)
38
- @ratelimit_handler.save("GET", path, resp)
39
- handle_response(:patch, resp, data, path, nil, headers, audit_log_reason, kwargs)
40
- end
41
- end
42
-
43
- #
44
- # Execute a POST request.
45
- # @macro async
46
- #
47
- # @param [String] path The path to the resource.
48
- # @param [String, Hash] body The body of the request.
49
- # @param [Hash] headers The headers to send with the request.
50
- # @param [String] audit_log_reason The audit log reason to send with the request.
51
- # @param [Hash] kwargs The keyword arguments.
52
- #
53
- # @return [Array(Net::HTTPResponse, Hash)] The response and as JSON.
54
- # @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
55
- #
56
- # @raise [Discorb::HTTPError] The request was failed.
57
- #
58
- def post(path, body = "", headers: nil, audit_log_reason: nil, **kwargs)
59
- Async do |task|
60
- @ratelimit_handler.wait("POST", path)
61
- resp = http.post(get_path(path), get_body(body), get_headers(headers, body, audit_log_reason), **kwargs)
62
- data = get_response_data(resp)
63
- @ratelimit_handler.save("POST", path, resp)
64
- handle_response(:post, resp, data, path, body, headers, audit_log_reason, kwargs)
65
- end
66
- end
67
-
68
- #
69
- # Execute a PATCH request.
70
- # @macro async
71
- #
72
- # @param [String] path The path to the resource.
73
- # @param [String, Hash] body The body of the request.
74
- # @param [Hash] headers The headers to send with the request.
75
- # @param [String] audit_log_reason The audit log reason to send with the request.
76
- # @param [Hash] kwargs The keyword arguments.
77
- #
78
- # @return [Array(Net::HTTPResponse, Hash)] The response and as JSON.
79
- # @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
80
- #
81
- # @raise [Discorb::HTTPError] The request was failed.
82
- #
83
- def patch(path, body = "", headers: nil, audit_log_reason: nil, **kwargs)
84
- Async do |task|
85
- @ratelimit_handler.wait("PATCH", path)
86
- resp = http.patch(get_path(path), get_body(body), get_headers(headers, body, audit_log_reason), **kwargs)
36
+ @ratelimit_handler.wait(path)
37
+ if %i[post patch put].include? path.method
38
+ resp = http.send(path.method, get_path(path), get_body(body), get_headers(headers, body, audit_log_reason), **kwargs)
39
+ else
40
+ resp = http.send(path.method, get_path(path), get_headers(headers, body, audit_log_reason), **kwargs)
41
+ end
87
42
  data = get_response_data(resp)
88
- @ratelimit_handler.save("PATCH", path, resp)
89
- handle_response(:patch, resp, data, path, body, headers, audit_log_reason, kwargs)
43
+ @ratelimit_handler.save(path, resp)
44
+ handle_response(resp, data, path, body, headers, audit_log_reason, kwargs)
90
45
  end
91
46
  end
92
47
 
93
48
  #
94
- # Execute a PUT request.
95
- # @macro async
49
+ # Execute a multipart request.
50
+ # @async
96
51
  #
97
- # @param [String] path The path to the resource.
52
+ # @param [Discorb::Route] path The path to the resource.
98
53
  # @param [String, Hash] body The body of the request.
54
+ # @param [Array<Discorb::File>] files The files to upload.
99
55
  # @param [Hash] headers The headers to send with the request.
100
56
  # @param [String] audit_log_reason The audit log reason to send with the request.
101
57
  # @param [Hash] kwargs The keyword arguments.
102
58
  #
103
- # @return [Array(Net::HTTPResponse, Hash)] The response and as JSON.
59
+ # @return [Async::Task<Array(Net::HTTPResponse, Hash)>] The response and as JSON.
104
60
  # @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
105
61
  #
106
62
  # @raise [Discorb::HTTPError] The request was failed.
107
63
  #
108
- def put(path, body = "", headers: nil, audit_log_reason: nil, **kwargs)
64
+ def multipart_request(path, body = "", files, headers: nil, audit_log_reason: nil, **kwargs)
109
65
  Async do |task|
110
- @ratelimit_handler.wait("PUT", path)
111
- resp = http.put(get_path(path), get_body(body), get_headers(headers, body, audit_log_reason), **kwargs)
112
- data = get_response_data(resp)
113
- @ratelimit_handler.save("PUT", path, resp)
114
- handle_response(:put, resp, data, path, body, headers, audit_log_reason, kwargs)
115
- end
116
- end
117
-
118
- #
119
- # Execute a DELETE request.
120
- # @macro async
121
- #
122
- # @param [String] path The path to the resource.
123
- # @param [Hash] headers The headers to send with the request.
124
- # @param [String] audit_log_reason The audit log reason to send with the request.
125
- # @param [Hash] kwargs The keyword arguments.
126
- #
127
- # @return [Array(Net::HTTPResponse, Hash)] The response and as JSON.
128
- # @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
129
- #
130
- # @raise [Discorb::HTTPError] The request was failed.
131
- #
132
- def delete(path, headers: nil, audit_log_reason: nil, **kwargs)
133
- Async do
134
- @ratelimit_handler.wait("DELETE", path)
135
- resp = http.delete(get_path(path), get_headers(headers, "", audit_log_reason))
66
+ @ratelimit_handler.wait(path)
67
+ req = Net::HTTP.const_get(path.method.to_s.capitalize).new(get_path(path), get_headers(headers, body, audit_log_reason), **kwargs)
68
+ data = [
69
+ ["payload_json", get_body(body)],
70
+ ]
71
+ files&.each_with_index do |file, i|
72
+ next if file.nil?
73
+ data << ["files[#{i}]", file.io, { filename: file.filename, content_type: file.content_type }]
74
+ end
75
+ req.set_form(data, "multipart/form-data")
76
+ session = Net::HTTP.new("discord.com", 443)
77
+ session.use_ssl = true
78
+ resp = session.request(req)
136
79
  data = get_response_data(resp)
137
- @ratelimit_handler.save("DELETE", path, resp)
138
- handle_response(:delete, resp, data, path, nil, headers, audit_log_reason, kwargs)
80
+ @ratelimit_handler.save(path, resp)
81
+ handle_response(resp, data, path, body, headers, audit_log_reason, kwargs)
139
82
  end
140
83
  end
141
84
 
@@ -143,52 +86,14 @@ module Discorb
143
86
  "#<#{self.class} client=#{@client}>"
144
87
  end
145
88
 
146
- #
147
- # A helper method to send multipart/form-data requests for creating messages.
148
- #
149
- # @param [Hash] payload The payload to send.
150
- # @param [Array<Discorb::File>] files The files to send.
151
- #
152
- # @return [Array(String, String)] The boundary and body.
153
- #
154
- def self.multipart(payload, files)
155
- boundary = "DiscorbBySevenC7CMultipartFormData#{Time.now.to_f}"
156
- str_payloads = [<<~HTTP]
157
- Content-Disposition: form-data; name="payload_json"
158
- Content-Type: application/json
159
-
160
- #{payload.to_json}
161
- HTTP
162
- files.each_with_index do |single_file, i|
163
- str_payloads << <<~HTTP
164
- Content-Disposition: form-data; name="files[#{i}]"; filename="#{single_file.filename}"
165
- Content-Type: #{single_file.content_type}
166
-
167
- #{single_file.io.read}
168
- HTTP
169
- end
170
- payload = +"--#{boundary}".encode(Encoding::ASCII_8BIT)
171
- str_payloads.each do |str_payload|
172
- payload << "\r\n".encode(Encoding::ASCII_8BIT)
173
- payload << str_payload.force_encoding(Encoding::ASCII_8BIT)
174
- payload << "\r\n--#{boundary}".encode(Encoding::ASCII_8BIT)
175
- end
176
- payload += +"--".encode(Encoding::ASCII_8BIT)
177
- [boundary, payload]
178
- end
179
-
180
89
  private
181
90
 
182
- def handle_response(method, resp, data, path, body, headers, audit_log_reason, kwargs)
91
+ def handle_response(resp, data, path, body, headers, audit_log_reason, kwargs)
183
92
  case resp.code
184
93
  when "429"
185
- @client.log.info("Rate limit exceeded for #{method} #{path}, waiting #{data[:retry_after]} seconds")
94
+ @client.log.info("Rate limit exceeded for #{path.method} #{path.url}, waiting #{data[:retry_after]} seconds")
186
95
  sleep(data[:retry_after])
187
- if body
188
- __send__(method, path, body, headers: headers, audit_log_reason: audit_log_reason, **kwargs).wait
189
- else
190
- __send__(method, path, headers: headers, audit_log_reason: audit_log_reason, **kwargs).wait
191
- end
96
+ request(path, body, headers: headers, audit_log_reason: audit_log_reason, **kwargs).wait
192
97
  when "400"
193
98
  raise BadRequestError.new(resp, data)
194
99
  when "401"
@@ -225,10 +130,10 @@ module Discorb
225
130
  end
226
131
 
227
132
  def get_path(path)
228
- full_path = if path.start_with?("https://")
229
- path
133
+ full_path = if path.url.start_with?("https://")
134
+ path.url
230
135
  else
231
- API_BASE_URL + path
136
+ API_BASE_URL + path.url
232
137
  end
233
138
  uri = URI(full_path)
234
139
  full_path.sub(uri.scheme + "://" + uri.host, "")
@@ -49,7 +49,6 @@ module Discorb
49
49
  @data = data
50
50
  @guild_id = guild_id
51
51
  _set_data(data)
52
- guild.integrations[@id] = self unless no_cache
53
52
  end
54
53
 
55
54
  def guild
@@ -58,12 +57,15 @@ module Discorb
58
57
 
59
58
  #
60
59
  # Delete the integration.
60
+ # @async
61
61
  #
62
62
  # @param [String] reason The reason for deleting the integration.
63
63
  #
64
+ # @return [Async::Task<void>] The task.
65
+ #
64
66
  def delete!(reason: nil)
65
67
  Async do
66
- @client.http.delete("/guilds/#{@guild}/integrations/#{@id}", audit_log_reason: reason).wait
68
+ @client.http.request(Route.new("/guilds/#{@guild}/integrations/#{@id}", "//guilds/:guild_id/integrations/:integration_id", :delete), audit_log_reason: reason).wait
67
69
  end
68
70
  end
69
71
 
@@ -107,5 +109,35 @@ module Discorb
107
109
  @name = data[:name]
108
110
  end
109
111
  end
112
+
113
+ #
114
+ # Represents an application for an integration.
115
+ #
116
+ class Application < DiscordModel
117
+ # @return [Discorb::Snowflake] The ID of the application.
118
+ attr_reader :id
119
+ # @return [String] The name of the application.
120
+ attr_reader :name
121
+ # @return [Asset] The icon of the application.
122
+ # @return [nil] If the application has no icon.
123
+ attr_reader :icon
124
+ # @return [String] The description of the application.
125
+ attr_reader :description
126
+ # @return [String] The summary of the application.
127
+ attr_reader :summary
128
+ # @return [Discorb::User] The bot user associated with the application.
129
+ # @return [nil] If the application has no bot user.
130
+ attr_reader :bot
131
+
132
+ # @private
133
+ def initialize(client, data)
134
+ @id = Snowflake.new(data[:id])
135
+ @name = data[:name]
136
+ @icon = data[:icon] && Asset.new(self, data[:icon])
137
+ @description = data[:description]
138
+ @summary = data[:summary]
139
+ @bot = data[:bot] and client.users[data[:bot][:id]] || Discorb::User.new(client, data[:bot])
140
+ end
141
+ end
110
142
  end
111
143
  end
@@ -27,7 +27,7 @@ module Discorb
27
27
 
28
28
  # @private
29
29
  def send_complete_result(val)
30
- @client.http.post("/interactions/#{@id}/#{@token}/callback", {
30
+ @client.http.request(Route.new("/interactions/#{@id}/#{@token}/callback", "//interactions/:interaction_id/:token/callback", :post), {
31
31
  type: 8,
32
32
  data: {
33
33
  choices: val.map do |vk, vv|
@@ -7,14 +7,15 @@ module Discorb
7
7
  #
8
8
  # Response with `DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE`(`5`).
9
9
  #
10
- # @macro async
11
- # @macro http
10
+ # @async
12
11
  #
13
12
  # @param [Boolean] ephemeral Whether to make the response ephemeral.
14
13
  #
14
+ # @return [Async::Task<void>] The task.
15
+ #
15
16
  def defer_source(ephemeral: false)
16
17
  Async do
17
- @client.http.post("/interactions/#{@id}/#{@token}/callback", {
18
+ @client.http.request(Route.new("/interactions/#{@id}/#{@token}/callback", "//interactions/:interaction_id/:token/callback", :post), {
18
19
  type: 5,
19
20
  data: {
20
21
  flags: (ephemeral ? 1 << 6 : 0),
@@ -27,8 +28,7 @@ module Discorb
27
28
  #
28
29
  # Response with `CHANNEL_MESSAGE_WITH_SOURCE`(`4`).
29
30
  #
30
- # @macro async
31
- # @macro http
31
+ # @async
32
32
  #
33
33
  # @param [String] content The content of the response.
34
34
  # @param [Boolean] tts Whether to send the message as text-to-speech.
@@ -51,14 +51,14 @@ module Discorb
51
51
  payload[:flags] = (ephemeral ? 1 << 6 : 0)
52
52
 
53
53
  ret = if @responded
54
- _resp, data = @client.http.post("/webhooks/#{@application_id}/#{@token}", payload).wait
54
+ _resp, data = @client.http.request(Route.new("/webhooks/#{@application_id}/#{@token}", "//webhooks/:webhook_id/:token", :post), payload).wait
55
55
  webhook = Webhook::URLWebhook.new("/webhooks/#{@application_id}/#{@token}")
56
56
  Webhook::Message.new(webhook, data, @client)
57
57
  elsif @defered
58
- @client.http.patch("/webhooks/#{@application_id}/#{@token}/messages/@original", payload).wait
58
+ @client.http.request(Route.new("/webhooks/#{@application_id}/#{@token}/messages/@original", "//webhooks/:webhook_id/:token/messages/@original", :patch), payload).wait
59
59
  CallbackMessage.new(@client, payload, @application_id, @token)
60
60
  else
61
- @client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 4, data: payload }).wait
61
+ @client.http.request(Route.new("/interactions/#{@id}/#{@token}/callback", "//interactions/:interaction_id/:token/callback", :post), { type: 4, data: payload }).wait
62
62
  CallbackMessage.new(@client, payload, @application_id, @token)
63
63
  end
64
64
  @responded = true
@@ -77,8 +77,7 @@ module Discorb
77
77
 
78
78
  #
79
79
  # Edits the callback message.
80
- # @macro async
81
- # @macro http
80
+ # @async
82
81
  # @macro edit
83
82
  #
84
83
  # @param [String] content The new content of the message.
@@ -88,27 +87,23 @@ module Discorb
88
87
  # @param [Discorb::File] file The file to send.
89
88
  # @param [Array<Discorb::File>] files The files to send.
90
89
  #
90
+ # @return [Async::Task<void>] The task.
91
+ #
91
92
  def edit(
92
- content = :unset,
93
- embed: :unset, embeds: :unset,
94
- file: :unset, files: :unset,
95
- attachments: :unset
93
+ content = Discorb::Unset,
94
+ embed: Discorb::Unset, embeds: Discorb::Unset,
95
+ file: Discorb::Unset, files: Discorb::Unset,
96
+ attachments: Discorb::Unset
96
97
  )
97
98
  Async do
98
99
  payload = {}
99
- payload[:content] = content if content != :unset
100
- payload[:embeds] = embed ? [embed.to_hash] : [] if embed != :unset
101
- payload[:embeds] = embeds.map(&:to_hash) if embeds != :unset
102
- payload[:attachments] = attachments.map(&:to_hash) if attachments != :unset
103
- files = [file] if file != :unset
104
- if files == :unset
105
- headers = {
106
- "Content-Type" => "application/json",
107
- }
108
- else
109
- headers, payload = HTTP.multipart(payload, files)
110
- end
111
- @client.http.patch("/webhooks/#{@application_id}/#{@token}/messages/@original", payload, headers: headers).wait
100
+ payload[:content] = content if content != Discorb::Unset
101
+ payload[:embeds] = embed ? [embed.to_hash] : [] if embed != Discorb::Unset
102
+ payload[:embeds] = embeds.map(&:to_hash) if embeds != Discorb::Unset
103
+ payload[:attachments] = attachments.map(&:to_hash) if attachments != Discorb::Unset
104
+ files = [file] if file != Discorb::Unset
105
+ files = [] if files == Discorb::Unset
106
+ @client.http.multipart_request(Route.new("/webhooks/#{@application_id}/#{@token}/messages/@original", "//webhooks/:webhook_id/:token/messages/@original", :patch), payload, files, headers: headers).wait
112
107
  end
113
108
  end
114
109
 
@@ -116,11 +111,14 @@ module Discorb
116
111
 
117
112
  #
118
113
  # Deletes the callback message.
114
+ # @async
119
115
  # @note This will fail if the message is ephemeral.
120
116
  #
117
+ # @return [Async::Task<void>] The task.
118
+ #
121
119
  def delete!
122
120
  Async do
123
- @client.http.delete("/webhooks/#{@application_id}/#{@token}/messages/@original").wait
121
+ @client.http.request(Route.new("/webhooks/#{@application_id}/#{@token}/messages/@original", "//webhooks/:webhook_id/:token/messages/@original", :delete)).wait
124
122
  end
125
123
  end
126
124
  end
@@ -132,12 +130,15 @@ module Discorb
132
130
  module UpdateResponse
133
131
  #
134
132
  # Response with `DEFERRED_UPDATE_MESSAGE`(`6`).
133
+ # @async
135
134
  #
136
135
  # @param [Boolean] ephemeral Whether to make the response ephemeral.
137
136
  #
137
+ # @return [Async::Task<void>] The task.
138
+ #
138
139
  def defer_update(ephemeral: false)
139
140
  Async do
140
- @client.http.post("/interactions/#{@id}/#{@token}/callback", {
141
+ @client.http.request(Route.new("/interactions/#{@id}/#{@token}/callback", "//interactions/:interaction_id/:token/callback", :post), {
141
142
  type: 6,
142
143
  data: {
143
144
  flags: (ephemeral ? 1 << 6 : 0),
@@ -149,8 +150,7 @@ module Discorb
149
150
  #
150
151
  # Response with `UPDATE_MESSAGE`(`7`).
151
152
  #
152
- # @macro async
153
- # @macro http
153
+ # @async
154
154
  #
155
155
  # @param [String] content The content of the response.
156
156
  # @param [Boolean] tts Whether to send the message as text-to-speech.
@@ -160,6 +160,8 @@ module Discorb
160
160
  # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
161
161
  # @param [Boolean] ephemeral Whether to make the response ephemeral.
162
162
  #
163
+ # @return [Async::Task<void>] The task.
164
+ #
163
165
  def edit(content, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false)
164
166
  Async do
165
167
  payload = {}
@@ -174,7 +176,7 @@ module Discorb
174
176
  payload[:allowed_mentions] = allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
175
177
  payload[:components] = Component.to_payload(components) if components
176
178
  payload[:flags] = (ephemeral ? 1 << 6 : 0)
177
- @client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 7, data: payload }).wait
179
+ @client.http.request(Route.new("/interactions/#{@id}/#{@token}/callback", "//interactions/:interaction_id/:token/callback", :post), { type: 7, data: payload }).wait
178
180
  end
179
181
  end
180
182
  end
@@ -18,6 +18,12 @@ module Discorb
18
18
  attr_reader :version
19
19
  # @return [String] The token for the interaction.
20
20
  attr_reader :token
21
+ # @return [Symbol] The locale of the user that created the interaction.
22
+ # @note This modifies the language code, `-` will be replaced with `_`.
23
+ attr_reader :locale
24
+ # @return [Symbol] The locale of the guild that created the interaction.
25
+ # @note This modifies the language code, `-` will be replaced with `_`.
26
+ attr_reader :guild_locale
21
27
 
22
28
  # @!attribute [r] guild
23
29
  # @macro client_cache
@@ -43,6 +49,8 @@ module Discorb
43
49
  @member = guild.members[data[:member][:id]] || Member.new(@client, @guild_id, data[:member][:user], data[:member]) if data[:member]
44
50
  @user = @client.users[data[:user][:id]] || User.new(@client, data[:user]) if data[:user]
45
51
  @token = data[:token]
52
+ @locale = data[:locale].to_s.gsub("-", "_").to_sym
53
+ @guild_locale = data[:guild_locale].to_s.gsub("-", "_").to_sym
46
54
  @version = data[:version]
47
55
  @defered = false
48
56
  @responded = false
@@ -100,11 +100,12 @@ module Discorb
100
100
  end
101
101
 
102
102
  # Delete the invite.
103
- # @macro async
104
- # @macro http
103
+ # @async
104
+ # @return [Async::Task<void>] The task.
105
+ #
105
106
  def delete!(reason: nil)
106
107
  Async do
107
- @client.http.delete("/invites/#{@code}", audit_log_reason: reason)
108
+ @client.http.request(Route.new("/invites/#{@code}", "//invites/:code", :delete), audit_log_reason: reason)
108
109
  end
109
110
  end
110
111
 
data/lib/discorb/log.rb CHANGED
@@ -71,10 +71,11 @@ module Discorb
71
71
 
72
72
  time = Time.now.iso8601
73
73
  if @colorize_log
74
- @out.puts("\e[90m#{time}\e[0m #{color}#{name.ljust(5)}\e[0m #{message}")
74
+ @out.write("\e[90m#{time}\e[0m #{color}#{name.ljust(5)}\e[0m #{message}\n")
75
75
  else
76
- @out.puts("#{time} #{name.ljust(5)} #{message}")
76
+ @out.write("#{time} #{name.ljust(5)} #{message}\n")
77
77
  end
78
+ @out.flush
78
79
  end
79
80
  end
80
81
  end