discorb 0.13.0 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build_main.yml +1 -0
- data/.github/workflows/build_version.yml +1 -0
- data/.github/workflows/crowdin.yml +32 -0
- data/.gitignore +3 -1
- data/.yardopts +2 -0
- data/Changelog.md +399 -388
- data/Gemfile +5 -1
- data/README.md +1 -1
- data/Rakefile +139 -9
- data/crowdin.yml +2 -0
- data/docs/Examples.md +2 -0
- data/docs/application_command.md +7 -5
- data/docs/cli/irb.md +2 -0
- data/docs/cli/new.md +2 -0
- data/docs/cli/run.md +3 -1
- data/docs/cli/setup.md +4 -2
- data/docs/cli.md +2 -0
- data/docs/events.md +6 -4
- data/docs/extension.md +2 -2
- data/docs/faq.md +4 -2
- data/docs/license.md +2 -0
- data/docs/tutorial.md +4 -3
- data/docs/voice_events.md +2 -0
- data/lib/discorb/app_command.rb +8 -7
- data/lib/discorb/application.rb +1 -1
- data/lib/discorb/channel.rb +100 -76
- data/lib/discorb/client.rb +13 -15
- data/lib/discorb/common.rb +3 -1
- data/lib/discorb/emoji.rb +5 -7
- data/lib/discorb/emoji_table.rb +3891 -3891
- data/lib/discorb/event.rb +8 -7
- data/lib/discorb/exe/show.rb +2 -0
- data/lib/discorb/extension.rb +1 -1
- data/lib/discorb/flag.rb +1 -1
- data/lib/discorb/gateway.rb +9 -13
- data/lib/discorb/guild.rb +63 -89
- data/lib/discorb/guild_template.rb +12 -9
- data/lib/discorb/http.rb +82 -44
- data/lib/discorb/integration.rb +3 -0
- data/lib/discorb/interaction/response.rb +27 -25
- data/lib/discorb/interaction/root.rb +8 -0
- data/lib/discorb/invite.rb +3 -2
- data/lib/discorb/member.rb +41 -12
- data/lib/discorb/message.rb +28 -17
- data/lib/discorb/modules.rb +19 -26
- data/lib/discorb/role.rb +15 -11
- data/lib/discorb/sticker.rb +8 -12
- data/lib/discorb/user.rb +7 -7
- data/lib/discorb/voice_state.rb +8 -5
- data/lib/discorb/webhook.rb +38 -47
- data/lib/discorb.rb +1 -1
- data/po/yard.pot +7772 -5154
- data/sig/discorb.rbs +3316 -3819
- data/template-replace/scripts/locale_ja.rb +62 -0
- metadata +5 -3
data/lib/discorb/http.rb
CHANGED
@@ -18,14 +18,14 @@ module Discorb
|
|
18
18
|
|
19
19
|
#
|
20
20
|
# Execute a GET request.
|
21
|
-
# @
|
21
|
+
# @async
|
22
22
|
#
|
23
23
|
# @param [String] path The path to the resource.
|
24
24
|
# @param [Hash] headers The headers to send with the request.
|
25
25
|
# @param [String] audit_log_reason The audit log reason to send with the request.
|
26
26
|
# @param [Hash] kwargs The keyword arguments.
|
27
27
|
#
|
28
|
-
# @return [Array(Net::HTTPResponse, Hash)] The response and as JSON.
|
28
|
+
# @return [Async::Task<Array(Net::HTTPResponse, Hash)>] The response and as JSON.
|
29
29
|
# @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
|
30
30
|
#
|
31
31
|
# @raise [Discorb::HTTPError] The request was failed.
|
@@ -42,7 +42,7 @@ module Discorb
|
|
42
42
|
|
43
43
|
#
|
44
44
|
# Execute a POST request.
|
45
|
-
# @
|
45
|
+
# @async
|
46
46
|
#
|
47
47
|
# @param [String] path The path to the resource.
|
48
48
|
# @param [String, Hash] body The body of the request.
|
@@ -50,7 +50,7 @@ module Discorb
|
|
50
50
|
# @param [String] audit_log_reason The audit log reason to send with the request.
|
51
51
|
# @param [Hash] kwargs The keyword arguments.
|
52
52
|
#
|
53
|
-
# @return [Array(Net::HTTPResponse, Hash)] The response and as JSON.
|
53
|
+
# @return [Async::Task<Array(Net::HTTPResponse, Hash)>] The response and as JSON.
|
54
54
|
# @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
|
55
55
|
#
|
56
56
|
# @raise [Discorb::HTTPError] The request was failed.
|
@@ -65,9 +65,46 @@ module Discorb
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
#
|
69
|
+
# Execute a multipart POST request.
|
70
|
+
# @async
|
71
|
+
#
|
72
|
+
# @param [String] path The path to the resource.
|
73
|
+
# @param [String, Hash] body The body of the request.
|
74
|
+
# @param [Array<Discorb::File>] files The files to upload.
|
75
|
+
# @param [Hash] headers The headers to send with the request.
|
76
|
+
# @param [String] audit_log_reason The audit log reason to send with the request.
|
77
|
+
# @param [Hash] kwargs The keyword arguments.
|
78
|
+
#
|
79
|
+
# @return [Async::Task<Array(Net::HTTPResponse, Hash)>] The response and as JSON.
|
80
|
+
# @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
|
81
|
+
#
|
82
|
+
# @raise [Discorb::HTTPError] The request was failed.
|
83
|
+
#
|
84
|
+
def multipart_post(path, body = "", files, headers: nil, audit_log_reason: nil, **kwargs)
|
85
|
+
Async do |task|
|
86
|
+
@ratelimit_handler.wait("POST", path)
|
87
|
+
req = Net::HTTP::Post.new(get_path(path), get_headers(headers, body, audit_log_reason), **kwargs)
|
88
|
+
data = [
|
89
|
+
["payload_json", get_body(body)],
|
90
|
+
]
|
91
|
+
files&.each_with_index do |file, i|
|
92
|
+
next if file.nil?
|
93
|
+
data << ["files[#{i}]", file.io, { filename: file.filename, content_type: file.content_type }]
|
94
|
+
end
|
95
|
+
req.set_form(data, "multipart/form-data")
|
96
|
+
session = Net::HTTP.new("discord.com", 443)
|
97
|
+
session.use_ssl = true
|
98
|
+
resp = session.request(req)
|
99
|
+
data = get_response_data(resp)
|
100
|
+
@ratelimit_handler.save("POST", path, resp)
|
101
|
+
handle_response(:post, resp, data, path, body, headers, audit_log_reason, kwargs)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
68
105
|
#
|
69
106
|
# Execute a PATCH request.
|
70
|
-
# @
|
107
|
+
# @async
|
71
108
|
#
|
72
109
|
# @param [String] path The path to the resource.
|
73
110
|
# @param [String, Hash] body The body of the request.
|
@@ -75,7 +112,7 @@ module Discorb
|
|
75
112
|
# @param [String] audit_log_reason The audit log reason to send with the request.
|
76
113
|
# @param [Hash] kwargs The keyword arguments.
|
77
114
|
#
|
78
|
-
# @return [Array(Net::HTTPResponse, Hash)] The response and as JSON.
|
115
|
+
# @return [Async::Task<Array(Net::HTTPResponse, Hash)>] The response and as JSON.
|
79
116
|
# @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
|
80
117
|
#
|
81
118
|
# @raise [Discorb::HTTPError] The request was failed.
|
@@ -90,9 +127,44 @@ module Discorb
|
|
90
127
|
end
|
91
128
|
end
|
92
129
|
|
130
|
+
#
|
131
|
+
# Execute a PATCH request.
|
132
|
+
# @async
|
133
|
+
#
|
134
|
+
# @param [String] path The path to the resource.
|
135
|
+
# @param [String, Hash] body The body of the request.
|
136
|
+
# @param [Hash] headers The headers to send with the request.
|
137
|
+
# @param [String] audit_log_reason The audit log reason to send with the request.
|
138
|
+
# @param [Hash] kwargs The keyword arguments.
|
139
|
+
#
|
140
|
+
# @return [Async::Task<Array(Net::HTTPResponse, Hash)>] The response and as JSON.
|
141
|
+
# @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
|
142
|
+
#
|
143
|
+
# @raise [Discorb::HTTPError] The request was failed.
|
144
|
+
#
|
145
|
+
def multipart_patch(path, body = "", headers: nil, audit_log_reason: nil, **kwargs)
|
146
|
+
Async do |task|
|
147
|
+
@ratelimit_handler.wait("PATCH", path)
|
148
|
+
req = Net::HTTP::Patch.new(get_path(path), get_headers(headers, body, audit_log_reason), **kwargs)
|
149
|
+
data = [
|
150
|
+
["payload_json", get_body(body)],
|
151
|
+
]
|
152
|
+
files&.each_with_index do |file, i|
|
153
|
+
data << ["files[#{i}]", file.io, { filename: file.filename, content_type: file.content_type }]
|
154
|
+
end
|
155
|
+
req.set_form(data, "multipart/form-data")
|
156
|
+
session = Net::HTTP.new("discord.com", 443)
|
157
|
+
session.use_ssl = true
|
158
|
+
resp = session.request(req)
|
159
|
+
data = get_response_data(resp)
|
160
|
+
@ratelimit_handler.save("PATCH", path, resp)
|
161
|
+
handle_response(:patch, resp, data, path, body, headers, audit_log_reason, kwargs)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
93
165
|
#
|
94
166
|
# Execute a PUT request.
|
95
|
-
# @
|
167
|
+
# @async
|
96
168
|
#
|
97
169
|
# @param [String] path The path to the resource.
|
98
170
|
# @param [String, Hash] body The body of the request.
|
@@ -100,7 +172,7 @@ module Discorb
|
|
100
172
|
# @param [String] audit_log_reason The audit log reason to send with the request.
|
101
173
|
# @param [Hash] kwargs The keyword arguments.
|
102
174
|
#
|
103
|
-
# @return [Array(Net::HTTPResponse, Hash)] The response and as JSON.
|
175
|
+
# @return [Async::Task<Array(Net::HTTPResponse, Hash)>] The response and as JSON.
|
104
176
|
# @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
|
105
177
|
#
|
106
178
|
# @raise [Discorb::HTTPError] The request was failed.
|
@@ -117,14 +189,14 @@ module Discorb
|
|
117
189
|
|
118
190
|
#
|
119
191
|
# Execute a DELETE request.
|
120
|
-
# @
|
192
|
+
# @async
|
121
193
|
#
|
122
194
|
# @param [String] path The path to the resource.
|
123
195
|
# @param [Hash] headers The headers to send with the request.
|
124
196
|
# @param [String] audit_log_reason The audit log reason to send with the request.
|
125
197
|
# @param [Hash] kwargs The keyword arguments.
|
126
198
|
#
|
127
|
-
# @return [Array(Net::HTTPResponse, Hash)] The response and as JSON.
|
199
|
+
# @return [Async::Task<Array(Net::HTTPResponse, Hash)>] The response and as JSON.
|
128
200
|
# @return [Async::Task<Array(Net::HTTPResponse, nil)>] The response was 204.
|
129
201
|
#
|
130
202
|
# @raise [Discorb::HTTPError] The request was failed.
|
@@ -143,40 +215,6 @@ module Discorb
|
|
143
215
|
"#<#{self.class} client=#{@client}>"
|
144
216
|
end
|
145
217
|
|
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
218
|
private
|
181
219
|
|
182
220
|
def handle_response(method, resp, data, path, body, headers, audit_log_reason, kwargs)
|
data/lib/discorb/integration.rb
CHANGED
@@ -58,9 +58,12 @@ module Discorb
|
|
58
58
|
|
59
59
|
#
|
60
60
|
# Delete the integration.
|
61
|
+
# @async
|
61
62
|
#
|
62
63
|
# @param [String] reason The reason for deleting the integration.
|
63
64
|
#
|
65
|
+
# @return [Async::Task<void>] The task.
|
66
|
+
#
|
64
67
|
def delete!(reason: nil)
|
65
68
|
Async do
|
66
69
|
@client.http.delete("/guilds/#{@guild}/integrations/#{@id}", audit_log_reason: reason).wait
|
@@ -7,11 +7,12 @@ module Discorb
|
|
7
7
|
#
|
8
8
|
# Response with `DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE`(`5`).
|
9
9
|
#
|
10
|
-
# @
|
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
18
|
@client.http.post("/interactions/#{@id}/#{@token}/callback", {
|
@@ -27,8 +28,7 @@ module Discorb
|
|
27
28
|
#
|
28
29
|
# Response with `CHANNEL_MESSAGE_WITH_SOURCE`(`4`).
|
29
30
|
#
|
30
|
-
# @
|
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.
|
@@ -77,8 +77,7 @@ module Discorb
|
|
77
77
|
|
78
78
|
#
|
79
79
|
# Edits the callback message.
|
80
|
-
# @
|
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 =
|
93
|
-
embed:
|
94
|
-
file:
|
95
|
-
attachments:
|
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 !=
|
100
|
-
payload[:embeds] = embed ? [embed.to_hash] : [] if embed !=
|
101
|
-
payload[:embeds] = embeds.map(&:to_hash) if embeds !=
|
102
|
-
payload[:attachments] = attachments.map(&:to_hash) if attachments !=
|
103
|
-
files = [file] if file !=
|
104
|
-
if files ==
|
105
|
-
|
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_patch("/webhooks/#{@application_id}/#{@token}/messages/@original", payload, files, headers: headers).wait
|
112
107
|
end
|
113
108
|
end
|
114
109
|
|
@@ -116,8 +111,11 @@ 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
121
|
@client.http.delete("/webhooks/#{@application_id}/#{@token}/messages/@original").wait
|
@@ -132,9 +130,12 @@ 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
141
|
@client.http.post("/interactions/#{@id}/#{@token}/callback", {
|
@@ -149,8 +150,7 @@ module Discorb
|
|
149
150
|
#
|
150
151
|
# Response with `UPDATE_MESSAGE`(`7`).
|
151
152
|
#
|
152
|
-
# @
|
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 = {}
|
@@ -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
|
data/lib/discorb/invite.rb
CHANGED
@@ -100,8 +100,9 @@ module Discorb
|
|
100
100
|
end
|
101
101
|
|
102
102
|
# Delete the invite.
|
103
|
-
# @
|
104
|
-
# @
|
103
|
+
# @async
|
104
|
+
# @return [Async::Task<void>] The task.
|
105
|
+
#
|
105
106
|
def delete!(reason: nil)
|
106
107
|
Async do
|
107
108
|
@client.http.delete("/invites/#{@code}", audit_log_reason: reason)
|
data/lib/discorb/member.rb
CHANGED
@@ -143,12 +143,13 @@ module Discorb
|
|
143
143
|
|
144
144
|
#
|
145
145
|
# Add a role to the member.
|
146
|
-
# @
|
147
|
-
# @macro async
|
146
|
+
# @async
|
148
147
|
#
|
149
148
|
# @param [Discorb::Role] role The role to add.
|
150
149
|
# @param [String] reason The reason for the action.
|
151
150
|
#
|
151
|
+
# @return [Async::Task<void>] The task.
|
152
|
+
#
|
152
153
|
def add_role(role, reason: nil)
|
153
154
|
Async do
|
154
155
|
@client.http.put("/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}", nil, audit_log_reason: reason).wait
|
@@ -157,12 +158,13 @@ module Discorb
|
|
157
158
|
|
158
159
|
#
|
159
160
|
# Remove a role to the member.
|
160
|
-
# @
|
161
|
-
# @macro async
|
161
|
+
# @async
|
162
162
|
#
|
163
163
|
# @param [Discorb::Role] role The role to add.
|
164
164
|
# @param [String] reason The reason for the action.
|
165
165
|
#
|
166
|
+
# @return [Async::Task<void>] The task.
|
167
|
+
#
|
166
168
|
def remove_role(role, reason: nil)
|
167
169
|
Async do
|
168
170
|
@client.http.delete("/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}", audit_log_reason: reason).wait
|
@@ -171,8 +173,7 @@ module Discorb
|
|
171
173
|
|
172
174
|
#
|
173
175
|
# Edit the member.
|
174
|
-
# @
|
175
|
-
# @macro async
|
176
|
+
# @async
|
176
177
|
# @macro edit
|
177
178
|
#
|
178
179
|
# @param [String] nick The nickname of the member.
|
@@ -180,27 +181,54 @@ module Discorb
|
|
180
181
|
# @param [Boolean] mute Whether the member is muted.
|
181
182
|
# @param [Boolean] deaf Whether the member is deafened.
|
182
183
|
# @param [Discorb::StageChannel] channel The channel the member is moved to.
|
184
|
+
# @param [Time, nil] communication_disabled_until The time the member is timed out. Set to `nil` to end the timeout.
|
185
|
+
# @param [Time, nil] timeout_until Alias of `communication_disabled_until`.
|
183
186
|
# @param [String] reason The reason for the action.
|
184
187
|
#
|
185
|
-
|
188
|
+
# @return [Async::Task<void>] The task.
|
189
|
+
#
|
190
|
+
def edit(
|
191
|
+
nick: Discorb::Unset, role: Discorb::Unset, mute: Discorb::Unset, deaf: Discorb::Unset, channel: Discorb::Unset, communication_disabled_until: Discorb::Unset, timeout_until: Discorb::Unset,
|
192
|
+
reason: nil
|
193
|
+
)
|
186
194
|
Async do
|
187
195
|
payload = {}
|
188
|
-
payload[:nick] = nick if nick !=
|
189
|
-
payload[:roles] = role if role !=
|
190
|
-
payload[:mute] = mute if mute !=
|
191
|
-
payload[:deaf] = deaf if deaf !=
|
192
|
-
|
196
|
+
payload[:nick] = nick if nick != Discorb::Unset
|
197
|
+
payload[:roles] = role if role != Discorb::Unset
|
198
|
+
payload[:mute] = mute if mute != Discorb::Unset
|
199
|
+
payload[:deaf] = deaf if deaf != Discorb::Unset
|
200
|
+
communication_disabled_until = timeout_until if timeout_until != Discorb::Unset
|
201
|
+
payload[:communication_disabled_until] = communication_disabled_until&.iso8601 if communication_disabled_until != Discorb::Unset
|
202
|
+
payload[:channel_id] = channel&.id if channel != Discorb::Unset
|
193
203
|
@client.http.patch("/guilds/#{@guild_id}/members/#{@id}", payload, audit_log_reason: reason).wait
|
194
204
|
end
|
195
205
|
end
|
196
206
|
|
197
207
|
alias modify edit
|
198
208
|
|
209
|
+
#
|
210
|
+
# Timeout the member.
|
211
|
+
# @async
|
212
|
+
#
|
213
|
+
# @param [Time] time The time until the member is timeout.
|
214
|
+
# @param [String] reason The reason for the action.
|
215
|
+
#
|
216
|
+
# @return [Async::Task<void>] The task.
|
217
|
+
#
|
218
|
+
def timeout(time, reason: nil)
|
219
|
+
edit(communication_disabled_until: time, reason: reason)
|
220
|
+
end
|
221
|
+
|
222
|
+
alias disable_communication timeout
|
223
|
+
|
199
224
|
#
|
200
225
|
# Kick the member.
|
226
|
+
# @async
|
201
227
|
#
|
202
228
|
# @param [String] reason The reason for the action.
|
203
229
|
#
|
230
|
+
# @return [Async::Task<void>] The task.
|
231
|
+
#
|
204
232
|
def kick(reason: nil)
|
205
233
|
Async do
|
206
234
|
guild.kick_member(self, reason: reason).wait
|
@@ -209,6 +237,7 @@ module Discorb
|
|
209
237
|
|
210
238
|
#
|
211
239
|
# Ban the member.
|
240
|
+
# @async
|
212
241
|
#
|
213
242
|
# @param [Integer] delete_message_days The number of days to delete messages.
|
214
243
|
# @param [String] reason The reason for the action.
|
data/lib/discorb/message.rb
CHANGED
@@ -294,6 +294,7 @@ module Discorb
|
|
294
294
|
|
295
295
|
#
|
296
296
|
# Edit the message.
|
297
|
+
# @async
|
297
298
|
#
|
298
299
|
# @param [String] content The message content.
|
299
300
|
# @param [Discorb::Embed] embed The embed to send.
|
@@ -302,6 +303,8 @@ module Discorb
|
|
302
303
|
# @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
|
303
304
|
# @param [Boolean] supress Whether to supress embeds.
|
304
305
|
#
|
306
|
+
# @return [Async::Task<void>] The task.
|
307
|
+
#
|
305
308
|
def edit(content = nil, embed: nil, embeds: nil, allowed_mentions: nil,
|
306
309
|
components: nil, supress: nil)
|
307
310
|
Async do
|
@@ -312,9 +315,12 @@ module Discorb
|
|
312
315
|
|
313
316
|
#
|
314
317
|
# Delete the message.
|
318
|
+
# @async
|
315
319
|
#
|
316
320
|
# @param [String] reason The reason for deleting the message.
|
317
321
|
#
|
322
|
+
# @return [Async::Task<void>] The task.
|
323
|
+
#
|
318
324
|
def delete!(reason: nil)
|
319
325
|
Async do
|
320
326
|
channel.delete_message!(@id, reason: reason).wait
|
@@ -342,8 +348,7 @@ module Discorb
|
|
342
348
|
end
|
343
349
|
|
344
350
|
# Reply to the message.
|
345
|
-
# @
|
346
|
-
# @macro http
|
351
|
+
# @async
|
347
352
|
# @param (see #post)
|
348
353
|
# @return [Async::Task<Discorb::Message>] The message.
|
349
354
|
def reply(*args, **kwargs)
|
@@ -354,8 +359,9 @@ module Discorb
|
|
354
359
|
|
355
360
|
#
|
356
361
|
# Publish the message.
|
357
|
-
# @
|
358
|
-
#
|
362
|
+
# @async
|
363
|
+
#
|
364
|
+
# @return [Async::Task<void>] The task.
|
359
365
|
#
|
360
366
|
def publish
|
361
367
|
Async do
|
@@ -365,11 +371,12 @@ module Discorb
|
|
365
371
|
|
366
372
|
#
|
367
373
|
# Add a reaction to the message.
|
368
|
-
# @
|
369
|
-
# @macro http
|
374
|
+
# @async
|
370
375
|
#
|
371
376
|
# @param [Discorb::Emoji] emoji The emoji to react with.
|
372
377
|
#
|
378
|
+
# @return [Async::Task<void>] The task.
|
379
|
+
#
|
373
380
|
def add_reaction(emoji)
|
374
381
|
Async do
|
375
382
|
@client.http.put("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me", nil).wait
|
@@ -380,11 +387,12 @@ module Discorb
|
|
380
387
|
|
381
388
|
#
|
382
389
|
# Remove a reaction from the message.
|
383
|
-
# @
|
384
|
-
# @macro http
|
390
|
+
# @async
|
385
391
|
#
|
386
392
|
# @param [Discorb::Emoji] emoji The emoji to remove.
|
387
393
|
#
|
394
|
+
# @return [Async::Task<void>] The task.
|
395
|
+
#
|
388
396
|
def remove_reaction(emoji)
|
389
397
|
Async do
|
390
398
|
@client.http.delete("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me").wait
|
@@ -395,12 +403,13 @@ module Discorb
|
|
395
403
|
|
396
404
|
#
|
397
405
|
# Remove other member's reaction from the message.
|
398
|
-
# @
|
399
|
-
# @macro http
|
406
|
+
# @async
|
400
407
|
#
|
401
408
|
# @param [Discorb::Emoji] emoji The emoji to remove.
|
402
409
|
# @param [Discorb::Member] member The member to remove the reaction from.
|
403
410
|
#
|
411
|
+
# @return [Async::Task<void>] The task.
|
412
|
+
#
|
404
413
|
def remove_reaction_of(emoji, member)
|
405
414
|
Async do
|
406
415
|
@client.http.delete("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/#{member.is_a?(Member) ? member.id : member}").wait
|
@@ -411,8 +420,7 @@ module Discorb
|
|
411
420
|
|
412
421
|
#
|
413
422
|
# Fetch reacted users of reaction.
|
414
|
-
# @
|
415
|
-
# @macro http
|
423
|
+
# @async
|
416
424
|
#
|
417
425
|
# @param [Discorb::Emoji] emoji The emoji to fetch.
|
418
426
|
# @param [Integer, nil] limit The maximum number of users to fetch. `nil` for no limit.
|
@@ -445,11 +453,12 @@ module Discorb
|
|
445
453
|
|
446
454
|
#
|
447
455
|
# Pin the message.
|
448
|
-
# @
|
449
|
-
# @macro http
|
456
|
+
# @async
|
450
457
|
#
|
451
458
|
# @param [String] reason The reason for pinning the message.
|
452
459
|
#
|
460
|
+
# @return [Async::Task<void>] The task.
|
461
|
+
#
|
453
462
|
def pin(reason: nil)
|
454
463
|
Async do
|
455
464
|
channel.pin_message(self, reason: reason).wait
|
@@ -458,11 +467,12 @@ module Discorb
|
|
458
467
|
|
459
468
|
#
|
460
469
|
# Unpin the message.
|
461
|
-
# @
|
462
|
-
# @macro http
|
470
|
+
# @async
|
463
471
|
#
|
464
472
|
# @param [String] reason The reason for unpinning the message.
|
465
473
|
#
|
474
|
+
# @return [Async::Task<void>] The task.
|
475
|
+
#
|
466
476
|
def unpin(reason: nil)
|
467
477
|
Async do
|
468
478
|
channel.unpin_message(self, reason: reason).wait
|
@@ -471,10 +481,11 @@ module Discorb
|
|
471
481
|
|
472
482
|
#
|
473
483
|
# Start thread from the message.
|
484
|
+
# @async
|
474
485
|
#
|
475
486
|
# @param (see Discorb::Channel#start_thread)
|
476
487
|
#
|
477
|
-
# @return [Async::Task
|
488
|
+
# @return [Async::Task<Discorb::ThreadChannel>] <description>
|
478
489
|
#
|
479
490
|
def start_thread(*args, **kwargs)
|
480
491
|
Async do
|