discorb 0.12.4 → 0.13.3
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 +4 -3
- data/.github/workflows/crowdin.yml +32 -0
- data/.gitignore +3 -1
- data/.yardopts +2 -0
- data/Changelog.md +412 -378
- 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 +16 -12
- 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 +59 -5
- 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 +32 -2
- data/lib/discorb/asset.rb +1 -1
- data/lib/discorb/audit_logs.rb +28 -16
- data/lib/discorb/channel.rb +140 -81
- data/lib/discorb/client.rb +17 -19
- data/lib/discorb/common.rb +28 -1
- data/lib/discorb/components.rb +12 -0
- data/lib/discorb/dictionary.rb +1 -1
- data/lib/discorb/embed.rb +4 -0
- data/lib/discorb/emoji.rb +9 -7
- data/lib/discorb/emoji_table.rb +3891 -3891
- data/lib/discorb/event.rb +266 -24
- data/lib/discorb/event_handler.rb +39 -0
- data/lib/discorb/exe/show.rb +2 -0
- data/lib/discorb/extension.rb +5 -5
- data/lib/discorb/file.rb +4 -0
- data/lib/discorb/flag.rb +5 -1
- data/lib/discorb/gateway.rb +97 -17
- data/lib/discorb/gateway_requests.rb +4 -0
- data/lib/discorb/guild.rb +169 -82
- data/lib/discorb/guild_template.rb +12 -9
- data/lib/discorb/http.rb +82 -44
- data/lib/discorb/image.rb +7 -5
- data/lib/discorb/integration.rb +33 -1
- data/lib/discorb/intents.rb +8 -3
- 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/log.rb +4 -0
- data/lib/discorb/member.rb +42 -13
- data/lib/discorb/message.rb +32 -17
- data/lib/discorb/modules.rb +19 -26
- data/lib/discorb/permission.rb +4 -0
- data/lib/discorb/rate_limit.rb +6 -2
- data/lib/discorb/role.rb +15 -11
- data/lib/discorb/sticker.rb +17 -12
- data/lib/discorb/user.rb +8 -7
- data/lib/discorb/voice_state.rb +8 -5
- data/lib/discorb/webhook.rb +38 -47
- data/lib/discorb.rb +2 -2
- data/po/yard.pot +7775 -5157
- data/sig/discorb.rbs +3317 -3820
- data/template-replace/scripts/locale_ja.rb +62 -0
- metadata +18 -5
data/lib/discorb/application.rb
CHANGED
@@ -27,7 +27,8 @@ module Discorb
|
|
27
27
|
# @return [Boolean] Whether the application's bot requires a code grant.
|
28
28
|
attr_reader :bot_require_code_grant
|
29
29
|
alias bot_require_code_grant? bot_require_code_grant
|
30
|
-
|
30
|
+
# @return [Discorb::Application::Flag] The application's flags.
|
31
|
+
attr_reader :flags
|
31
32
|
# @private
|
32
33
|
def initialize(client, data)
|
33
34
|
@client = client
|
@@ -42,6 +43,7 @@ module Discorb
|
|
42
43
|
@verify_key = data[:verify_key]
|
43
44
|
@owner = @client.users[data[:owner][:id]] || User.new(@client, data[:owner])
|
44
45
|
@team = data[:team] && Team.new(@client, data[:team])
|
46
|
+
@flags = Flag.new(data[:flags])
|
45
47
|
end
|
46
48
|
|
47
49
|
def inspect
|
@@ -52,6 +54,34 @@ module Discorb
|
|
52
54
|
|
53
55
|
alias require_code_grant? bot_require_code_grant?
|
54
56
|
|
57
|
+
#
|
58
|
+
# Represents a flag for an application.
|
59
|
+
# ## Flag fields
|
60
|
+
#
|
61
|
+
# | Field|Value|
|
62
|
+
# |---|---|
|
63
|
+
# | `1 << 12` | `:gateway_presence` |
|
64
|
+
# | `1 << 13` | `:gateway_presence_limited` |
|
65
|
+
# | `1 << 14` | `:gateway_guild_members` |
|
66
|
+
# | `1 << 15` | `:gateway_guild_members_limited` |
|
67
|
+
# | `1 << 16` | `:verification_pending_guild_limit` |
|
68
|
+
# | `1 << 17` | `:embedded` |
|
69
|
+
# | `1 << 18` | `:gateway_message_content` |
|
70
|
+
# | `1 << 19` | `:gateway_message_content_limited` |
|
71
|
+
#
|
72
|
+
class Flag < Discorb::Flag
|
73
|
+
@bits = {
|
74
|
+
gateway_presence: 12,
|
75
|
+
gateway_presence_limited: 13,
|
76
|
+
gateway_guild_members: 14,
|
77
|
+
gateway_guild_members_limited: 15,
|
78
|
+
verification_pending_guild_limit: 16,
|
79
|
+
embedded: 17,
|
80
|
+
gateway_message_content: 18,
|
81
|
+
gateway_message_content_limited: 19,
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
55
85
|
#
|
56
86
|
# Represents a team for an application.
|
57
87
|
#
|
@@ -101,7 +131,7 @@ module Discorb
|
|
101
131
|
# @return [:invited, :accepted] The member's membership state.
|
102
132
|
attr_reader :membership_state
|
103
133
|
alias state membership_state
|
104
|
-
# @return [Array<
|
134
|
+
# @return [Array<Symbol>] The permissions of the member.
|
105
135
|
# @note This always return `:*`.
|
106
136
|
attr_reader :permissions
|
107
137
|
|
data/lib/discorb/asset.rb
CHANGED
data/lib/discorb/audit_logs.rb
CHANGED
@@ -90,6 +90,9 @@ module Discorb
|
|
90
90
|
# * `:sticker_create`
|
91
91
|
# * `:sticker_update`
|
92
92
|
# * `:sticker_delete`
|
93
|
+
# * `:guild_scheduled_event_create`
|
94
|
+
# * `:guild_scheduled_event_update`
|
95
|
+
# * `:guild_scheduled_event_delete`
|
93
96
|
# * `:thread_create`
|
94
97
|
# * `:thread_update`
|
95
98
|
# * `:thread_delete`
|
@@ -148,9 +151,12 @@ module Discorb
|
|
148
151
|
90 => :sticker_create,
|
149
152
|
91 => :sticker_update,
|
150
153
|
92 => :sticker_delete,
|
154
|
+
100 => :guild_scheduled_event_create,
|
155
|
+
101 => :guild_scheduled_event_update,
|
156
|
+
102 => :guild_scheduled_event_delete,
|
151
157
|
110 => :thread_create,
|
152
158
|
111 => :thread_update,
|
153
|
-
112 => :thread_delete
|
159
|
+
112 => :thread_delete,
|
154
160
|
}.freeze
|
155
161
|
|
156
162
|
# @private
|
@@ -160,7 +166,7 @@ module Discorb
|
|
160
166
|
role: ->(client, id, guild_id) { client.guilds[guild_id]&.roles&.[](id) },
|
161
167
|
member: ->(client, id, guild_id) { client.guilds[guild_id]&.members&.[](id) },
|
162
168
|
guild: ->(client, id, _guild_id) { client.guilds[id] },
|
163
|
-
message: ->(client, id, _guild_id) { client.messages[id] }
|
169
|
+
message: ->(client, id, _guild_id) { client.messages[id] },
|
164
170
|
}
|
165
171
|
|
166
172
|
# @private
|
@@ -171,15 +177,15 @@ module Discorb
|
|
171
177
|
@user_id = Snowflake.new(data[:user_id])
|
172
178
|
@target_id = Snowflake.new(data[:target_id])
|
173
179
|
@type = self.class.events[data[:action_type]]
|
174
|
-
@target = self.class.converts[@type.to_s.split(
|
180
|
+
@target = self.class.converts[@type.to_s.split("_")[0].to_sym]&.call(client, @target_id, @gui)
|
175
181
|
@target ||= Snowflake.new(data[:target_id])
|
176
182
|
@changes = data[:changes] && Changes.new(data[:changes])
|
177
183
|
@reason = data[:reason]
|
178
184
|
data[:options]&.each do |option, value|
|
179
185
|
define_singleton_method(option) { value }
|
180
|
-
if option.end_with?(
|
181
|
-
define_singleton_method(option.to_s.sub(
|
182
|
-
self.class.converts[option.to_s.split(
|
186
|
+
if option.end_with?("_id")
|
187
|
+
define_singleton_method(option.to_s.sub("_id", "")) do
|
188
|
+
self.class.converts[option.to_s.split("_")[0].to_sym]&.call(client, value, @guild_id)
|
183
189
|
end
|
184
190
|
end
|
185
191
|
end
|
@@ -203,7 +209,7 @@ module Discorb
|
|
203
209
|
end
|
204
210
|
|
205
211
|
def inspect
|
206
|
-
"#<#{self.class} #{@changes&.data&.length ||
|
212
|
+
"#<#{self.class} #{@changes&.data&.length || "No"} changes>"
|
207
213
|
end
|
208
214
|
|
209
215
|
class << self
|
@@ -268,15 +274,21 @@ module Discorb
|
|
268
274
|
def initialize(data)
|
269
275
|
@key = data[:key].to_sym
|
270
276
|
method = case @key.to_s
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
277
|
+
when /.*_id$/, "id"
|
278
|
+
->(v) { Snowflake.new(v) }
|
279
|
+
when "permissions"
|
280
|
+
->(v) { Discorb::Permission.new(v.to_i) }
|
281
|
+
when "status"
|
282
|
+
->(v) { Discorb::ScheduledEvent.status[v] }
|
283
|
+
when "entity_type"
|
284
|
+
->(v) { Discorb::ScheduledEvent.entity_type[v] }
|
285
|
+
when "privacy_level"
|
286
|
+
->(v) { Discorb::StageInstance.privacy_level[v] || Discorb::ScheduledEvent.privacy_level[v] }
|
287
|
+
else
|
288
|
+
->(v) { v }
|
289
|
+
end
|
290
|
+
@old_value = method.(data[:old_value])
|
291
|
+
@new_value = method.(data[:new_value])
|
280
292
|
end
|
281
293
|
|
282
294
|
#
|
data/lib/discorb/channel.rb
CHANGED
@@ -166,8 +166,7 @@ module Discorb
|
|
166
166
|
|
167
167
|
#
|
168
168
|
# Deletes the channel.
|
169
|
-
# @
|
170
|
-
# @macro http
|
169
|
+
# @async
|
171
170
|
#
|
172
171
|
# @param [String] reason The reason of deleting the channel.
|
173
172
|
#
|
@@ -186,8 +185,7 @@ module Discorb
|
|
186
185
|
|
187
186
|
#
|
188
187
|
# Moves the channel to another position.
|
189
|
-
# @
|
190
|
-
# @macro http
|
188
|
+
# @async
|
191
189
|
#
|
192
190
|
# @param [Integer] position The position to move the channel.
|
193
191
|
# @param [Boolean] lock_permissions Whether to lock the permissions of the channel.
|
@@ -196,13 +194,13 @@ module Discorb
|
|
196
194
|
#
|
197
195
|
# @return [Async::Task<self>] The moved channel.
|
198
196
|
#
|
199
|
-
def move(position, lock_permissions: false, parent:
|
197
|
+
def move(position, lock_permissions: false, parent: Discorb::Unset, reason: nil)
|
200
198
|
Async do
|
201
199
|
payload = {
|
202
200
|
position: position,
|
203
201
|
}
|
204
202
|
payload[:lock_permissions] = lock_permissions
|
205
|
-
payload[:parent_id] = parent&.id if parent !=
|
203
|
+
payload[:parent_id] = parent&.id if parent != Discorb::Unset
|
206
204
|
@client.http.patch("/guilds/#{@guild_id}/channels", payload, audit_log_reason: reason).wait
|
207
205
|
end
|
208
206
|
end
|
@@ -256,8 +254,7 @@ module Discorb
|
|
256
254
|
|
257
255
|
#
|
258
256
|
# Edits the channel.
|
259
|
-
# @
|
260
|
-
# @macro http
|
257
|
+
# @async
|
261
258
|
# @macro edit
|
262
259
|
#
|
263
260
|
# @param [String] name The name of the channel.
|
@@ -275,25 +272,25 @@ module Discorb
|
|
275
272
|
#
|
276
273
|
# @return [Async::Task<self>] The edited channel.
|
277
274
|
#
|
278
|
-
def edit(name:
|
279
|
-
topic:
|
280
|
-
rate_limit_per_user:
|
281
|
-
archive_in:
|
275
|
+
def edit(name: Discorb::Unset, position: Discorb::Unset, category: Discorb::Unset, parent: Discorb::Unset,
|
276
|
+
topic: Discorb::Unset, nsfw: Discorb::Unset, announce: Discorb::Unset,
|
277
|
+
rate_limit_per_user: Discorb::Unset, slowmode: Discorb::Unset, default_auto_archive_duration: Discorb::Unset,
|
278
|
+
archive_in: Discorb::Unset, reason: nil)
|
282
279
|
Async do
|
283
280
|
payload = {}
|
284
|
-
payload[:name] = name if name !=
|
285
|
-
payload[:announce] = announce ? 5 : 0 if announce !=
|
286
|
-
payload[:position] = position if position !=
|
287
|
-
payload[:topic] = topic || "" if topic !=
|
288
|
-
payload[:nsfw] = nsfw if nsfw !=
|
281
|
+
payload[:name] = name if name != Discorb::Unset
|
282
|
+
payload[:announce] = announce ? 5 : 0 if announce != Discorb::Unset
|
283
|
+
payload[:position] = position if position != Discorb::Unset
|
284
|
+
payload[:topic] = topic || "" if topic != Discorb::Unset
|
285
|
+
payload[:nsfw] = nsfw if nsfw != Discorb::Unset
|
289
286
|
|
290
|
-
slowmode = rate_limit_per_user if slowmode ==
|
291
|
-
payload[:rate_limit_per_user] = slowmode || 0 if slowmode !=
|
292
|
-
parent = category if parent ==
|
293
|
-
payload[:parent_id] = parent&.id if parent !=
|
287
|
+
slowmode = rate_limit_per_user if slowmode == Discorb::Unset
|
288
|
+
payload[:rate_limit_per_user] = slowmode || 0 if slowmode != Discorb::Unset
|
289
|
+
parent = category if parent == Discorb::Unset
|
290
|
+
payload[:parent_id] = parent&.id if parent != Discorb::Unset
|
294
291
|
|
295
292
|
default_auto_archive_duration ||= archive_in
|
296
|
-
payload[:default_auto_archive_duration] = default_auto_archive_duration if default_auto_archive_duration !=
|
293
|
+
payload[:default_auto_archive_duration] = default_auto_archive_duration if default_auto_archive_duration != Discorb::Unset
|
297
294
|
|
298
295
|
@client.http.patch("/channels/#{@id}", payload, audit_log_reason: reason).wait
|
299
296
|
self
|
@@ -304,8 +301,7 @@ module Discorb
|
|
304
301
|
|
305
302
|
#
|
306
303
|
# Create webhook in the channel.
|
307
|
-
# @
|
308
|
-
# @macro http
|
304
|
+
# @async
|
309
305
|
#
|
310
306
|
# @param [String] name The name of the webhook.
|
311
307
|
# @param [Discorb::Image] avatar The avatar of the webhook.
|
@@ -324,8 +320,7 @@ module Discorb
|
|
324
320
|
|
325
321
|
#
|
326
322
|
# Fetch webhooks in the channel.
|
327
|
-
# @
|
328
|
-
# @macro http
|
323
|
+
# @async
|
329
324
|
#
|
330
325
|
# @return [Async::Task<Array<Discorb::Webhook>>] The webhooks in the channel.
|
331
326
|
#
|
@@ -338,12 +333,13 @@ module Discorb
|
|
338
333
|
|
339
334
|
#
|
340
335
|
# Bulk delete messages in the channel.
|
341
|
-
# @
|
342
|
-
# @macro http
|
336
|
+
# @async
|
343
337
|
#
|
344
338
|
# @param [Discorb::Message] messages The messages to delete.
|
345
339
|
# @param [Boolean] force Whether to ignore the validation for message (14 days limit).
|
346
340
|
#
|
341
|
+
# @return [Async::Task<void>] The task.
|
342
|
+
#
|
347
343
|
def delete_messages!(*messages, force: false)
|
348
344
|
Async do
|
349
345
|
messages = messages.first if messages.length == 1 && messages.first.is_a?(Array)
|
@@ -367,12 +363,13 @@ module Discorb
|
|
367
363
|
|
368
364
|
#
|
369
365
|
# Set the channel's permission overwrite.
|
370
|
-
# @
|
371
|
-
# @macro http
|
366
|
+
# @async
|
372
367
|
#
|
373
368
|
# @param [Discorb::Role, Discorb::Member] target The target of the overwrite.
|
374
369
|
# @param [String] reason The reason of setting the overwrite.
|
375
|
-
# @param [Symbol => Boolean] perms The permission overwrites to replace.
|
370
|
+
# @param [{Symbol => Boolean}] perms The permission overwrites to replace.
|
371
|
+
#
|
372
|
+
# @return [Async::Task<void>] The task.
|
376
373
|
#
|
377
374
|
def set_permissions(target, reason: nil, **perms)
|
378
375
|
Async do
|
@@ -398,12 +395,13 @@ module Discorb
|
|
398
395
|
|
399
396
|
#
|
400
397
|
# Delete the channel's permission overwrite.
|
401
|
-
# @
|
402
|
-
# @macro http
|
398
|
+
# @async
|
403
399
|
#
|
404
400
|
# @param [Discorb::Role, Discorb::Member] target The target of the overwrite.
|
405
401
|
# @param [String] reason The reason of deleting the overwrite.
|
406
402
|
#
|
403
|
+
# @return [Async::Task<void>] The task.
|
404
|
+
#
|
407
405
|
def delete_permissions(target, reason: nil)
|
408
406
|
Async do
|
409
407
|
@client.http.delete("/channels/#{@id}/permissions/#{target.id}", audit_log_reason: reason).wait
|
@@ -416,8 +414,7 @@ module Discorb
|
|
416
414
|
|
417
415
|
#
|
418
416
|
# Fetch the channel's invites.
|
419
|
-
# @
|
420
|
-
# @macro http
|
417
|
+
# @async
|
421
418
|
#
|
422
419
|
# @return [Async::Task<Array<Discorb::Invite>>] The invites in the channel.
|
423
420
|
#
|
@@ -430,8 +427,7 @@ module Discorb
|
|
430
427
|
|
431
428
|
#
|
432
429
|
# Create an invite in the channel.
|
433
|
-
# @
|
434
|
-
# @macro http
|
430
|
+
# @async
|
435
431
|
#
|
436
432
|
# @param [Integer] max_age The max age of the invite.
|
437
433
|
# @param [Integer] max_uses The max uses of the invite.
|
@@ -456,12 +452,13 @@ module Discorb
|
|
456
452
|
|
457
453
|
#
|
458
454
|
# Follow the existing announcement channel.
|
459
|
-
# @
|
460
|
-
# @macro http
|
455
|
+
# @async
|
461
456
|
#
|
462
457
|
# @param [Discorb::NewsChannel] target The channel to follow.
|
463
458
|
# @param [String] reason The reason of following the channel.
|
464
459
|
#
|
460
|
+
# @return [Async::Task<void>] The task.
|
461
|
+
#
|
465
462
|
def follow_from(target, reason: nil)
|
466
463
|
Async do
|
467
464
|
@client.http.post("/channels/#{target.id}/followers", { webhook_channel_id: @id }, audit_log_reason: reason).wait
|
@@ -470,12 +467,13 @@ module Discorb
|
|
470
467
|
|
471
468
|
#
|
472
469
|
# Follow the existing announcement channel from self.
|
473
|
-
# @
|
474
|
-
# @macro http
|
470
|
+
# @async
|
475
471
|
#
|
476
472
|
# @param [Discorb::TextChannel] target The channel to follow to.
|
477
473
|
# @param [String] reason The reason of following the channel.
|
478
474
|
#
|
475
|
+
# @return [Async::Task<void>] The task.
|
476
|
+
#
|
479
477
|
def follow_to(target, reason: nil)
|
480
478
|
Async do
|
481
479
|
@client.http.post("/channels/#{@id}/followers", { webhook_channel_id: target.id }, audit_log_reason: reason).wait
|
@@ -484,24 +482,30 @@ module Discorb
|
|
484
482
|
|
485
483
|
#
|
486
484
|
# Start thread in the channel.
|
487
|
-
# @
|
488
|
-
# @macro http
|
485
|
+
# @async
|
489
486
|
#
|
490
487
|
# @param [String] name The name of the thread.
|
491
488
|
# @param [Discorb::Message] message The message to start the thread.
|
492
489
|
# @param [Integer] auto_archive_duration The duration of auto-archiving.
|
493
490
|
# @param [Boolean] public Whether the thread is public.
|
491
|
+
# @param [Integer] rate_limit_per_user The rate limit per user.
|
492
|
+
# @param [Integer] slowmode Alias of `rate_limit_per_user`.
|
494
493
|
# @param [String] reason The reason of starting the thread.
|
495
494
|
#
|
496
495
|
# @return [Async::Task<Discorb::ThreadChannel>] The started thread.
|
497
496
|
#
|
498
|
-
def start_thread(name, message: nil, auto_archive_duration: 1440, public: true, reason: nil)
|
497
|
+
def start_thread(name, message: nil, auto_archive_duration: 1440, public: true, rate_limit_per_user: nil, slowmode: nil, reason: nil)
|
499
498
|
Async do
|
500
499
|
_resp, data = if message.nil?
|
501
|
-
@client.http.post(
|
502
|
-
|
503
|
-
|
504
|
-
|
500
|
+
@client.http.post(
|
501
|
+
"/channels/#{@id}/threads", {
|
502
|
+
name: name,
|
503
|
+
auto_archive_duration: auto_archive_duration,
|
504
|
+
type: public ? 11 : 10,
|
505
|
+
rate_limit_per_user: rate_limit_per_user || slowmode,
|
506
|
+
},
|
507
|
+
audit_log_reason: reason,
|
508
|
+
).wait
|
505
509
|
else
|
506
510
|
@client.http.post("/channels/#{@id}/messages/#{Utils.try(message, :id)}/threads", {
|
507
511
|
name: name, auto_archive_duration: auto_archive_duration,
|
@@ -515,8 +519,7 @@ module Discorb
|
|
515
519
|
|
516
520
|
#
|
517
521
|
# Fetch archived threads in the channel.
|
518
|
-
# @
|
519
|
-
# @macro http
|
522
|
+
# @async
|
520
523
|
#
|
521
524
|
# @return [Async::Task<Array<Discorb::ThreadChannel>>] The archived threads in the channel.
|
522
525
|
#
|
@@ -529,8 +532,7 @@ module Discorb
|
|
529
532
|
|
530
533
|
#
|
531
534
|
# Fetch archived private threads in the channel.
|
532
|
-
# @
|
533
|
-
# @macro http
|
535
|
+
# @async
|
534
536
|
#
|
535
537
|
# @return [Async::Task<Array<Discorb::ThreadChannel>>] The archived private threads in the channel.
|
536
538
|
#
|
@@ -543,8 +545,7 @@ module Discorb
|
|
543
545
|
|
544
546
|
#
|
545
547
|
# Fetch joined archived private threads in the channel.
|
546
|
-
# @
|
547
|
-
# @macro http
|
548
|
+
# @async
|
548
549
|
#
|
549
550
|
# @param [Integer] limit The limit of threads to fetch.
|
550
551
|
# @param [Time] before <description>
|
@@ -602,13 +603,17 @@ module Discorb
|
|
602
603
|
# @return [nil] If the user limit is not set.
|
603
604
|
attr_reader :user_limit
|
604
605
|
|
606
|
+
# @!attribute [r] members
|
607
|
+
# @return [Array<Discorb::Member>] The members in the voice channel.
|
608
|
+
# @!attribute [r] voice_states
|
609
|
+
# @return [Array<Discorb::VoiceState>] The voice states associated with the voice channel.
|
610
|
+
|
605
611
|
include Connectable
|
606
612
|
|
607
613
|
@channel_type = 2
|
608
614
|
#
|
609
615
|
# Edit the voice channel.
|
610
|
-
# @
|
611
|
-
# @macro http
|
616
|
+
# @async
|
612
617
|
# @macro edit
|
613
618
|
#
|
614
619
|
# @param [String] name The name of the voice channel.
|
@@ -620,14 +625,14 @@ module Discorb
|
|
620
625
|
#
|
621
626
|
# @return [Async::Task<self>] The edited voice channel.
|
622
627
|
#
|
623
|
-
def edit(name:
|
628
|
+
def edit(name: Discorb::Unset, position: Discorb::Unset, bitrate: Discorb::Unset, user_limit: Discorb::Unset, rtc_region: Discorb::Unset, reason: nil)
|
624
629
|
Async do
|
625
630
|
payload = {}
|
626
|
-
payload[:name] = name if name !=
|
627
|
-
payload[:position] = position if position !=
|
628
|
-
payload[:bitrate] = bitrate if bitrate !=
|
629
|
-
payload[:user_limit] = user_limit if user_limit !=
|
630
|
-
payload[:rtc_region] = rtc_region if rtc_region !=
|
631
|
+
payload[:name] = name if name != Discorb::Unset
|
632
|
+
payload[:position] = position if position != Discorb::Unset
|
633
|
+
payload[:bitrate] = bitrate if bitrate != Discorb::Unset
|
634
|
+
payload[:user_limit] = user_limit if user_limit != Discorb::Unset
|
635
|
+
payload[:rtc_region] = rtc_region if rtc_region != Discorb::Unset
|
631
636
|
|
632
637
|
@client.http.patch("/channels/#{@id}", payload, audit_log_reason: reason).wait
|
633
638
|
self
|
@@ -636,6 +641,14 @@ module Discorb
|
|
636
641
|
|
637
642
|
alias modify edit
|
638
643
|
|
644
|
+
def voice_states
|
645
|
+
guild.voice_states.select { |state| state.channel&.id == @id }
|
646
|
+
end
|
647
|
+
|
648
|
+
def members
|
649
|
+
voice_states.map(&:member)
|
650
|
+
end
|
651
|
+
|
639
652
|
private
|
640
653
|
|
641
654
|
def _set_data(data)
|
@@ -676,8 +689,7 @@ module Discorb
|
|
676
689
|
|
677
690
|
#
|
678
691
|
# Edit the stage channel.
|
679
|
-
# @
|
680
|
-
# @macro http
|
692
|
+
# @async
|
681
693
|
# @macro edit
|
682
694
|
#
|
683
695
|
# @param [String] name The name of the stage channel.
|
@@ -688,13 +700,13 @@ module Discorb
|
|
688
700
|
#
|
689
701
|
# @return [Async::Task<self>] The edited stage channel.
|
690
702
|
#
|
691
|
-
def edit(name:
|
703
|
+
def edit(name: Discorb::Unset, position: Discorb::Unset, bitrate: Discorb::Unset, rtc_region: Discorb::Unset, reason: nil)
|
692
704
|
Async do
|
693
705
|
payload = {}
|
694
|
-
payload[:name] = name if name !=
|
695
|
-
payload[:position] = position if position !=
|
696
|
-
payload[:bitrate] = bitrate if bitrate !=
|
697
|
-
payload[:rtc_region] = rtc_region if rtc_region !=
|
706
|
+
payload[:name] = name if name != Discorb::Unset
|
707
|
+
payload[:position] = position if position != Discorb::Unset
|
708
|
+
payload[:bitrate] = bitrate if bitrate != Discorb::Unset
|
709
|
+
payload[:rtc_region] = rtc_region if rtc_region != Discorb::Unset
|
698
710
|
@client.http.patch("/channels/#{@id}", payload, audit_log_reason: reason).wait
|
699
711
|
self
|
700
712
|
end
|
@@ -704,8 +716,7 @@ module Discorb
|
|
704
716
|
|
705
717
|
#
|
706
718
|
# Start a stage instance.
|
707
|
-
# @
|
708
|
-
# @macro http
|
719
|
+
# @async
|
709
720
|
#
|
710
721
|
# @param [String] topic The topic of the stage instance.
|
711
722
|
# @param [Boolean] public Whether the stage instance is public or not.
|
@@ -722,8 +733,7 @@ module Discorb
|
|
722
733
|
|
723
734
|
#
|
724
735
|
# Fetch a current stage instance.
|
725
|
-
# @
|
726
|
-
# @macro http
|
736
|
+
# @async
|
727
737
|
#
|
728
738
|
# @return [Async::Task<StageInstance>] The current stage instance.
|
729
739
|
# @return [Async::Task<nil>] If there is no current stage instance.
|
@@ -738,6 +748,22 @@ module Discorb
|
|
738
748
|
end
|
739
749
|
end
|
740
750
|
|
751
|
+
def voice_states
|
752
|
+
guild.voice_states.select { |state| state.channel&.id == @id }
|
753
|
+
end
|
754
|
+
|
755
|
+
def members
|
756
|
+
voice_states.map(&:member)
|
757
|
+
end
|
758
|
+
|
759
|
+
def speakers
|
760
|
+
voice_states.filter { |state| !state.suppress? }.map(&:member)
|
761
|
+
end
|
762
|
+
|
763
|
+
def audiences
|
764
|
+
voice_states.filter { |state| state.suppress? }.map(&:member)
|
765
|
+
end
|
766
|
+
|
741
767
|
private
|
742
768
|
|
743
769
|
def _set_data(data)
|
@@ -785,6 +811,18 @@ module Discorb
|
|
785
811
|
# @!attribute [r] parent
|
786
812
|
# @macro client_cache
|
787
813
|
# @return [Discorb::GuildChannel] The parent channel of the thread.
|
814
|
+
# @!attribute [r] me
|
815
|
+
# @return [Discorb::ThreadChannel::Member] The bot's member in the thread.
|
816
|
+
# @return [nil] If the bot is not in the thread.
|
817
|
+
# @!attribute [r] joined?
|
818
|
+
# @return [Boolean] Whether the bot is in the thread or not.
|
819
|
+
# @!attribute [r] guild
|
820
|
+
# @macro client_cache
|
821
|
+
# @return [Discorb::Guild] The guild of the thread.
|
822
|
+
# @!attribute [r] owner
|
823
|
+
# @macro client_cache
|
824
|
+
# @macro members_intent
|
825
|
+
# @return [Discorb::Member] The owner of the thread.
|
788
826
|
|
789
827
|
include Messageable
|
790
828
|
@channel_type = nil
|
@@ -800,8 +838,7 @@ module Discorb
|
|
800
838
|
|
801
839
|
#
|
802
840
|
# Edit the thread.
|
803
|
-
# @
|
804
|
-
# @macro http
|
841
|
+
# @async
|
805
842
|
# @macro edit
|
806
843
|
#
|
807
844
|
# @param [String] name The name of the thread.
|
@@ -818,14 +855,14 @@ module Discorb
|
|
818
855
|
# @see #unarchive
|
819
856
|
# @see #unlock
|
820
857
|
#
|
821
|
-
def edit(name:
|
858
|
+
def edit(name: Discorb::Unset, archived: Discorb::Unset, auto_archive_duration: Discorb::Unset, archive_in: Discorb::Unset, locked: Discorb::Unset, reason: nil)
|
822
859
|
Async do
|
823
860
|
payload = {}
|
824
|
-
payload[:name] = name if name !=
|
825
|
-
payload[:archived] = archived if archived !=
|
861
|
+
payload[:name] = name if name != Discorb::Unset
|
862
|
+
payload[:archived] = archived if archived != Discorb::Unset
|
826
863
|
auto_archive_duration ||= archive_in
|
827
|
-
payload[:auto_archive_duration] = auto_archive_duration if auto_archive_duration !=
|
828
|
-
payload[:locked] = locked if locked !=
|
864
|
+
payload[:auto_archive_duration] = auto_archive_duration if auto_archive_duration != Discorb::Unset
|
865
|
+
payload[:locked] = locked if locked != Discorb::Unset
|
829
866
|
@client.http.patch("/channels/#{@id}", payload, audit_log_reason: reason).wait
|
830
867
|
self
|
831
868
|
end
|
@@ -890,7 +927,7 @@ module Discorb
|
|
890
927
|
end
|
891
928
|
|
892
929
|
def joined?
|
893
|
-
|
930
|
+
!!me
|
894
931
|
end
|
895
932
|
|
896
933
|
def guild
|
@@ -905,6 +942,13 @@ module Discorb
|
|
905
942
|
"#<#{self.class} \"##{@name}\" id=#{@id}>"
|
906
943
|
end
|
907
944
|
|
945
|
+
#
|
946
|
+
# Add a member to the thread.
|
947
|
+
#
|
948
|
+
# @param [Discorb::Member, :me] member The member to add. If `:me` is given, the bot will be added.
|
949
|
+
#
|
950
|
+
# @return [Async::Task<void>] The task.
|
951
|
+
#
|
908
952
|
def add_member(member = :me)
|
909
953
|
Async do
|
910
954
|
if member == :me
|
@@ -917,6 +961,13 @@ module Discorb
|
|
917
961
|
|
918
962
|
alias join add_member
|
919
963
|
|
964
|
+
#
|
965
|
+
# Remove a member from the thread.
|
966
|
+
#
|
967
|
+
# @param [Discorb::Member, :me] member The member to remove. If `:me` is given, the bot will be removed.
|
968
|
+
#
|
969
|
+
# @return [Async::Task<void>] The task.
|
970
|
+
#
|
920
971
|
def remove_member(member = :me)
|
921
972
|
Async do
|
922
973
|
if member == :me
|
@@ -929,6 +980,11 @@ module Discorb
|
|
929
980
|
|
930
981
|
alias leave remove_member
|
931
982
|
|
983
|
+
#
|
984
|
+
# Fetch members in the thread.
|
985
|
+
#
|
986
|
+
# @return [Array<Discorb::ThreadChannel::Member>] The members in the thread.
|
987
|
+
#
|
932
988
|
def fetch_members
|
933
989
|
Async do
|
934
990
|
_resp, data = @client.http.get("/channels/#{@id}/thread-members").wait
|
@@ -952,6 +1008,9 @@ module Discorb
|
|
952
1008
|
attr_reader :channel_type
|
953
1009
|
end
|
954
1010
|
|
1011
|
+
#
|
1012
|
+
# Repre
|
1013
|
+
#
|
955
1014
|
class Member < DiscordModel
|
956
1015
|
attr_reader :joined_at
|
957
1016
|
|