discorb 0.13.0 → 0.13.4
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.
- checksums.yaml +4 -4
- data/.github/workflows/build_main.yml +1 -0
- data/.github/workflows/build_version.yml +4 -3
- data/.github/workflows/crowdin.yml +32 -0
- data/.gitignore +3 -1
- data/.yardopts +2 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/Changelog.md +420 -388
- data/Gemfile +5 -1
- data/README.md +2 -2
- data/Rakefile +131 -1
- data/crowdin.yml +2 -0
- data/discorb.gemspec +12 -1
- 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 +32 -9
- data/lib/discorb/application.rb +1 -1
- data/lib/discorb/asset.rb +1 -1
- data/lib/discorb/channel.rb +170 -125
- data/lib/discorb/client.rb +20 -22
- data/lib/discorb/common.rb +32 -1
- data/lib/discorb/dictionary.rb +10 -2
- data/lib/discorb/emoji.rb +7 -9
- data/lib/discorb/emoji_table.rb +3891 -3891
- data/lib/discorb/event.rb +12 -11
- 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 +63 -17
- data/lib/discorb/guild.rb +110 -156
- data/lib/discorb/guild_template.rb +15 -12
- data/lib/discorb/http.rb +41 -136
- data/lib/discorb/integration.rb +34 -2
- data/lib/discorb/interaction/autocomplete.rb +1 -1
- data/lib/discorb/interaction/response.rb +34 -32
- data/lib/discorb/interaction/root.rb +8 -0
- data/lib/discorb/invite.rb +4 -3
- data/lib/discorb/log.rb +3 -2
- data/lib/discorb/member.rb +44 -15
- data/lib/discorb/message.rb +33 -22
- data/lib/discorb/modules.rb +28 -35
- data/lib/discorb/presence.rb +2 -2
- data/lib/discorb/rate_limit.rb +14 -18
- data/lib/discorb/role.rb +18 -14
- data/lib/discorb/sticker.rb +10 -14
- data/lib/discorb/user.rb +10 -10
- data/lib/discorb/voice_state.rb +12 -7
- data/lib/discorb/webhook.rb +44 -50
- 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 +18 -5
data/lib/discorb/member.rb
CHANGED
@@ -143,36 +143,37 @@ 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
|
-
@client.http.
|
155
|
+
@client.http.request(Route.new("/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}", "//guilds/:guild_id/members/:user_id/roles/:role_id", :put), nil, audit_log_reason: reason).wait
|
155
156
|
end
|
156
157
|
end
|
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
|
-
@client.http.
|
170
|
+
@client.http.request(Route.new("/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}", "//guilds/:guild_id/members/:user_id/roles/:role_id", :delete), audit_log_reason: reason).wait
|
169
171
|
end
|
170
172
|
end
|
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
|
-
|
193
|
-
|
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
|
203
|
+
@client.http.request(Route.new("/guilds/#{@guild_id}/members/#{@id}", "//guilds/:guild_id/members/:user_id", :patch), 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,14 +371,15 @@ 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
|
-
@client.http.
|
382
|
+
@client.http.request(Route.new("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me", "//channels/:channel_id/messages/:message_id/reactions/:emoji/@me", :put), nil).wait
|
376
383
|
end
|
377
384
|
end
|
378
385
|
|
@@ -380,14 +387,15 @@ 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
|
-
@client.http.
|
398
|
+
@client.http.request(Route.new("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me", "//channels/:channel_id/messages/:message_id/reactions/:emoji/@me", :delete)).wait
|
391
399
|
end
|
392
400
|
end
|
393
401
|
|
@@ -395,15 +403,16 @@ 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
|
-
@client.http.
|
415
|
+
@client.http.request(Route.new("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/#{member.is_a?(Member) ? member.id : member}", "//channels/:channel_id/messages/:message_id/reactions/:emoji/:user_id", :delete)).wait
|
407
416
|
end
|
408
417
|
end
|
409
418
|
|
@@ -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.
|
@@ -426,7 +434,7 @@ module Discorb
|
|
426
434
|
after = 0
|
427
435
|
users = []
|
428
436
|
loop do
|
429
|
-
_resp, data = @client.http.
|
437
|
+
_resp, data = @client.http.request(Route.new("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=100&after=#{after}", "//channels/:channel_id/messages/:message_id/reactions/:emoji", :get)).wait
|
430
438
|
break if data.empty?
|
431
439
|
|
432
440
|
users += data.map { |r| guild&.members&.[](r[:id]) || @client.users[r[:id]] || User.new(@client, r) }
|
@@ -437,7 +445,7 @@ module Discorb
|
|
437
445
|
end
|
438
446
|
next users
|
439
447
|
else
|
440
|
-
_resp, data = @client.http.
|
448
|
+
_resp, data = @client.http.request(Route.new("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=#{limit}&after=#{after}", "//channels/:channel_id/messages/:message_id/reactions/:emoji", :get)).wait
|
441
449
|
next data.map { |r| guild&.members&.[](r[:id]) || @client.users[r[:id]] || User.new(@client, r) }
|
442
450
|
end
|
443
451
|
end
|
@@ -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
|
data/lib/discorb/modules.rb
CHANGED
@@ -7,8 +7,7 @@ module Discorb
|
|
7
7
|
module Messageable
|
8
8
|
#
|
9
9
|
# Post a message to the channel.
|
10
|
-
# @
|
11
|
-
# @macro http
|
10
|
+
# @async
|
12
11
|
#
|
13
12
|
# @param [String] content The message content.
|
14
13
|
# @param [Boolean] tts Whether the message is tts.
|
@@ -38,14 +37,8 @@ module Discorb
|
|
38
37
|
allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
|
39
38
|
payload[:message_reference] = reference.to_reference if reference
|
40
39
|
payload[:components] = Component.to_payload(components) if components
|
41
|
-
files = [file]
|
42
|
-
|
43
|
-
seperator, payload = HTTP.multipart(payload, files)
|
44
|
-
headers = { "content-type" => "multipart/form-data; boundary=#{seperator}" }
|
45
|
-
else
|
46
|
-
headers = {}
|
47
|
-
end
|
48
|
-
_resp, data = @client.http.post("/channels/#{channel_id.wait}/messages", payload, headers: headers).wait
|
40
|
+
files = [file]
|
41
|
+
_resp, data = @client.http.multipart_request(Route.new("/channels/#{channel_id.wait}/messages", "//channels/:channel_id/messages", :post), payload, files).wait
|
49
42
|
Message.new(@client, data.merge({ guild_id: @guild_id.to_s }))
|
50
43
|
end
|
51
44
|
end
|
@@ -54,8 +47,7 @@ module Discorb
|
|
54
47
|
|
55
48
|
#
|
56
49
|
# Edit a message.
|
57
|
-
# @
|
58
|
-
# @macro http
|
50
|
+
# @async
|
59
51
|
#
|
60
52
|
# @param [#to_s] message_id The message id.
|
61
53
|
# @param [String] content The message content.
|
@@ -65,6 +57,8 @@ module Discorb
|
|
65
57
|
# @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
|
66
58
|
# @param [Boolean] supress Whether to supress embeds.
|
67
59
|
#
|
60
|
+
# @return [Async::Task<void>] The task.
|
61
|
+
#
|
68
62
|
def edit_message(message_id, content = nil, embed: nil, embeds: nil, allowed_mentions: nil,
|
69
63
|
components: nil, supress: nil)
|
70
64
|
Async do
|
@@ -80,21 +74,22 @@ module Discorb
|
|
80
74
|
allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
|
81
75
|
payload[:components] = Component.to_payload(components) if components
|
82
76
|
payload[:flags] = (supress ? 1 << 2 : 0) unless supress.nil?
|
83
|
-
@client.http.
|
77
|
+
@client.http.request(Route.new("/channels/#{channel_id.wait}/messages/#{message_id}", "//channels/:channel_id/messages/:message_id", :patch), payload).wait
|
84
78
|
end
|
85
79
|
end
|
86
80
|
|
87
81
|
#
|
88
82
|
# Delete a message.
|
89
|
-
# @
|
90
|
-
# @macro http
|
83
|
+
# @async
|
91
84
|
#
|
92
85
|
# @param [#to_s] message_id The message id.
|
93
86
|
# @param [String] reason The reason for deleting the message.
|
94
87
|
#
|
88
|
+
# @return [Async::Task<void>] The task.
|
89
|
+
#
|
95
90
|
def delete_message!(message_id, reason: nil)
|
96
91
|
Async do
|
97
|
-
@client.http.
|
92
|
+
@client.http.request(Route.new("/channels/#{channel_id.wait}/messages/#{message_id}", "//channels/:channel_id/messages/:message_id", :delete), audit_log_reason: reason).wait
|
98
93
|
end
|
99
94
|
end
|
100
95
|
|
@@ -102,8 +97,7 @@ module Discorb
|
|
102
97
|
|
103
98
|
#
|
104
99
|
# Fetch a message from ID.
|
105
|
-
# @
|
106
|
-
# @macro http
|
100
|
+
# @async
|
107
101
|
#
|
108
102
|
# @param [Discorb::Snowflake] id The ID of the message.
|
109
103
|
#
|
@@ -112,15 +106,14 @@ module Discorb
|
|
112
106
|
#
|
113
107
|
def fetch_message(id)
|
114
108
|
Async do
|
115
|
-
_resp, data = @client.http.
|
109
|
+
_resp, data = @client.http.request(Route.new("/channels/#{channel_id.wait}/messages/#{id}", "//channels/:channel_id/messages/:message_id", :get)).wait
|
116
110
|
Message.new(@client, data.merge({ guild_id: @guild_id.to_s }))
|
117
111
|
end
|
118
112
|
end
|
119
113
|
|
120
114
|
#
|
121
115
|
# Fetch a message history.
|
122
|
-
# @
|
123
|
-
# @macro http
|
116
|
+
# @async
|
124
117
|
#
|
125
118
|
# @param [Integer] limit The number of messages to fetch.
|
126
119
|
# @param [Discorb::Snowflake] before The ID of the message to fetch before.
|
@@ -137,57 +130,57 @@ module Discorb
|
|
137
130
|
after: Discorb::Utils.try(around, :id),
|
138
131
|
around: Discorb::Utils.try(before, :id),
|
139
132
|
}.filter { |_k, v| !v.nil? }.to_h
|
140
|
-
_resp, messages = @client.http.
|
133
|
+
_resp, messages = @client.http.request(Route.new("/channels/#{channel_id.wait}/messages?#{URI.encode_www_form(params)}", "//channels/:channel_id/messages", :get)).wait
|
141
134
|
messages.map { |m| Message.new(@client, m.merge({ guild_id: @guild_id.to_s })) }
|
142
135
|
end
|
143
136
|
end
|
144
137
|
|
145
138
|
#
|
146
139
|
# Fetch the pinned messages in the channel.
|
147
|
-
# @
|
148
|
-
# @macro http
|
140
|
+
# @async
|
149
141
|
#
|
150
142
|
# @return [Async::Task<Array<Discorb::Message>>] The pinned messages in the channel.
|
151
143
|
#
|
152
144
|
def fetch_pins
|
153
145
|
Async do
|
154
|
-
_resp, data = @client.http.
|
146
|
+
_resp, data = @client.http.request(Route.new("/channels/#{channel_id.wait}/pins", "//channels/:channel_id/pins", :get)).wait
|
155
147
|
data.map { |pin| Message.new(@client, pin) }
|
156
148
|
end
|
157
149
|
end
|
158
150
|
|
159
151
|
#
|
160
152
|
# Pin a message in the channel.
|
161
|
-
# @
|
162
|
-
# @macro http
|
153
|
+
# @async
|
163
154
|
#
|
164
155
|
# @param [Discorb::Message] message The message to pin.
|
165
156
|
# @param [String] reason The reason of pinning the message.
|
166
157
|
#
|
158
|
+
# @return [Async::Task<void>] The task.
|
159
|
+
#
|
167
160
|
def pin_message(message, reason: nil)
|
168
161
|
Async do
|
169
|
-
@client.http.
|
162
|
+
@client.http.request(Route.new("/channels/#{channel_id.wait}/pins/#{message.id}", "//channels/:channel_id/pins/:message_id", :put), {}, audit_log_reason: reason).wait
|
170
163
|
end
|
171
164
|
end
|
172
165
|
|
173
166
|
#
|
174
167
|
# Unpin a message in the channel.
|
175
|
-
# @
|
176
|
-
# @macro http
|
168
|
+
# @async
|
177
169
|
#
|
178
170
|
# @param [Discorb::Message] message The message to unpin.
|
179
171
|
# @param [String] reason The reason of unpinning the message.
|
180
172
|
#
|
173
|
+
# @return [Async::Task<void>] The task.
|
174
|
+
#
|
181
175
|
def unpin_message(message, reason: nil)
|
182
176
|
Async do
|
183
|
-
@client.http.
|
177
|
+
@client.http.request(Route.new("/channels/#{channel_id.wait}/pins/#{message.id}", "//channels/:channel_id/pins/:message_id", :delete), audit_log_reason: reason).wait
|
184
178
|
end
|
185
179
|
end
|
186
180
|
|
187
181
|
#
|
188
182
|
# Trigger the typing indicator in the channel.
|
189
|
-
# @
|
190
|
-
# @macro http
|
183
|
+
# @async
|
191
184
|
#
|
192
185
|
# If block is given, trigger typing indicator during executing block.
|
193
186
|
# @example
|
@@ -202,7 +195,7 @@ module Discorb
|
|
202
195
|
begin
|
203
196
|
post_task = Async do
|
204
197
|
loop do
|
205
|
-
@client.http.
|
198
|
+
@client.http.request(Route.new("/channels/#{@id}/typing", "//channels/:channel_id/typing", :post), {})
|
206
199
|
sleep(5)
|
207
200
|
end
|
208
201
|
end
|
@@ -212,7 +205,7 @@ module Discorb
|
|
212
205
|
end
|
213
206
|
else
|
214
207
|
Async do |task|
|
215
|
-
@client.http.
|
208
|
+
@client.http.request(Route.new("/channels/#{@id}/typing", "//channels/:channel_id/typing", :post), {})
|
216
209
|
end
|
217
210
|
end
|
218
211
|
end
|
data/lib/discorb/presence.rb
CHANGED
@@ -175,12 +175,12 @@ module Discorb
|
|
175
175
|
# Represents the assets of an activity.
|
176
176
|
#
|
177
177
|
class Asset < DiscordModel
|
178
|
-
# @return [String] The large image ID of the asset.
|
178
|
+
# @return [String] The large image ID or URL of the asset.
|
179
179
|
attr_reader :large_image
|
180
180
|
alias large_id large_image
|
181
181
|
# @return [String] The large text of the activity.
|
182
182
|
attr_reader :large_text
|
183
|
-
# @return [String] The small image ID of the activity.
|
183
|
+
# @return [String] The small image ID or URL of the activity.
|
184
184
|
attr_reader :small_image
|
185
185
|
alias small_id small_image
|
186
186
|
# @return [String] The small text of the activity.
|
data/lib/discorb/rate_limit.rb
CHANGED
@@ -9,8 +9,8 @@ module Discorb
|
|
9
9
|
# @private
|
10
10
|
def initialize(client)
|
11
11
|
@client = client
|
12
|
-
@current_ratelimits = {}
|
13
12
|
@path_ratelimit_bucket = {}
|
13
|
+
@path_ratelimit_hash = {}
|
14
14
|
@global = false
|
15
15
|
end
|
16
16
|
|
@@ -21,12 +21,10 @@ module Discorb
|
|
21
21
|
#
|
22
22
|
# Wait for the rate limit to reset.
|
23
23
|
#
|
24
|
-
# @param [
|
25
|
-
# @param [String] path The path.
|
24
|
+
# @param [Discorb::Route] path The path.
|
26
25
|
#
|
27
|
-
def wait(
|
28
|
-
return if path.start_with?("https://")
|
29
|
-
|
26
|
+
def wait(path)
|
27
|
+
# return if path.url.start_with?("https://")
|
30
28
|
if @global && @global > Time.now.to_f
|
31
29
|
time = @global - Time.now.to_f
|
32
30
|
@client.log.info("global rate limit reached, waiting #{time} seconds")
|
@@ -34,36 +32,34 @@ module Discorb
|
|
34
32
|
@global = false
|
35
33
|
end
|
36
34
|
|
37
|
-
return unless hash = @
|
35
|
+
return unless hash = @path_ratelimit_hash[path.identifier]
|
38
36
|
|
39
|
-
return unless
|
37
|
+
return unless bucket = @path_ratelimit_bucket[hash + path.major_param]
|
40
38
|
|
41
|
-
if
|
42
|
-
@
|
39
|
+
if bucket[:reset_at] < Time.now.to_f
|
40
|
+
@path_ratelimit_bucket.delete(path.identifier + path.major_param)
|
43
41
|
return
|
44
42
|
end
|
45
|
-
return if
|
43
|
+
return if bucket[:remaining] > 0
|
46
44
|
|
47
|
-
time =
|
48
|
-
@client.log.info("rate limit for #{
|
45
|
+
time = bucket[:reset_at] - Time.now.to_f
|
46
|
+
@client.log.info("rate limit for #{path.identifier} with #{path.major_param} reached, waiting #{time.round(4)} seconds")
|
49
47
|
sleep(time)
|
50
48
|
end
|
51
49
|
|
52
50
|
#
|
53
51
|
# Save the rate limit.
|
54
52
|
#
|
55
|
-
# @param [String] method The HTTP method.
|
56
53
|
# @param [String] path The path.
|
57
54
|
# @param [Net::HTTPResponse] resp The response.
|
58
55
|
#
|
59
|
-
def save(
|
56
|
+
def save(path, resp)
|
60
57
|
if resp["X-Ratelimit-Global"] == "true"
|
61
58
|
@global = Time.now.to_f + JSON.parse(resp.body, symbolize_names: true)[:retry_after]
|
62
59
|
end
|
63
60
|
return unless resp["X-RateLimit-Remaining"]
|
64
|
-
|
65
|
-
@path_ratelimit_bucket[
|
66
|
-
@current_ratelimits[resp["X-RateLimit-Bucket"]] = {
|
61
|
+
@path_ratelimit_hash[path.identifier] = resp["X-Ratelimit-Bucket"]
|
62
|
+
@path_ratelimit_bucket[resp["X-Ratelimit-Bucket"] + path.major_param] = {
|
67
63
|
remaining: resp["X-RateLimit-Remaining"].to_i,
|
68
64
|
reset_at: Time.now.to_f + resp["X-RateLimit-Reset-After"].to_f,
|
69
65
|
}
|
data/lib/discorb/role.rb
CHANGED
@@ -90,22 +90,22 @@ module Discorb
|
|
90
90
|
|
91
91
|
#
|
92
92
|
# Moves the role to a new position.
|
93
|
-
# @
|
94
|
-
# @macro http
|
93
|
+
# @async
|
95
94
|
#
|
96
95
|
# @param [Integer] position The new position.
|
97
96
|
# @param [String] reason The reason for moving the role.
|
98
97
|
#
|
98
|
+
# @return [Async::Task<void>] The task.
|
99
|
+
#
|
99
100
|
def move(position, reason: nil)
|
100
101
|
Async do
|
101
|
-
@client.http.
|
102
|
+
@client.http.request(Route.new("/guilds/#{@guild.id}/roles", "//guilds/:guild_id/roles", :patch), { id: @id, position: position }, audit_log_reason: reason).wait
|
102
103
|
end
|
103
104
|
end
|
104
105
|
|
105
106
|
#
|
106
107
|
# Edits the role.
|
107
|
-
# @
|
108
|
-
# @macro http
|
108
|
+
# @async
|
109
109
|
# @macro edit
|
110
110
|
#
|
111
111
|
# @param [String] name The new name of the role.
|
@@ -116,22 +116,24 @@ module Discorb
|
|
116
116
|
# @param [Discorb::Image, Discorb::UnicodeEmoji] icon The new icon or emoji of the role.
|
117
117
|
# @param [String] reason The reason for editing the role.
|
118
118
|
#
|
119
|
-
|
119
|
+
# @return [Async::Task<void>] The task.
|
120
|
+
#
|
121
|
+
def edit(name: Discorb::Unset, position: Discorb::Unset, color: Discorb::Unset, hoist: Discorb::Unset, mentionable: Discorb::Unset, icon: Discorb::Unset, reason: nil)
|
120
122
|
Async do
|
121
123
|
payload = {}
|
122
|
-
payload[:name] = name if name !=
|
123
|
-
payload[:position] = position if position !=
|
124
|
-
payload[:color] = color.to_i if color !=
|
125
|
-
payload[:hoist] = hoist if hoist !=
|
126
|
-
payload[:mentionable] = mentionable if mentionable !=
|
127
|
-
if icon !=
|
124
|
+
payload[:name] = name if name != Discorb::Unset
|
125
|
+
payload[:position] = position if position != Discorb::Unset
|
126
|
+
payload[:color] = color.to_i if color != Discorb::Unset
|
127
|
+
payload[:hoist] = hoist if hoist != Discorb::Unset
|
128
|
+
payload[:mentionable] = mentionable if mentionable != Discorb::Unset
|
129
|
+
if icon != Discorb::Unset
|
128
130
|
if icon.is_a?(Discorb::Image)
|
129
131
|
payload[:icon] = icon.to_s
|
130
132
|
else
|
131
133
|
payload[:unicode_emoji] = icon.to_s
|
132
134
|
end
|
133
135
|
end
|
134
|
-
@client.http.
|
136
|
+
@client.http.request(Route.new("/guilds/#{@guild.id}/roles/#{@id}", "//guilds/:guild_id/roles/:role_id", :patch), payload, audit_log_reason: reason).wait
|
135
137
|
end
|
136
138
|
end
|
137
139
|
|
@@ -142,9 +144,11 @@ module Discorb
|
|
142
144
|
#
|
143
145
|
# @param [String] reason The reason for deleting the role.
|
144
146
|
#
|
147
|
+
# @return [Async::Task<void>] The task.
|
148
|
+
#
|
145
149
|
def delete!(reason: nil)
|
146
150
|
Async do
|
147
|
-
@client.http.
|
151
|
+
@client.http.request(Route.new("/guilds/#{@guild.id}/roles/#{@id}", "//guilds/:guild_id/roles/:role_id", :delete), audit_log_reason: reason).wait
|
148
152
|
end
|
149
153
|
end
|
150
154
|
|