discorb 0.18.0 → 0.20.0
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_version.yml +2 -2
- data/.rubocop.yml +12 -75
- data/Changelog.md +25 -0
- data/Gemfile +4 -4
- data/README.md +2 -1
- data/Rakefile +482 -459
- data/Steepfile +8 -6
- data/docs/application_command.md +1 -0
- data/docs/events.md +2 -2
- data/docs/voice_events.md +6 -6
- data/lib/discorb/allowed_mentions.rb +68 -72
- data/lib/discorb/app_command/command.rb +466 -394
- data/lib/discorb/app_command/common.rb +65 -25
- data/lib/discorb/app_command/handler.rb +304 -265
- data/lib/discorb/app_command.rb +5 -5
- data/lib/discorb/application.rb +198 -197
- data/lib/discorb/asset.rb +101 -101
- data/lib/discorb/attachment.rb +134 -119
- data/lib/discorb/audit_logs.rb +412 -385
- data/lib/discorb/automod.rb +279 -269
- data/lib/discorb/channel/base.rb +107 -108
- data/lib/discorb/channel/category.rb +32 -32
- data/lib/discorb/channel/container.rb +44 -44
- data/lib/discorb/channel/dm.rb +26 -28
- data/lib/discorb/channel/guild.rb +311 -246
- data/lib/discorb/channel/stage.rb +156 -140
- data/lib/discorb/channel/text.rb +430 -336
- data/lib/discorb/channel/thread.rb +374 -325
- data/lib/discorb/channel/voice.rb +85 -79
- data/lib/discorb/channel.rb +5 -5
- data/lib/discorb/client.rb +635 -623
- data/lib/discorb/color.rb +178 -182
- data/lib/discorb/common.rb +168 -164
- data/lib/discorb/components/button.rb +107 -106
- data/lib/discorb/components/select_menu.rb +157 -145
- data/lib/discorb/components/text_input.rb +103 -106
- data/lib/discorb/components.rb +68 -66
- data/lib/discorb/dictionary.rb +135 -135
- data/lib/discorb/embed.rb +404 -398
- data/lib/discorb/emoji.rb +309 -302
- data/lib/discorb/emoji_table.rb +16099 -8857
- data/lib/discorb/error.rb +131 -131
- data/lib/discorb/event.rb +360 -314
- data/lib/discorb/event_handler.rb +39 -39
- data/lib/discorb/exe/about.rb +17 -17
- data/lib/discorb/exe/irb.rb +72 -67
- data/lib/discorb/exe/new.rb +323 -315
- data/lib/discorb/exe/run.rb +69 -68
- data/lib/discorb/exe/setup.rb +57 -55
- data/lib/discorb/exe/show.rb +12 -12
- data/lib/discorb/extend.rb +25 -45
- data/lib/discorb/extension.rb +89 -83
- data/lib/discorb/flag.rb +126 -128
- data/lib/discorb/gateway.rb +984 -794
- data/lib/discorb/gateway_events.rb +670 -638
- data/lib/discorb/gateway_requests.rb +45 -48
- data/lib/discorb/guild.rb +2115 -1626
- data/lib/discorb/guild_template.rb +280 -241
- data/lib/discorb/http.rb +247 -232
- data/lib/discorb/image.rb +42 -42
- data/lib/discorb/integration.rb +169 -161
- data/lib/discorb/intents.rb +161 -163
- data/lib/discorb/interaction/autocomplete.rb +76 -62
- data/lib/discorb/interaction/command.rb +279 -224
- data/lib/discorb/interaction/components.rb +114 -104
- data/lib/discorb/interaction/modal.rb +36 -32
- data/lib/discorb/interaction/response.rb +379 -330
- data/lib/discorb/interaction/root.rb +271 -118
- data/lib/discorb/interaction.rb +5 -5
- data/lib/discorb/invite.rb +154 -153
- data/lib/discorb/member.rb +344 -311
- data/lib/discorb/message.rb +615 -544
- data/lib/discorb/message_meta.rb +197 -186
- data/lib/discorb/modules.rb +371 -290
- data/lib/discorb/permission.rb +305 -289
- data/lib/discorb/presence.rb +352 -346
- data/lib/discorb/rate_limit.rb +81 -76
- data/lib/discorb/reaction.rb +55 -54
- data/lib/discorb/role.rb +272 -240
- data/lib/discorb/shard.rb +76 -74
- data/lib/discorb/sticker.rb +193 -171
- data/lib/discorb/user.rb +205 -188
- data/lib/discorb/utils/colored_puts.rb +16 -16
- data/lib/discorb/utils.rb +12 -16
- data/lib/discorb/voice_state.rb +305 -281
- data/lib/discorb/webhook.rb +537 -507
- data/lib/discorb.rb +62 -56
- data/sig/discorb/activity.rbs +1 -0
- data/sig/discorb/allowed_mentions.rbs +1 -0
- data/sig/discorb/app_command/base.rbs +7 -1
- data/sig/discorb/application.rbs +6 -0
- data/sig/discorb/asset.rbs +2 -0
- data/sig/discorb/attachment.rbs +8 -0
- data/sig/discorb/audit_log.rbs +7 -0
- data/sig/discorb/automod.rbs +32 -6
- data/sig/discorb/avatar.rbs +1 -0
- data/sig/discorb/channel/base.rbs +8 -1
- data/sig/discorb/channel/category.rbs +1 -0
- data/sig/discorb/channel/container.rbs +4 -0
- data/sig/discorb/channel/stage.rbs +4 -0
- data/sig/discorb/channel/text.rbs +2 -2
- data/sig/discorb/channel/thread.rbs +11 -0
- data/sig/discorb/channel/voice.rbs +2 -0
- data/sig/discorb/client.rbs +21 -20
- data/sig/discorb/color.rbs +6 -0
- data/sig/discorb/component/base.rbs +1 -0
- data/sig/discorb/component/button.rbs +2 -0
- data/sig/discorb/component/select_menu.rbs +4 -0
- data/sig/discorb/component/text_input.rbs +1 -0
- data/sig/discorb/custom_emoji.rbs +5 -1
- data/sig/discorb/dictionary.rbs +2 -0
- data/sig/discorb/discord_model.rbs +2 -0
- data/sig/discorb/embed.rbs +7 -0
- data/sig/discorb/emoji.rbs +1 -0
- data/sig/discorb/event_handler.rbs +2 -1
- data/sig/discorb/extension.rbs +13 -12
- data/sig/discorb/flag.rbs +2 -0
- data/sig/discorb/gateway.rbs +5 -0
- data/sig/discorb/guild.rbs +8 -4
- data/sig/discorb/guild_template.rbs +1 -1
- data/sig/discorb/http.rbs +4 -1
- data/sig/discorb/image.rbs +2 -0
- data/sig/discorb/integration.rbs +1 -1
- data/sig/discorb/intents.rbs +4 -3
- data/sig/discorb/interaction/base.rbs +36 -0
- data/sig/discorb/interaction/message_component.rbs +1 -2
- data/sig/discorb/interaction/modal.rbs +1 -2
- data/sig/discorb/interaction/responder.rbs +49 -49
- data/sig/discorb/invite.rbs +1 -1
- data/sig/discorb/member.rbs +2 -0
- data/sig/discorb/message.rbs +8 -1
- data/sig/discorb/messageable.rbs +1 -4
- data/sig/discorb/partial_emoji.rbs +3 -0
- data/sig/discorb/permissions.rbs +7 -0
- data/sig/discorb/presence.rbs +2 -0
- data/sig/discorb/reaction.rbs +5 -1
- data/sig/discorb/role.rbs +7 -1
- data/sig/discorb/scheduled_event.rbs +2 -1
- data/sig/discorb/shard.rbs +2 -1
- data/sig/discorb/snowflake.rbs +2 -0
- data/sig/discorb/stage_instance.rbs +9 -3
- data/sig/discorb/sticker.rbs +1 -1
- data/sig/discorb/unicode_emoji.rbs +4 -0
- data/sig/discorb/user.rbs +24 -20
- data/sig/discorb/webhook.rbs +17 -6
- data/sig/discorb/welcome_screen.rbs +1 -0
- data/sig/override.rbs +2 -0
- metadata +3 -3
data/lib/discorb/guild.rb
CHANGED
@@ -1,1626 +1,2115 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Represents a guild in the Discord.
|
6
|
-
#
|
7
|
-
class Guild < DiscordModel
|
8
|
-
# @return [Discorb::Snowflake] ID of the guild.
|
9
|
-
attr_reader :id
|
10
|
-
# @return [String] The name of the guild.
|
11
|
-
attr_reader :name
|
12
|
-
# @return [Discorb::Asset] The splash of the guild.
|
13
|
-
attr_reader :splash
|
14
|
-
# @return [Discorb::Asset] The discovery splash of the guild.
|
15
|
-
attr_reader :discovery_splash
|
16
|
-
# @return [Discorb::Snowflake] ID of the guild owner.
|
17
|
-
attr_reader :owner_id
|
18
|
-
# @return [Discorb::Permission] The bot's permission in the guild.
|
19
|
-
attr_reader :permissions
|
20
|
-
# @return [Integer] The AFK timeout of the guild.
|
21
|
-
attr_reader :afk_timeout
|
22
|
-
# @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::Role}] A dictionary of roles in the guild.
|
23
|
-
attr_reader :roles
|
24
|
-
# @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}]
|
25
|
-
# A dictionary of custom emojis in the guild.
|
26
|
-
attr_reader :emojis
|
27
|
-
# @return [Array<Symbol>] features that are enabled in the guild.
|
28
|
-
# @see https://discord.com/developers/docs/resources/guild#guild-object-guild-features Official Discord API docs
|
29
|
-
attr_reader :features
|
30
|
-
# @return [:none, :elevated] The MFA level of the guild.
|
31
|
-
attr_reader :mfa_level
|
32
|
-
# @return [Discorb::SystemChannelFlag] The flag for the system channel.
|
33
|
-
attr_reader :system_channel_flags
|
34
|
-
# @return [Time] Time that representing when bot has joined the guild.
|
35
|
-
attr_reader :joined_at
|
36
|
-
# @return [Boolean] Whether the guild is unavailable.
|
37
|
-
attr_reader :unavailable
|
38
|
-
# @return [Integer] The amount of members in the guild.
|
39
|
-
attr_reader :member_count
|
40
|
-
# @return [Discorb::Asset] The icon of the guild.
|
41
|
-
attr_reader :icon
|
42
|
-
# @return [Discorb::Dictionary{Discorb::User => Discorb::VoiceState}] A dictionary of voice states in the guild.
|
43
|
-
attr_reader :voice_states
|
44
|
-
# @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::Member}] A dictionary of members in the guild.
|
45
|
-
# @macro members_intent
|
46
|
-
attr_reader :members
|
47
|
-
# @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::GuildChannel}] A dictionary of channels in the guild.
|
48
|
-
attr_reader :channels
|
49
|
-
# @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::ThreadChannel}] A dictionary of threads in the guild.
|
50
|
-
attr_reader :threads
|
51
|
-
# @return [Discorb::Dictionary{Discorb::User => Discorb::Presence}] A dictionary of presence in the guild.
|
52
|
-
attr_reader :presences
|
53
|
-
# @return [Integer] Number of online members in the guild.
|
54
|
-
attr_reader :max_presences
|
55
|
-
# @return [String] The vanity invite URL for the guild.
|
56
|
-
# @return [nil] If the guild does not have a vanity invite URL.
|
57
|
-
attr_reader :vanity_url_code
|
58
|
-
# @return [String] The description of the guild.
|
59
|
-
attr_reader :description
|
60
|
-
# @return [Discorb::Asset] The banner of the guild.
|
61
|
-
# @return [nil] If the guild does not have a banner.
|
62
|
-
attr_reader :banner
|
63
|
-
# @return [Integer] The premium tier (Boost Level) of the guild.
|
64
|
-
attr_reader :premium_tier
|
65
|
-
# @return [Integer] The amount of premium subscriptions (Server Boosts) the guild has.
|
66
|
-
attr_reader :premium_subscription_count
|
67
|
-
# @return [Symbol] The preffered language of the guild.
|
68
|
-
# @note This modifies the language code, `-` will be replaced with `_`.
|
69
|
-
attr_reader :preferred_locale
|
70
|
-
# @return [Integer] The maximum amount of users in a video channel.
|
71
|
-
attr_reader :max_video_channel_users
|
72
|
-
# @return [Integer] The approxmate amount of members in the guild.
|
73
|
-
attr_reader :approximate_member_count
|
74
|
-
# @return [Integer] The approxmate amount of non-offline members in the guild.
|
75
|
-
attr_reader :approximate_presence_count
|
76
|
-
# @return [Discorb::WelcomeScreen] The welcome screen of the guild.
|
77
|
-
attr_reader :welcome_screen
|
78
|
-
# @return [:default, :explicit, :safe, :age_restricted] The nsfw level of the guild.
|
79
|
-
attr_reader :nsfw_level
|
80
|
-
# @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::StageInstance}]
|
81
|
-
# A dictionary of stage instances in the guild.
|
82
|
-
attr_reader :stage_instances
|
83
|
-
# @return [:none, :low, :medium, :high, :very_high] The verification level of the guild.
|
84
|
-
attr_reader :verification_level
|
85
|
-
# @return [:all_messages, :only_mentions] The default message notification level of the guild.
|
86
|
-
attr_reader :default_message_notifications
|
87
|
-
# @return [:disabled_in_text, :members_without_roles, :all_members] The explict content filter level of the guild.
|
88
|
-
attr_reader :explicit_content_filter
|
89
|
-
# @return [Boolean] Whether the client is the owner of the guild.
|
90
|
-
attr_reader :owner
|
91
|
-
alias owner? owner
|
92
|
-
# @return [Boolean] Whether the guild is large.
|
93
|
-
attr_reader :large
|
94
|
-
alias large? large
|
95
|
-
# @return [Boolean] Whether the guild enabled the widget.
|
96
|
-
attr_reader :widget_enabled
|
97
|
-
alias widget_enabled? widget_enabled
|
98
|
-
# @return [Boolean] Whether the guild is available.
|
99
|
-
attr_reader :available
|
100
|
-
alias available? available
|
101
|
-
# @return [Dictionary{Discorb::Snowflake => Discorb::ScheduledEvent}] A dictionary of scheduled events in the guild.
|
102
|
-
attr_reader :scheduled_events
|
103
|
-
alias events scheduled_events
|
104
|
-
|
105
|
-
include Discorb::ChannelContainer
|
106
|
-
|
107
|
-
# @!attribute [r] afk_channel
|
108
|
-
# @return [Discorb::VoiceChannel] The AFK channel for this guild.
|
109
|
-
# @macro client_cache
|
110
|
-
# @!attribute [r] system_channel
|
111
|
-
# @return [Discorb::TextChannel] The system message channel for this guild.
|
112
|
-
# @macro client_cache
|
113
|
-
# @!attribute [r] rules_channel
|
114
|
-
# @return [Discorb::TextChannel] The rules channel for this guild.
|
115
|
-
# @macro client_cache
|
116
|
-
# @!attribute [r] public_updates_channel
|
117
|
-
# @return [Discorb::TextChannel] The public updates channel (`#moderator-only`) for this guild.
|
118
|
-
# @macro client_cache
|
119
|
-
# @!attribute [r] me
|
120
|
-
# @return [Discorb::Member] The client's member in the guild.
|
121
|
-
|
122
|
-
# @private
|
123
|
-
# @return [Array<Symbol>] The mapping of mfa_level.
|
124
|
-
MFA_LEVELS = %i[none elevated].freeze
|
125
|
-
# @private
|
126
|
-
# @return [Array<Symbol>] The mapping of nsfw_level.
|
127
|
-
NSFW_LEVELS = %i[default explicit safe age_restricted].freeze
|
128
|
-
# @private
|
129
|
-
# @return [Array<Symbol>] The mapping of verification_level.
|
130
|
-
VERIFICATION_LEVELS = %i[none low medium high very_high].freeze
|
131
|
-
# @private
|
132
|
-
# @return [Array<Symbol>] The mapping of default_message_notifications.
|
133
|
-
DEFAULT_MESSAGE_NOTIFICATIONS = %i[all_messages only_mentions].freeze
|
134
|
-
# @private
|
135
|
-
# @return [Array<Symbol>] The mapping of explicit_content_filter.
|
136
|
-
EXPLICIT_CONTENT_FILTER = %i[
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
#
|
143
|
-
#
|
144
|
-
# @
|
145
|
-
#
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
end
|
155
|
-
|
156
|
-
def
|
157
|
-
@client.channels[@
|
158
|
-
end
|
159
|
-
|
160
|
-
def
|
161
|
-
@client.channels[@
|
162
|
-
end
|
163
|
-
|
164
|
-
def
|
165
|
-
@client.channels[@
|
166
|
-
end
|
167
|
-
|
168
|
-
def
|
169
|
-
|
170
|
-
end
|
171
|
-
|
172
|
-
def
|
173
|
-
@
|
174
|
-
end
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
#
|
181
|
-
#
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
#
|
234
|
-
#
|
235
|
-
# @
|
236
|
-
#
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
{
|
289
|
-
name: name,
|
290
|
-
description: description,
|
291
|
-
scheduled_start_time: start_time.iso8601,
|
292
|
-
scheduled_end_time: end_time
|
293
|
-
privacy_level:
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
}
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
#
|
356
|
-
#
|
357
|
-
# @async
|
358
|
-
#
|
359
|
-
#
|
360
|
-
# @
|
361
|
-
#
|
362
|
-
#
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
#
|
394
|
-
#
|
395
|
-
#
|
396
|
-
#
|
397
|
-
#
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
#
|
422
|
-
#
|
423
|
-
# @
|
424
|
-
#
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
#
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
# Create a new
|
518
|
-
# @async
|
519
|
-
#
|
520
|
-
# @param [String] name The name of the channel.
|
521
|
-
# @param [
|
522
|
-
# @param [
|
523
|
-
#
|
524
|
-
# @param [
|
525
|
-
# @param [
|
526
|
-
#
|
527
|
-
#
|
528
|
-
#
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
#
|
591
|
-
#
|
592
|
-
# @
|
593
|
-
#
|
594
|
-
#
|
595
|
-
# @param [
|
596
|
-
# @param [
|
597
|
-
#
|
598
|
-
# @
|
599
|
-
#
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
#
|
647
|
-
# @
|
648
|
-
#
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
#
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
#
|
759
|
-
#
|
760
|
-
# @
|
761
|
-
#
|
762
|
-
# @
|
763
|
-
#
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
#
|
827
|
-
#
|
828
|
-
#
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
#
|
855
|
-
#
|
856
|
-
# @
|
857
|
-
#
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
)
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
#
|
880
|
-
#
|
881
|
-
#
|
882
|
-
#
|
883
|
-
# @param [
|
884
|
-
#
|
885
|
-
#
|
886
|
-
#
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
#
|
934
|
-
#
|
935
|
-
# @
|
936
|
-
#
|
937
|
-
# @
|
938
|
-
#
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
#
|
959
|
-
#
|
960
|
-
# @
|
961
|
-
#
|
962
|
-
#
|
963
|
-
# @return [Async::Task<
|
964
|
-
#
|
965
|
-
def
|
966
|
-
Async
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
#
|
974
|
-
#
|
975
|
-
#
|
976
|
-
#
|
977
|
-
#
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
#
|
1000
|
-
#
|
1001
|
-
# @async
|
1002
|
-
#
|
1003
|
-
# @
|
1004
|
-
#
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
#
|
1027
|
-
#
|
1028
|
-
#
|
1029
|
-
#
|
1030
|
-
# @
|
1031
|
-
#
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
#
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
#
|
1090
|
-
#
|
1091
|
-
#
|
1092
|
-
#
|
1093
|
-
#
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
#
|
1103
|
-
#
|
1104
|
-
#
|
1105
|
-
# @
|
1106
|
-
# @
|
1107
|
-
#
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
#
|
1134
|
-
#
|
1135
|
-
# @
|
1136
|
-
#
|
1137
|
-
# @return [Async::Task<
|
1138
|
-
#
|
1139
|
-
def
|
1140
|
-
Async do
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
#
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
#
|
1180
|
-
#
|
1181
|
-
# @
|
1182
|
-
#
|
1183
|
-
# @param [String]
|
1184
|
-
#
|
1185
|
-
# @
|
1186
|
-
#
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
payload =
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
#
|
1228
|
-
#
|
1229
|
-
#
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
#
|
1260
|
-
#
|
1261
|
-
#
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
#
|
1496
|
-
|
1497
|
-
# @return [Discorb::
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
#
|
1505
|
-
#
|
1506
|
-
#
|
1507
|
-
#
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
(
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
)
|
1529
|
-
end
|
1530
|
-
end
|
1531
|
-
|
1532
|
-
#
|
1533
|
-
#
|
1534
|
-
#
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
1547
|
-
|
1548
|
-
|
1549
|
-
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Represents a guild in the Discord.
|
6
|
+
#
|
7
|
+
class Guild < DiscordModel
|
8
|
+
# @return [Discorb::Snowflake] ID of the guild.
|
9
|
+
attr_reader :id
|
10
|
+
# @return [String] The name of the guild.
|
11
|
+
attr_reader :name
|
12
|
+
# @return [Discorb::Asset] The splash of the guild.
|
13
|
+
attr_reader :splash
|
14
|
+
# @return [Discorb::Asset] The discovery splash of the guild.
|
15
|
+
attr_reader :discovery_splash
|
16
|
+
# @return [Discorb::Snowflake] ID of the guild owner.
|
17
|
+
attr_reader :owner_id
|
18
|
+
# @return [Discorb::Permission] The bot's permission in the guild.
|
19
|
+
attr_reader :permissions
|
20
|
+
# @return [Integer] The AFK timeout of the guild.
|
21
|
+
attr_reader :afk_timeout
|
22
|
+
# @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::Role}] A dictionary of roles in the guild.
|
23
|
+
attr_reader :roles
|
24
|
+
# @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}]
|
25
|
+
# A dictionary of custom emojis in the guild.
|
26
|
+
attr_reader :emojis
|
27
|
+
# @return [Array<Symbol>] features that are enabled in the guild.
|
28
|
+
# @see https://discord.com/developers/docs/resources/guild#guild-object-guild-features Official Discord API docs
|
29
|
+
attr_reader :features
|
30
|
+
# @return [:none, :elevated] The MFA level of the guild.
|
31
|
+
attr_reader :mfa_level
|
32
|
+
# @return [Discorb::SystemChannelFlag] The flag for the system channel.
|
33
|
+
attr_reader :system_channel_flags
|
34
|
+
# @return [Time] Time that representing when bot has joined the guild.
|
35
|
+
attr_reader :joined_at
|
36
|
+
# @return [Boolean] Whether the guild is unavailable.
|
37
|
+
attr_reader :unavailable
|
38
|
+
# @return [Integer] The amount of members in the guild.
|
39
|
+
attr_reader :member_count
|
40
|
+
# @return [Discorb::Asset] The icon of the guild.
|
41
|
+
attr_reader :icon
|
42
|
+
# @return [Discorb::Dictionary{Discorb::User => Discorb::VoiceState}] A dictionary of voice states in the guild.
|
43
|
+
attr_reader :voice_states
|
44
|
+
# @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::Member}] A dictionary of members in the guild.
|
45
|
+
# @macro members_intent
|
46
|
+
attr_reader :members
|
47
|
+
# @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::GuildChannel}] A dictionary of channels in the guild.
|
48
|
+
attr_reader :channels
|
49
|
+
# @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::ThreadChannel}] A dictionary of threads in the guild.
|
50
|
+
attr_reader :threads
|
51
|
+
# @return [Discorb::Dictionary{Discorb::User => Discorb::Presence}] A dictionary of presence in the guild.
|
52
|
+
attr_reader :presences
|
53
|
+
# @return [Integer] Number of online members in the guild.
|
54
|
+
attr_reader :max_presences
|
55
|
+
# @return [String] The vanity invite URL for the guild.
|
56
|
+
# @return [nil] If the guild does not have a vanity invite URL.
|
57
|
+
attr_reader :vanity_url_code
|
58
|
+
# @return [String] The description of the guild.
|
59
|
+
attr_reader :description
|
60
|
+
# @return [Discorb::Asset] The banner of the guild.
|
61
|
+
# @return [nil] If the guild does not have a banner.
|
62
|
+
attr_reader :banner
|
63
|
+
# @return [Integer] The premium tier (Boost Level) of the guild.
|
64
|
+
attr_reader :premium_tier
|
65
|
+
# @return [Integer] The amount of premium subscriptions (Server Boosts) the guild has.
|
66
|
+
attr_reader :premium_subscription_count
|
67
|
+
# @return [Symbol] The preffered language of the guild.
|
68
|
+
# @note This modifies the language code, `-` will be replaced with `_`.
|
69
|
+
attr_reader :preferred_locale
|
70
|
+
# @return [Integer] The maximum amount of users in a video channel.
|
71
|
+
attr_reader :max_video_channel_users
|
72
|
+
# @return [Integer] The approxmate amount of members in the guild.
|
73
|
+
attr_reader :approximate_member_count
|
74
|
+
# @return [Integer] The approxmate amount of non-offline members in the guild.
|
75
|
+
attr_reader :approximate_presence_count
|
76
|
+
# @return [Discorb::WelcomeScreen] The welcome screen of the guild.
|
77
|
+
attr_reader :welcome_screen
|
78
|
+
# @return [:default, :explicit, :safe, :age_restricted] The nsfw level of the guild.
|
79
|
+
attr_reader :nsfw_level
|
80
|
+
# @return [Discorb::Dictionary{Discorb::Snowflake => Discorb::StageInstance}]
|
81
|
+
# A dictionary of stage instances in the guild.
|
82
|
+
attr_reader :stage_instances
|
83
|
+
# @return [:none, :low, :medium, :high, :very_high] The verification level of the guild.
|
84
|
+
attr_reader :verification_level
|
85
|
+
# @return [:all_messages, :only_mentions] The default message notification level of the guild.
|
86
|
+
attr_reader :default_message_notifications
|
87
|
+
# @return [:disabled_in_text, :members_without_roles, :all_members] The explict content filter level of the guild.
|
88
|
+
attr_reader :explicit_content_filter
|
89
|
+
# @return [Boolean] Whether the client is the owner of the guild.
|
90
|
+
attr_reader :owner
|
91
|
+
alias owner? owner
|
92
|
+
# @return [Boolean] Whether the guild is large.
|
93
|
+
attr_reader :large
|
94
|
+
alias large? large
|
95
|
+
# @return [Boolean] Whether the guild enabled the widget.
|
96
|
+
attr_reader :widget_enabled
|
97
|
+
alias widget_enabled? widget_enabled
|
98
|
+
# @return [Boolean] Whether the guild is available.
|
99
|
+
attr_reader :available
|
100
|
+
alias available? available
|
101
|
+
# @return [Dictionary{Discorb::Snowflake => Discorb::ScheduledEvent}] A dictionary of scheduled events in the guild.
|
102
|
+
attr_reader :scheduled_events
|
103
|
+
alias events scheduled_events
|
104
|
+
|
105
|
+
include Discorb::ChannelContainer
|
106
|
+
|
107
|
+
# @!attribute [r] afk_channel
|
108
|
+
# @return [Discorb::VoiceChannel] The AFK channel for this guild.
|
109
|
+
# @macro client_cache
|
110
|
+
# @!attribute [r] system_channel
|
111
|
+
# @return [Discorb::TextChannel] The system message channel for this guild.
|
112
|
+
# @macro client_cache
|
113
|
+
# @!attribute [r] rules_channel
|
114
|
+
# @return [Discorb::TextChannel] The rules channel for this guild.
|
115
|
+
# @macro client_cache
|
116
|
+
# @!attribute [r] public_updates_channel
|
117
|
+
# @return [Discorb::TextChannel] The public updates channel (`#moderator-only`) for this guild.
|
118
|
+
# @macro client_cache
|
119
|
+
# @!attribute [r] me
|
120
|
+
# @return [Discorb::Member] The client's member in the guild.
|
121
|
+
|
122
|
+
# @private
|
123
|
+
# @return [Array<Symbol>] The mapping of mfa_level.
|
124
|
+
MFA_LEVELS = %i[none elevated].freeze
|
125
|
+
# @private
|
126
|
+
# @return [Array<Symbol>] The mapping of nsfw_level.
|
127
|
+
NSFW_LEVELS = %i[default explicit safe age_restricted].freeze
|
128
|
+
# @private
|
129
|
+
# @return [Array<Symbol>] The mapping of verification_level.
|
130
|
+
VERIFICATION_LEVELS = %i[none low medium high very_high].freeze
|
131
|
+
# @private
|
132
|
+
# @return [Array<Symbol>] The mapping of default_message_notifications.
|
133
|
+
DEFAULT_MESSAGE_NOTIFICATIONS = %i[all_messages only_mentions].freeze
|
134
|
+
# @private
|
135
|
+
# @return [Array<Symbol>] The mapping of explicit_content_filter.
|
136
|
+
EXPLICIT_CONTENT_FILTER = %i[
|
137
|
+
disabled_in_text
|
138
|
+
members_without_roles
|
139
|
+
all_members
|
140
|
+
].freeze
|
141
|
+
|
142
|
+
#
|
143
|
+
# Creates a new guild object.
|
144
|
+
# @private
|
145
|
+
#
|
146
|
+
# @param [Discorb::Client] client The client that owns this guild.
|
147
|
+
# @param [Hash] data The data of the guild.
|
148
|
+
# @param [Boolean] is_create_event Whether the guild is created by a `GUILD_CREATE` event.
|
149
|
+
#
|
150
|
+
def initialize(client, data, is_create_event)
|
151
|
+
@client = client
|
152
|
+
@data = {}
|
153
|
+
_set_data(data, is_create_event)
|
154
|
+
end
|
155
|
+
|
156
|
+
def afk_channel
|
157
|
+
@client.channels[@afk_channel_id]
|
158
|
+
end
|
159
|
+
|
160
|
+
def system_channel
|
161
|
+
@client.channels[@system_channel_id]
|
162
|
+
end
|
163
|
+
|
164
|
+
def rules_channel
|
165
|
+
@client.channels[@rules_channel_id]
|
166
|
+
end
|
167
|
+
|
168
|
+
def public_updates_channel
|
169
|
+
@client.channels[@public_updates_channel_id]
|
170
|
+
end
|
171
|
+
|
172
|
+
def inspect
|
173
|
+
"#<#{self.class} \"#{@name}\" id=#{@id}>"
|
174
|
+
end
|
175
|
+
|
176
|
+
def me
|
177
|
+
@members[@client.user.id]
|
178
|
+
end
|
179
|
+
|
180
|
+
#
|
181
|
+
# Leave the guild.
|
182
|
+
# @async
|
183
|
+
#
|
184
|
+
# @return [Async::Task<void>] The task.
|
185
|
+
#
|
186
|
+
def leave
|
187
|
+
Async do
|
188
|
+
@client
|
189
|
+
.http
|
190
|
+
.request(
|
191
|
+
Route.new(
|
192
|
+
"/users/@me/guilds/#{@id}",
|
193
|
+
"//users/@me/guilds/:guild_id",
|
194
|
+
:delete
|
195
|
+
)
|
196
|
+
)
|
197
|
+
.wait
|
198
|
+
@client.guilds.delete(@id)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
#
|
203
|
+
# Fetch scheduled events for the guild.
|
204
|
+
# @async
|
205
|
+
#
|
206
|
+
# @param [Boolean] with_user_count Whether to include the user count in the events.
|
207
|
+
# Defaults to `true`.
|
208
|
+
#
|
209
|
+
# @return [Array<Discorb::ScheduledEvent>] The events for the guild.
|
210
|
+
#
|
211
|
+
def fetch_scheduled_events(with_user_count: true)
|
212
|
+
Async do
|
213
|
+
_resp, events =
|
214
|
+
@client
|
215
|
+
.http
|
216
|
+
.request(
|
217
|
+
Route.new(
|
218
|
+
"/guilds/#{@id}/scheduled-events?with_user_count=#{with_user_count}",
|
219
|
+
"//guilds/:guild_id/scheduled-events",
|
220
|
+
:get
|
221
|
+
)
|
222
|
+
)
|
223
|
+
.wait
|
224
|
+
@scheduled_events = events.map { |e| ScheduledEvent.new(@client, e) }
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
#
|
229
|
+
# Fetch the scheduled event by ID.
|
230
|
+
# @async
|
231
|
+
#
|
232
|
+
# @param [#to_s] id The ID of the scheduled event.
|
233
|
+
#
|
234
|
+
# @return [Async::Task<Discorb::ScheduledEvent>] The event with the given ID.
|
235
|
+
# @return [Async::Task<nil>] If no event with the given ID exists.
|
236
|
+
#
|
237
|
+
def fetch_scheduled_event(id)
|
238
|
+
Async do
|
239
|
+
_resp, event =
|
240
|
+
@client
|
241
|
+
.http
|
242
|
+
.request(
|
243
|
+
Route.new(
|
244
|
+
"/guilds/#{@id}/scheduled-events/#{id}",
|
245
|
+
"//guilds/:guild_id/scheduled-events/:scheduled_event_id",
|
246
|
+
:get
|
247
|
+
)
|
248
|
+
)
|
249
|
+
.wait
|
250
|
+
ScheduledEvent.new(@client, event)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
#
|
255
|
+
# Create a scheduled event for the guild.
|
256
|
+
# @async
|
257
|
+
#
|
258
|
+
# @param [:stage_instance, :voice, :external] type The type of event to create.
|
259
|
+
# @param [String] name The name of the event.
|
260
|
+
# @param [String] description The description of the event.
|
261
|
+
# @param [Time] start_time The start time of the event.
|
262
|
+
# @param [Time, nil] end_time The end time of the event. Defaults to `nil`.
|
263
|
+
# @param [Discorb::Channel, Discorb::Snowflake, nil] channel The channel to run the event in.
|
264
|
+
# @param [String, nil] location The location of the event. Defaults to `nil`.
|
265
|
+
# @param [:guild_only] privacy_level The privacy level of the event. This must be `:guild_only`.
|
266
|
+
#
|
267
|
+
# @return [Async::Task<Discorb::ScheduledEvent>] The created event.
|
268
|
+
#
|
269
|
+
def create_scheduled_event(
|
270
|
+
type,
|
271
|
+
name,
|
272
|
+
description,
|
273
|
+
start_time,
|
274
|
+
end_time = nil,
|
275
|
+
privacy_level: :guild_only,
|
276
|
+
location: nil,
|
277
|
+
channel: nil
|
278
|
+
)
|
279
|
+
Async do
|
280
|
+
payload =
|
281
|
+
case type
|
282
|
+
when :stage_instance
|
283
|
+
unless channel
|
284
|
+
raise ArgumentError,
|
285
|
+
"channel must be provided for stage_instance events"
|
286
|
+
end
|
287
|
+
|
288
|
+
{
|
289
|
+
name: name,
|
290
|
+
description: description,
|
291
|
+
scheduled_start_time: start_time.iso8601,
|
292
|
+
scheduled_end_time: end_time&.iso8601,
|
293
|
+
privacy_level:
|
294
|
+
Discorb::ScheduledEvent::PRIVACY_LEVEL.key(privacy_level),
|
295
|
+
channel_id: channel&.id,
|
296
|
+
entity_type:
|
297
|
+
Discorb::ScheduledEvent::ENTITY_TYPE.key(:stage_instance)
|
298
|
+
}
|
299
|
+
when :voice
|
300
|
+
unless channel
|
301
|
+
raise ArgumentError, "channel must be provided for voice events"
|
302
|
+
end
|
303
|
+
|
304
|
+
{
|
305
|
+
name: name,
|
306
|
+
description: description,
|
307
|
+
scheduled_start_time: start_time.iso8601,
|
308
|
+
scheduled_end_time: end_time&.iso8601,
|
309
|
+
privacy_level:
|
310
|
+
Discorb::ScheduledEvent::PRIVACY_LEVEL.key(privacy_level),
|
311
|
+
channel_id: channel&.id,
|
312
|
+
entity_type: Discorb::ScheduledEvent::ENTITY_TYPE.key(:voice)
|
313
|
+
}
|
314
|
+
when :external
|
315
|
+
unless location
|
316
|
+
raise ArgumentError,
|
317
|
+
"location must be provided for external events"
|
318
|
+
end
|
319
|
+
unless end_time
|
320
|
+
raise ArgumentError,
|
321
|
+
"end_time must be provided for external events"
|
322
|
+
end
|
323
|
+
|
324
|
+
{
|
325
|
+
name: name,
|
326
|
+
description: description,
|
327
|
+
scheduled_start_time: start_time.iso8601,
|
328
|
+
scheduled_end_time: end_time.iso8601,
|
329
|
+
privacy_level:
|
330
|
+
Discorb::ScheduledEvent::PRIVACY_LEVEL.key(privacy_level),
|
331
|
+
entity_type: Discorb::ScheduledEvent::ENTITY_TYPE.key(:external),
|
332
|
+
entity_metadata: {
|
333
|
+
location: location
|
334
|
+
}
|
335
|
+
}
|
336
|
+
else
|
337
|
+
raise ArgumentError, "Invalid scheduled event type: #{type}"
|
338
|
+
end
|
339
|
+
_resp, event =
|
340
|
+
@client
|
341
|
+
.http
|
342
|
+
.request(
|
343
|
+
Route.new(
|
344
|
+
"/guilds/#{@id}/scheduled-events",
|
345
|
+
"//guilds/:guild_id/scheduled-events",
|
346
|
+
:post
|
347
|
+
),
|
348
|
+
payload
|
349
|
+
)
|
350
|
+
.wait
|
351
|
+
Discorb::ScheduledEvent.new(@client, event)
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
#
|
356
|
+
# Fetch emoji list of the guild.
|
357
|
+
# @async
|
358
|
+
# @note This querys the API every time. We recommend using {#emojis} instead.
|
359
|
+
#
|
360
|
+
# @return [Async::Task<Discorb::Dictionary{Discorb::Snowflake => Discorb::CustomEmoji}>]
|
361
|
+
# A dictionary of emoji in the guild.
|
362
|
+
#
|
363
|
+
def fetch_emoji_list
|
364
|
+
Async do
|
365
|
+
_resp, data =
|
366
|
+
@client
|
367
|
+
.http
|
368
|
+
.request(
|
369
|
+
Route.new(
|
370
|
+
"/guilds/#{@id}/emojis",
|
371
|
+
"//guilds/:guild_id/emojis",
|
372
|
+
:get
|
373
|
+
)
|
374
|
+
)
|
375
|
+
.wait
|
376
|
+
@emojis = Dictionary.new
|
377
|
+
ids = @emojis.map(&:id).map(&:to_s)
|
378
|
+
data.map do |e|
|
379
|
+
next if ids.include?(e[:id])
|
380
|
+
|
381
|
+
@emojis[e[:id]] = CustomEmoji.new(@client, self, e)
|
382
|
+
end
|
383
|
+
@emojis
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
alias fetch_emojis fetch_emoji_list
|
388
|
+
|
389
|
+
#
|
390
|
+
# Fetch emoji id of the guild.
|
391
|
+
# @async
|
392
|
+
# @note This querys the API every time. We recommend using {#emojis} instead.
|
393
|
+
#
|
394
|
+
# @param [#to_s] id The emoji id.
|
395
|
+
#
|
396
|
+
# @return [Async::Task<Discorb::CustomEmoji>] The emoji with the given id.
|
397
|
+
#
|
398
|
+
def fetch_emoji(id)
|
399
|
+
Async do
|
400
|
+
_resp, data =
|
401
|
+
@client
|
402
|
+
.http
|
403
|
+
.request(
|
404
|
+
Route.new(
|
405
|
+
"/guilds/#{@id}/emojis/#{id}",
|
406
|
+
"//guilds/:guild_id/emojis/:emoji_id",
|
407
|
+
:get
|
408
|
+
)
|
409
|
+
)
|
410
|
+
.wait
|
411
|
+
@emojis[e[:id]] = CustomEmoji.new(@client, self, data)
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
#
|
416
|
+
# Create a custom emoji.
|
417
|
+
# @async
|
418
|
+
#
|
419
|
+
# @param [#to_s] name The name of the emoji.
|
420
|
+
# @param [Discorb::Image] image The image of the emoji.
|
421
|
+
# @param [Array<Discorb::Role>] roles A list of roles to give the emoji.
|
422
|
+
#
|
423
|
+
# @return [Async::Task<Discorb::CustomEmoji>] The created emoji.
|
424
|
+
#
|
425
|
+
def create_emoji(name, image, roles: [])
|
426
|
+
Async do
|
427
|
+
_resp, data =
|
428
|
+
@client
|
429
|
+
.http
|
430
|
+
.request(
|
431
|
+
Route.new(
|
432
|
+
"/guilds/#{@id}/emojis",
|
433
|
+
"//guilds/:guild_id/emojis",
|
434
|
+
:post
|
435
|
+
),
|
436
|
+
{
|
437
|
+
name: name,
|
438
|
+
image: image.to_s,
|
439
|
+
roles: roles.map { |r| Discorb::Utils.try(r, :id) }
|
440
|
+
}
|
441
|
+
)
|
442
|
+
.wait
|
443
|
+
@emojis[data[:id]] = CustomEmoji.new(@client, self, data)
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
#
|
448
|
+
# Fetch webhooks of the guild.
|
449
|
+
# @async
|
450
|
+
#
|
451
|
+
# @return [Async::Task<Array<Discorb::Webhook>>] A list of webhooks in the guild.
|
452
|
+
#
|
453
|
+
def fetch_webhooks
|
454
|
+
Async do
|
455
|
+
_resp, data =
|
456
|
+
@client
|
457
|
+
.http
|
458
|
+
.request(
|
459
|
+
Route.new(
|
460
|
+
"/guilds/#{@id}/webhooks",
|
461
|
+
"//guilds/:guild_id/webhooks",
|
462
|
+
:get
|
463
|
+
)
|
464
|
+
)
|
465
|
+
.wait
|
466
|
+
data.map { |webhook| Webhook.from_data(@client, webhook) }
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
#
|
471
|
+
# Fetch audit log of the guild.
|
472
|
+
# @async
|
473
|
+
#
|
474
|
+
# @return [Async::Task<Discorb::AuditLog>] The audit log of the guild.
|
475
|
+
#
|
476
|
+
def fetch_audit_log
|
477
|
+
Async do
|
478
|
+
_resp, data =
|
479
|
+
@client
|
480
|
+
.http
|
481
|
+
.request(
|
482
|
+
Route.new(
|
483
|
+
"/guilds/#{@id}/audit-logs",
|
484
|
+
"//guilds/:guild_id/audit-logs",
|
485
|
+
:get
|
486
|
+
)
|
487
|
+
)
|
488
|
+
.wait
|
489
|
+
AuditLog.new(@client, data, self)
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
#
|
494
|
+
# Fetch channels of the guild.
|
495
|
+
# @async
|
496
|
+
#
|
497
|
+
# @return [Async::Task<Array<Discorb::Channel>>] A list of channels in the guild.
|
498
|
+
#
|
499
|
+
def fetch_channels
|
500
|
+
Async do
|
501
|
+
_resp, data =
|
502
|
+
@client
|
503
|
+
.http
|
504
|
+
.request(
|
505
|
+
Route.new(
|
506
|
+
"/guilds/#{@id}/channels",
|
507
|
+
"//guilds/:guild_id/channels",
|
508
|
+
:get
|
509
|
+
)
|
510
|
+
)
|
511
|
+
.wait
|
512
|
+
data.map { |c| Channel.make_channel(@client, c) }
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
516
|
+
#
|
517
|
+
# Create a new text channel.
|
518
|
+
# @async
|
519
|
+
#
|
520
|
+
# @param [String] name The name of the channel.
|
521
|
+
# @param [String] topic The topic of the channel.
|
522
|
+
# @param [Integer] rate_limit_per_user The rate limit per user in the channel.
|
523
|
+
# @param [Integer] slowmode Alias for `rate_limit_per_user`.
|
524
|
+
# @param [Integer] position The position of the channel.
|
525
|
+
# @param [Boolean] nsfw Whether the channel is nsfw.
|
526
|
+
# @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
|
527
|
+
# A list of permission overwrites.
|
528
|
+
# @param [Discorb::CategoryChannel] parent The parent of the channel.
|
529
|
+
# @param [String] reason The reason for creating the channel.
|
530
|
+
#
|
531
|
+
# @return [Async::Task<Discorb::TextChannel>] The created text channel.
|
532
|
+
#
|
533
|
+
def create_text_channel(
|
534
|
+
name,
|
535
|
+
topic: nil,
|
536
|
+
rate_limit_per_user: nil,
|
537
|
+
slowmode: nil,
|
538
|
+
position: nil,
|
539
|
+
nsfw: nil,
|
540
|
+
permission_overwrites: nil,
|
541
|
+
parent: nil,
|
542
|
+
reason: nil
|
543
|
+
)
|
544
|
+
Async do
|
545
|
+
payload = { type: TextChannel.channel_type }
|
546
|
+
payload[:name] = name
|
547
|
+
payload[:topic] = topic if topic
|
548
|
+
rate_limit_per_user ||= slowmode
|
549
|
+
payload[
|
550
|
+
:rate_limit_per_user
|
551
|
+
] = rate_limit_per_user if rate_limit_per_user
|
552
|
+
payload[:nsfw] = nsfw if nsfw
|
553
|
+
payload[:position] = position if position
|
554
|
+
if permission_overwrites
|
555
|
+
payload[
|
556
|
+
:permission_overwrites
|
557
|
+
] = permission_overwrites.map do |target, overwrite|
|
558
|
+
{
|
559
|
+
type: target.is_a?(Role) ? 0 : 1,
|
560
|
+
id: target.id,
|
561
|
+
allow: overwrite.allow_value,
|
562
|
+
deny: overwrite.deny_value
|
563
|
+
}
|
564
|
+
end
|
565
|
+
end
|
566
|
+
payload[:parent_id] = parent.id if parent
|
567
|
+
_resp, data =
|
568
|
+
@client
|
569
|
+
.http
|
570
|
+
.request(
|
571
|
+
Route.new(
|
572
|
+
"/guilds/#{@id}/channels",
|
573
|
+
"//guilds/:guild_id/channels",
|
574
|
+
:post
|
575
|
+
),
|
576
|
+
payload,
|
577
|
+
audit_log_reason: reason
|
578
|
+
)
|
579
|
+
.wait
|
580
|
+
payload[:parent_id] = parent&.id
|
581
|
+
Channel.make_channel(@client, data)
|
582
|
+
end
|
583
|
+
end
|
584
|
+
|
585
|
+
#
|
586
|
+
# Create a new voice channel.
|
587
|
+
# @async
|
588
|
+
#
|
589
|
+
# @param [String] name The name of the channel.
|
590
|
+
# @param [Integer] bitrate The bitrate of the channel.
|
591
|
+
# @param [Integer] user_limit The user limit of the channel.
|
592
|
+
# @param [Integer] position The position of the channel.
|
593
|
+
# @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
|
594
|
+
# A list of permission overwrites.
|
595
|
+
# @param [Discorb::CategoryChannel] parent The parent of the channel.
|
596
|
+
# @param [String] reason The reason for creating the channel.
|
597
|
+
#
|
598
|
+
# @return [Async::Task<Discorb::VoiceChannel>] The created voice channel.
|
599
|
+
#
|
600
|
+
def create_voice_channel(
|
601
|
+
name,
|
602
|
+
bitrate: 64,
|
603
|
+
user_limit: nil,
|
604
|
+
position: nil,
|
605
|
+
permission_overwrites: nil,
|
606
|
+
parent: nil,
|
607
|
+
reason: nil
|
608
|
+
)
|
609
|
+
Async do
|
610
|
+
payload = { type: VoiceChannel.channel_type }
|
611
|
+
payload[:name] = name
|
612
|
+
payload[:bitrate] = bitrate * 1000 if bitrate
|
613
|
+
payload[:user_limit] = user_limit if user_limit
|
614
|
+
payload[:position] = position if position
|
615
|
+
if permission_overwrites
|
616
|
+
payload[
|
617
|
+
:permission_overwrites
|
618
|
+
] = permission_overwrites.map do |target, overwrite|
|
619
|
+
{
|
620
|
+
type: target.is_a?(Role) ? 0 : 1,
|
621
|
+
id: target.id,
|
622
|
+
allow: overwrite.allow_value,
|
623
|
+
deny: overwrite.deny_value
|
624
|
+
}
|
625
|
+
end
|
626
|
+
end
|
627
|
+
payload[:parent_id] = parent.id if parent
|
628
|
+
_resp, data =
|
629
|
+
@client
|
630
|
+
.http
|
631
|
+
.request(
|
632
|
+
Route.new(
|
633
|
+
"/guilds/#{@id}/channels",
|
634
|
+
"//guilds/:guild_id/channels",
|
635
|
+
:post
|
636
|
+
),
|
637
|
+
payload,
|
638
|
+
audit_log_reason: reason
|
639
|
+
)
|
640
|
+
.wait
|
641
|
+
payload[:parent_id] = parent&.id
|
642
|
+
Channel.make_channel(@client, data)
|
643
|
+
end
|
644
|
+
end
|
645
|
+
|
646
|
+
# Create a new category channel.
|
647
|
+
# @async
|
648
|
+
#
|
649
|
+
# @param [String] name The name of the channel.
|
650
|
+
# @param [Integer] position The position of the channel.
|
651
|
+
# @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
|
652
|
+
# A list of permission overwrites.
|
653
|
+
# @param [Discorb::CategoryChannel] parent The parent of the channel.
|
654
|
+
# @param [String] reason The reason for creating the channel.
|
655
|
+
#
|
656
|
+
# @return [Async::Task<Discorb::CategoryChannel>] The created category channel.
|
657
|
+
#
|
658
|
+
def create_category_channel(
|
659
|
+
name,
|
660
|
+
position: nil,
|
661
|
+
permission_overwrites: nil,
|
662
|
+
parent: nil,
|
663
|
+
reason: nil
|
664
|
+
)
|
665
|
+
Async do
|
666
|
+
payload = { type: CategoryChannel.channel_type }
|
667
|
+
payload[:name] = name
|
668
|
+
payload[:position] = position if position
|
669
|
+
if permission_overwrites
|
670
|
+
payload[
|
671
|
+
:permission_overwrites
|
672
|
+
] = permission_overwrites.map do |target, overwrite|
|
673
|
+
{
|
674
|
+
type: target.is_a?(Role) ? 0 : 1,
|
675
|
+
id: target.id,
|
676
|
+
allow: overwrite.allow_value,
|
677
|
+
deny: overwrite.deny_value
|
678
|
+
}
|
679
|
+
end
|
680
|
+
end
|
681
|
+
payload[:parent_id] = parent&.id
|
682
|
+
_resp, data =
|
683
|
+
@client
|
684
|
+
.http
|
685
|
+
.request(
|
686
|
+
Route.new(
|
687
|
+
"/guilds/#{@id}/channels",
|
688
|
+
"//guilds/:guild_id/channels",
|
689
|
+
:post
|
690
|
+
),
|
691
|
+
payload,
|
692
|
+
audit_log_reason: reason
|
693
|
+
)
|
694
|
+
.wait
|
695
|
+
Channel.make_channel(@client, data)
|
696
|
+
end
|
697
|
+
end
|
698
|
+
|
699
|
+
alias create_category create_category_channel
|
700
|
+
|
701
|
+
#
|
702
|
+
# Create a new stage channel.
|
703
|
+
# @async
|
704
|
+
#
|
705
|
+
# @param [String] name The name of the channel.
|
706
|
+
# @param [Integer] bitrate The bitrate of the channel.
|
707
|
+
# @param [Integer] position The position of the channel.
|
708
|
+
# @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
|
709
|
+
# A list of permission overwrites.
|
710
|
+
# @param [Discorb::CategoryChannel] parent The parent of the channel.
|
711
|
+
# @param [String] reason The reason for creating the channel.
|
712
|
+
#
|
713
|
+
# @return [Async::Task<Discorb::StageChannel>] The created stage channel.
|
714
|
+
#
|
715
|
+
def create_stage_channel(
|
716
|
+
name,
|
717
|
+
bitrate: 64,
|
718
|
+
position: nil,
|
719
|
+
permission_overwrites: nil,
|
720
|
+
parent: nil,
|
721
|
+
reason: nil
|
722
|
+
)
|
723
|
+
Async do
|
724
|
+
payload = { type: StageChannel.channel_type }
|
725
|
+
payload[:name] = name
|
726
|
+
payload[:bitrate] = bitrate * 1000 if bitrate
|
727
|
+
payload[:position] = position if position
|
728
|
+
if permission_overwrites
|
729
|
+
payload[
|
730
|
+
:permission_overwrites
|
731
|
+
] = permission_overwrites.map do |target, overwrite|
|
732
|
+
{
|
733
|
+
type: target.is_a?(Role) ? 0 : 1,
|
734
|
+
id: target.id,
|
735
|
+
allow: overwrite.allow_value,
|
736
|
+
deny: overwrite.deny_value
|
737
|
+
}
|
738
|
+
end
|
739
|
+
end
|
740
|
+
payload[:parent_id] = parent&.id
|
741
|
+
_resp, data =
|
742
|
+
@client
|
743
|
+
.http
|
744
|
+
.request(
|
745
|
+
Route.new(
|
746
|
+
"/guilds/#{@id}/channels",
|
747
|
+
"//guilds/:guild_id/channels",
|
748
|
+
:post
|
749
|
+
),
|
750
|
+
payload,
|
751
|
+
audit_log_reason: reason
|
752
|
+
)
|
753
|
+
.wait
|
754
|
+
Channel.make_channel(@client, data)
|
755
|
+
end
|
756
|
+
end
|
757
|
+
|
758
|
+
#
|
759
|
+
# Create a new news channel.
|
760
|
+
# @async
|
761
|
+
#
|
762
|
+
# @param [String] name The name of the channel.
|
763
|
+
# @param [String] topic The topic of the channel.
|
764
|
+
# @param [Integer] rate_limit_per_user The rate limit per user in the channel.
|
765
|
+
# @param [Integer] slowmode Alias for `rate_limit_per_user`.
|
766
|
+
# @param [Integer] position The position of the channel.
|
767
|
+
# @param [Boolean] nsfw Whether the channel is nsfw.
|
768
|
+
# @param [Hash{Discorb::Role, Discorb::Member => Discorb::PermissionOverwrite}] permission_overwrites
|
769
|
+
# A list of permission overwrites.
|
770
|
+
# @param [Discorb::CategoryChannel] parent The parent of the channel.
|
771
|
+
# @param [String] reason The reason for creating the channel.
|
772
|
+
#
|
773
|
+
# @return [Async::Task<Discorb::NewsChannel>] The created news channel.
|
774
|
+
#
|
775
|
+
def create_news_channel(
|
776
|
+
name,
|
777
|
+
topic: nil,
|
778
|
+
rate_limit_per_user: nil,
|
779
|
+
slowmode: nil,
|
780
|
+
position: nil,
|
781
|
+
nsfw: nil,
|
782
|
+
permission_overwrites: nil,
|
783
|
+
parent: nil,
|
784
|
+
reason: nil
|
785
|
+
)
|
786
|
+
Async do
|
787
|
+
payload = { type: NewsChannel.channel_type }
|
788
|
+
payload[:name] = name
|
789
|
+
payload[:topic] = topic if topic
|
790
|
+
rate_limit_per_user ||= slowmode
|
791
|
+
payload[
|
792
|
+
:rate_limit_per_user
|
793
|
+
] = rate_limit_per_user if rate_limit_per_user
|
794
|
+
payload[:position] = position if position
|
795
|
+
if permission_overwrites
|
796
|
+
payload[
|
797
|
+
:permission_overwrites
|
798
|
+
] = permission_overwrites.map do |target, overwrite|
|
799
|
+
{
|
800
|
+
type: target.is_a?(Role) ? 0 : 1,
|
801
|
+
id: target.id,
|
802
|
+
allow: overwrite.allow_value,
|
803
|
+
deny: overwrite.deny_value
|
804
|
+
}
|
805
|
+
end
|
806
|
+
end
|
807
|
+
payload[:nsfw] = nsfw unless nsfw.nil?
|
808
|
+
payload[:parent_id] = parent&.id
|
809
|
+
_resp, data =
|
810
|
+
@client
|
811
|
+
.http
|
812
|
+
.request(
|
813
|
+
Route.new(
|
814
|
+
"/guilds/#{@id}/channels",
|
815
|
+
"//guilds/:guild_id/channels",
|
816
|
+
:post
|
817
|
+
),
|
818
|
+
payload,
|
819
|
+
audit_log_reason: reason
|
820
|
+
)
|
821
|
+
.wait
|
822
|
+
Channel.make_channel(@client, data)
|
823
|
+
end
|
824
|
+
end
|
825
|
+
|
826
|
+
#
|
827
|
+
# Fetch a list of active threads in the guild.
|
828
|
+
# @async
|
829
|
+
#
|
830
|
+
# @return [Async::Task<Array<Discorb::ThreadChannel>>] The list of threads.
|
831
|
+
#
|
832
|
+
def fetch_active_threads
|
833
|
+
Async do
|
834
|
+
_resp, data =
|
835
|
+
@client
|
836
|
+
.http
|
837
|
+
.request(
|
838
|
+
Route.new(
|
839
|
+
"/guilds/#{@id}/threads/active",
|
840
|
+
"//guilds/:guild_id/threads/active",
|
841
|
+
:get
|
842
|
+
)
|
843
|
+
)
|
844
|
+
.wait
|
845
|
+
data[:threads].map { |t| Channel.make_thread(@client, t) }
|
846
|
+
end
|
847
|
+
end
|
848
|
+
|
849
|
+
#
|
850
|
+
# Fetch a member in the guild.
|
851
|
+
# @async
|
852
|
+
#
|
853
|
+
# @param [#to_s] id The ID of the member to fetch.
|
854
|
+
#
|
855
|
+
# @return [Async::Task<Discorb::Member>] The member.
|
856
|
+
# @return [Async::Task<nil>] If the member is not found.
|
857
|
+
#
|
858
|
+
def fetch_member(id)
|
859
|
+
Async do
|
860
|
+
_resp, data =
|
861
|
+
@client
|
862
|
+
.http
|
863
|
+
.request(
|
864
|
+
Route.new(
|
865
|
+
"/guilds/#{@id}/members/#{id}",
|
866
|
+
"//guilds/:guild_id/members/:user_id",
|
867
|
+
:get
|
868
|
+
)
|
869
|
+
)
|
870
|
+
.wait
|
871
|
+
rescue Discorb::NotFoundError
|
872
|
+
nil
|
873
|
+
else
|
874
|
+
Member.new(@client, @id, data[:user], data)
|
875
|
+
end
|
876
|
+
end
|
877
|
+
|
878
|
+
# Fetch members in the guild.
|
879
|
+
# @async
|
880
|
+
# @macro members_intent
|
881
|
+
#
|
882
|
+
# @param [Integer] limit The maximum number of members to fetch, 0 for all.
|
883
|
+
# @param [Integer] after The ID of the member to start fetching after.
|
884
|
+
#
|
885
|
+
# @return [Async::Task<Array<Discorb::Member>>] The list of members.
|
886
|
+
#
|
887
|
+
def fetch_members(limit: 0, after: nil)
|
888
|
+
Async do
|
889
|
+
unless limit.zero?
|
890
|
+
_resp, data =
|
891
|
+
@client
|
892
|
+
.http
|
893
|
+
.request(
|
894
|
+
Route.new(
|
895
|
+
"/guilds/#{@id}/members?#{
|
896
|
+
URI.encode_www_form({ after: after, limit: limit })
|
897
|
+
}",
|
898
|
+
"//guilds/:guild_id/members",
|
899
|
+
:get
|
900
|
+
)
|
901
|
+
)
|
902
|
+
.wait
|
903
|
+
next data[:members].map { |m| Member.new(@client, @id, m[:user], m) }
|
904
|
+
end
|
905
|
+
ret = []
|
906
|
+
after = 0
|
907
|
+
loop do
|
908
|
+
params = { after: after, limit: 100 }
|
909
|
+
_resp, data =
|
910
|
+
@client
|
911
|
+
.http
|
912
|
+
.request(
|
913
|
+
Route.new(
|
914
|
+
"/guilds/#{@id}/members?#{URI.encode_www_form(params)}",
|
915
|
+
"//guilds/:guild_id/members",
|
916
|
+
:get
|
917
|
+
)
|
918
|
+
)
|
919
|
+
.wait
|
920
|
+
ret += data.map { |m| Member.new(@client, @id, m[:user], m) }
|
921
|
+
after = data.last[:user][:id]
|
922
|
+
break if data.length != 100
|
923
|
+
end
|
924
|
+
ret
|
925
|
+
end
|
926
|
+
end
|
927
|
+
|
928
|
+
alias fetch_member_list fetch_members
|
929
|
+
|
930
|
+
#
|
931
|
+
# Search for members by name in the guild.
|
932
|
+
# @async
|
933
|
+
#
|
934
|
+
# @param [String] name The name of the member to search for.
|
935
|
+
# @param [Integer] limit The maximum number of members to return.
|
936
|
+
#
|
937
|
+
# @return [Async::Task<Array<Discorb::Member>>] The list of members.
|
938
|
+
#
|
939
|
+
def fetch_members_named(name, limit: 1)
|
940
|
+
Async do
|
941
|
+
_resp, data =
|
942
|
+
@client
|
943
|
+
.http
|
944
|
+
.request(
|
945
|
+
Route.new(
|
946
|
+
"/guilds/#{@id}/members/search?#{
|
947
|
+
URI.encode_www_form({ query: name, limit: limit })
|
948
|
+
}",
|
949
|
+
"//guilds/:guild_id/members/search",
|
950
|
+
:get
|
951
|
+
)
|
952
|
+
)
|
953
|
+
.wait
|
954
|
+
data.map { |d| Member.new(@client, @id, d[:user], d) }
|
955
|
+
end
|
956
|
+
end
|
957
|
+
|
958
|
+
#
|
959
|
+
# Almost the same as {#fetch_members_named}, but returns a single member.
|
960
|
+
# @async
|
961
|
+
#
|
962
|
+
# @return [Async::Task<Discorb::Member>] The member.
|
963
|
+
# @return [Async::Task<nil>] If the member is not found.
|
964
|
+
#
|
965
|
+
def fetch_member_named(...)
|
966
|
+
Async { fetch_members_named(...).first }
|
967
|
+
end
|
968
|
+
|
969
|
+
#
|
970
|
+
# Change nickname of client member.
|
971
|
+
# @async
|
972
|
+
#
|
973
|
+
# @param [String] nickname The nickname to set.
|
974
|
+
# @param [String] reason The reason for changing the nickname.
|
975
|
+
#
|
976
|
+
# @return [Async::Task<void>] The task.
|
977
|
+
#
|
978
|
+
def edit_nickname(nickname, reason: nil)
|
979
|
+
Async do
|
980
|
+
@client
|
981
|
+
.http
|
982
|
+
.request(
|
983
|
+
Route.new(
|
984
|
+
"/guilds/#{@id}/members/@me/nick",
|
985
|
+
"//guilds/:guild_id/members/@me/nick",
|
986
|
+
:patch
|
987
|
+
),
|
988
|
+
{ nick: nickname },
|
989
|
+
audit_log_reason: reason
|
990
|
+
)
|
991
|
+
.wait
|
992
|
+
end
|
993
|
+
end
|
994
|
+
|
995
|
+
alias edit_nick edit_nickname
|
996
|
+
alias modify_nickname edit_nickname
|
997
|
+
alias modify_nick modify_nickname
|
998
|
+
|
999
|
+
#
|
1000
|
+
# Kick a member from the guild.
|
1001
|
+
# @async
|
1002
|
+
#
|
1003
|
+
# @param [Discorb::Member] member The member to kick.
|
1004
|
+
# @param [String] reason The reason for kicking the member.
|
1005
|
+
#
|
1006
|
+
# @return [Async::Task<void>] The task.
|
1007
|
+
#
|
1008
|
+
def kick_member(member, reason: nil)
|
1009
|
+
Async do
|
1010
|
+
@client
|
1011
|
+
.http
|
1012
|
+
.request(
|
1013
|
+
Route.new(
|
1014
|
+
"/guilds/#{@id}/members/#{member.id}",
|
1015
|
+
"//guilds/:guild_id/members/:user_id",
|
1016
|
+
:delete
|
1017
|
+
),
|
1018
|
+
{},
|
1019
|
+
audit_log_reason: reason
|
1020
|
+
)
|
1021
|
+
.wait
|
1022
|
+
end
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
#
|
1026
|
+
# Fetch a list of bans in the guild.
|
1027
|
+
# @async
|
1028
|
+
#
|
1029
|
+
# @param [Integer] limit The number of bans to fetch.
|
1030
|
+
# @param [Discorb::Snowflake] before The ID of the ban to fetch before.
|
1031
|
+
# @param [Discorb::Snowflake] after The ID of the ban to fetch after.
|
1032
|
+
# @param [Discorb::Snowflake] around The ID of the ban to fetch around.
|
1033
|
+
#
|
1034
|
+
# @return [Async::Task<Array<Discorb::Guild::Ban>>] The list of bans.
|
1035
|
+
#
|
1036
|
+
def fetch_bans(limit = 50, before: nil, after: nil, around: nil)
|
1037
|
+
Async do
|
1038
|
+
params =
|
1039
|
+
{
|
1040
|
+
limit: limit,
|
1041
|
+
before: Discorb::Utils.try(after, :id),
|
1042
|
+
after: Discorb::Utils.try(around, :id),
|
1043
|
+
around: Discorb::Utils.try(before, :id)
|
1044
|
+
}.filter { |_k, v| !v.nil? }.to_h
|
1045
|
+
_resp, bans =
|
1046
|
+
@client
|
1047
|
+
.http
|
1048
|
+
.request(
|
1049
|
+
Route.new(
|
1050
|
+
"/guilds/#{@id}/bans?#{URI.encode_www_form(params)}",
|
1051
|
+
"//guilds/:guild_id/bans",
|
1052
|
+
:get
|
1053
|
+
)
|
1054
|
+
)
|
1055
|
+
.wait
|
1056
|
+
bans.map { |d| Ban.new(@client, self, d) }
|
1057
|
+
end
|
1058
|
+
end
|
1059
|
+
|
1060
|
+
#
|
1061
|
+
# Fetch a ban in the guild.
|
1062
|
+
# @async
|
1063
|
+
#
|
1064
|
+
# @param [Discorb::User] user The user to fetch.
|
1065
|
+
#
|
1066
|
+
# @return [Async::Task<Discorb::Guild::Ban>] The ban.
|
1067
|
+
# @return [Async::Task<nil>] If the ban is not found.
|
1068
|
+
#
|
1069
|
+
def fetch_ban(user)
|
1070
|
+
Async do
|
1071
|
+
_resp, data =
|
1072
|
+
@client
|
1073
|
+
.http
|
1074
|
+
.request(
|
1075
|
+
Route.new(
|
1076
|
+
"/guilds/#{@id}/bans/#{user.id}",
|
1077
|
+
"//guilds/:guild_id/bans/:user_id",
|
1078
|
+
:get
|
1079
|
+
)
|
1080
|
+
)
|
1081
|
+
.wait
|
1082
|
+
rescue Discorb::NotFoundError
|
1083
|
+
nil
|
1084
|
+
else
|
1085
|
+
Ban.new(@client, self, data)
|
1086
|
+
end
|
1087
|
+
end
|
1088
|
+
|
1089
|
+
#
|
1090
|
+
# Checks the user was banned from the guild.
|
1091
|
+
# @async
|
1092
|
+
#
|
1093
|
+
# @param [Discorb::User] user The user to check.
|
1094
|
+
#
|
1095
|
+
# @return [Async::Task<Boolean>] Whether the user was banned.
|
1096
|
+
#
|
1097
|
+
def banned?(user)
|
1098
|
+
Async { !fetch_ban(user).wait.nil? }
|
1099
|
+
end
|
1100
|
+
|
1101
|
+
#
|
1102
|
+
# Ban a member from the guild.
|
1103
|
+
# @async
|
1104
|
+
#
|
1105
|
+
# @param [Discorb::Member] member The member to ban.
|
1106
|
+
# @param [Integer] delete_message_days The number of days to delete messages.
|
1107
|
+
# @param [String] reason The reason for banning the member.
|
1108
|
+
#
|
1109
|
+
# @return [Async::Task<Discorb::Guild::Ban>] The ban.
|
1110
|
+
#
|
1111
|
+
def ban_member(member, delete_message_days: 0, reason: nil)
|
1112
|
+
Async do
|
1113
|
+
_resp, data =
|
1114
|
+
@client
|
1115
|
+
.http
|
1116
|
+
.request(
|
1117
|
+
Route.new(
|
1118
|
+
"/guilds/#{@id}/bans",
|
1119
|
+
"//guilds/:guild_id/bans",
|
1120
|
+
:post
|
1121
|
+
),
|
1122
|
+
{ user: member.id, delete_message_days: delete_message_days },
|
1123
|
+
audit_log_reason: reason
|
1124
|
+
)
|
1125
|
+
.wait
|
1126
|
+
Ban.new(@client, self, data)
|
1127
|
+
end
|
1128
|
+
end
|
1129
|
+
|
1130
|
+
#
|
1131
|
+
# Unban a user from the guild.
|
1132
|
+
# @async
|
1133
|
+
#
|
1134
|
+
# @param [Discorb::User] user The user to unban.
|
1135
|
+
# @param [String] reason The reason for unbanning the user.
|
1136
|
+
#
|
1137
|
+
# @return [Async::Task<void>] The task.
|
1138
|
+
#
|
1139
|
+
def unban_user(user, reason: nil)
|
1140
|
+
Async do
|
1141
|
+
@client
|
1142
|
+
.http
|
1143
|
+
.request(
|
1144
|
+
Route.new(
|
1145
|
+
"/guilds/#{@id}/bans/#{user.id}",
|
1146
|
+
"//guilds/:guild_id/bans/:user_id",
|
1147
|
+
:delete
|
1148
|
+
),
|
1149
|
+
{},
|
1150
|
+
audit_log_reason: reason
|
1151
|
+
)
|
1152
|
+
.wait
|
1153
|
+
end
|
1154
|
+
end
|
1155
|
+
|
1156
|
+
#
|
1157
|
+
# Fetch a list of roles in the guild.
|
1158
|
+
# @async
|
1159
|
+
#
|
1160
|
+
# @return [Async::Task<Array<Discorb::Role>>] The list of roles.
|
1161
|
+
#
|
1162
|
+
def fetch_roles
|
1163
|
+
Async do
|
1164
|
+
_resp, data =
|
1165
|
+
@client
|
1166
|
+
.http
|
1167
|
+
.request(
|
1168
|
+
Route.new(
|
1169
|
+
"/guilds/#{@id}/roles",
|
1170
|
+
"//guilds/:guild_id/roles",
|
1171
|
+
:get
|
1172
|
+
)
|
1173
|
+
)
|
1174
|
+
.wait
|
1175
|
+
data.map { |d| Role.new(@client, self, d) }
|
1176
|
+
end
|
1177
|
+
end
|
1178
|
+
|
1179
|
+
#
|
1180
|
+
# Create a role in the guild.
|
1181
|
+
# @async
|
1182
|
+
#
|
1183
|
+
# @param [String] name The name of the role.
|
1184
|
+
# @param [Discorb::Color] color The color of the role.
|
1185
|
+
# @param [Boolean] hoist Whether the role should be hoisted.
|
1186
|
+
# @param [Boolean] mentionable Whether the role should be mentionable.
|
1187
|
+
# @param [String] reason The reason for creating the role.
|
1188
|
+
#
|
1189
|
+
# @return [Async::Task<Discorb::Role>] The role.
|
1190
|
+
#
|
1191
|
+
def create_role(
|
1192
|
+
name = nil,
|
1193
|
+
color: nil,
|
1194
|
+
hoist: nil,
|
1195
|
+
mentionable: nil,
|
1196
|
+
reason: nil
|
1197
|
+
)
|
1198
|
+
Async do
|
1199
|
+
payload = {}
|
1200
|
+
payload[:name] = name if name
|
1201
|
+
payload[:color] = color.to_i if color
|
1202
|
+
payload[:hoist] = hoist if hoist
|
1203
|
+
payload[:mentionable] = mentionable if mentionable
|
1204
|
+
_resp, data =
|
1205
|
+
@client
|
1206
|
+
.http
|
1207
|
+
.request(
|
1208
|
+
Route.new(
|
1209
|
+
"/guilds/#{@id}/roles",
|
1210
|
+
"//guilds/:guild_id/roles",
|
1211
|
+
:post
|
1212
|
+
),
|
1213
|
+
payload,
|
1214
|
+
audit_log_reason: reason
|
1215
|
+
)
|
1216
|
+
.wait
|
1217
|
+
Role.new(@client, self, data)
|
1218
|
+
end
|
1219
|
+
end
|
1220
|
+
|
1221
|
+
#
|
1222
|
+
# Fetch how many members will be pruned.
|
1223
|
+
# @async
|
1224
|
+
#
|
1225
|
+
# @param [Integer] days The number of days to prune.
|
1226
|
+
# @param [Array<Discorb::Role>] roles The roles that include for pruning.
|
1227
|
+
#
|
1228
|
+
# @return [Async::Task<Integer>] The number of members that will be pruned.
|
1229
|
+
#
|
1230
|
+
def fetch_prune(days = 7, roles: [])
|
1231
|
+
Async do
|
1232
|
+
params = { days: days, include_roles: @id.to_s }
|
1233
|
+
param[:include_roles] = roles
|
1234
|
+
.map(&:id)
|
1235
|
+
.map(&:to_s)
|
1236
|
+
.join(";") if roles.any?
|
1237
|
+
_resp, data =
|
1238
|
+
@client
|
1239
|
+
.http
|
1240
|
+
.request(
|
1241
|
+
Route.new(
|
1242
|
+
"/guilds/#{@id}/prune?#{URI.encode_www_form(params)}",
|
1243
|
+
"//guilds/:guild_id/prune",
|
1244
|
+
:get
|
1245
|
+
)
|
1246
|
+
)
|
1247
|
+
.wait
|
1248
|
+
data[:pruned]
|
1249
|
+
end
|
1250
|
+
end
|
1251
|
+
|
1252
|
+
#
|
1253
|
+
# Prune members from the guild.
|
1254
|
+
# @async
|
1255
|
+
#
|
1256
|
+
# @param [Integer] days The number of days to prune.
|
1257
|
+
# @param [Array<Discorb::Role>] roles The roles that include for pruning.
|
1258
|
+
# @param [String] reason The reason for pruning.
|
1259
|
+
#
|
1260
|
+
# @return [Async::Task<Integer>] The number of members that were pruned.
|
1261
|
+
#
|
1262
|
+
def prune(days = 7, roles: [], reason: nil)
|
1263
|
+
Async do
|
1264
|
+
_resp, data =
|
1265
|
+
@client
|
1266
|
+
.http
|
1267
|
+
.request(
|
1268
|
+
Route.new(
|
1269
|
+
"/guilds/#{@id}/prune",
|
1270
|
+
"//guilds/:guild_id/prune",
|
1271
|
+
:post
|
1272
|
+
),
|
1273
|
+
{ days: days, roles: roles.map(&:id) },
|
1274
|
+
audit_log_reason: reason
|
1275
|
+
)
|
1276
|
+
.wait
|
1277
|
+
data[:pruned]
|
1278
|
+
end
|
1279
|
+
end
|
1280
|
+
|
1281
|
+
#
|
1282
|
+
# Fetch voice regions that are available in the guild.
|
1283
|
+
# @async
|
1284
|
+
#
|
1285
|
+
# @return [Async::Task<Array<Discorb::VoiceRegion>>] The available voice regions.
|
1286
|
+
#
|
1287
|
+
def fetch_voice_regions
|
1288
|
+
Async do
|
1289
|
+
_resp, data =
|
1290
|
+
@client
|
1291
|
+
.http
|
1292
|
+
.request(
|
1293
|
+
Route.new(
|
1294
|
+
"/guilds/#{@id}/voice",
|
1295
|
+
"//guilds/:guild_id/voice",
|
1296
|
+
:get
|
1297
|
+
)
|
1298
|
+
)
|
1299
|
+
.wait
|
1300
|
+
data.map { |d| VoiceRegion.new(d) }
|
1301
|
+
end
|
1302
|
+
end
|
1303
|
+
|
1304
|
+
#
|
1305
|
+
# Fetch invites in the guild.
|
1306
|
+
# @async
|
1307
|
+
#
|
1308
|
+
# @return [Async::Task<Array<Invite>>] The invites.
|
1309
|
+
#
|
1310
|
+
def fetch_invites
|
1311
|
+
Async do
|
1312
|
+
_resp, data =
|
1313
|
+
@client
|
1314
|
+
.http
|
1315
|
+
.request(
|
1316
|
+
Route.new(
|
1317
|
+
"/guilds/#{@id}/invites",
|
1318
|
+
"//guilds/:guild_id/invites",
|
1319
|
+
:get
|
1320
|
+
)
|
1321
|
+
)
|
1322
|
+
.wait
|
1323
|
+
data.map { |d| Invite.new(@client, d, false) }
|
1324
|
+
end
|
1325
|
+
end
|
1326
|
+
|
1327
|
+
#
|
1328
|
+
# Fetch integrations in the guild.
|
1329
|
+
# @async
|
1330
|
+
#
|
1331
|
+
# @return [Async::Task<Array<Discorb::Integration>>] The integrations.
|
1332
|
+
#
|
1333
|
+
def fetch_integrations
|
1334
|
+
Async do
|
1335
|
+
_resp, data =
|
1336
|
+
@client
|
1337
|
+
.http
|
1338
|
+
.request(
|
1339
|
+
Route.new(
|
1340
|
+
"/guilds/#{@id}/integrations",
|
1341
|
+
"//guilds/:guild_id/integrations",
|
1342
|
+
:get
|
1343
|
+
)
|
1344
|
+
)
|
1345
|
+
.wait
|
1346
|
+
data.map { |d| Integration.new(@client, d, @id) }
|
1347
|
+
end
|
1348
|
+
end
|
1349
|
+
|
1350
|
+
#
|
1351
|
+
# Fetch the widget of the guild.
|
1352
|
+
# @async
|
1353
|
+
#
|
1354
|
+
# @return [Async::Task<Discorb::Guild::Widget>] The widget.
|
1355
|
+
#
|
1356
|
+
def fetch_widget
|
1357
|
+
Async do
|
1358
|
+
_resp, data =
|
1359
|
+
@client
|
1360
|
+
.http
|
1361
|
+
.request(
|
1362
|
+
Route.new(
|
1363
|
+
"/guilds/#{@id}/widget",
|
1364
|
+
"//guilds/:guild_id/widget",
|
1365
|
+
:get
|
1366
|
+
)
|
1367
|
+
)
|
1368
|
+
.wait
|
1369
|
+
Widget.new(@client, @id, data)
|
1370
|
+
end
|
1371
|
+
end
|
1372
|
+
|
1373
|
+
#
|
1374
|
+
# Fetch the vanity URL of the guild.
|
1375
|
+
# @async
|
1376
|
+
#
|
1377
|
+
# @return [Async::Task<Discorb::Guild::VanityInvite>] The vanity URL.
|
1378
|
+
#
|
1379
|
+
def fetch_vanity_invite
|
1380
|
+
Async do
|
1381
|
+
_resp, data =
|
1382
|
+
@client
|
1383
|
+
.http
|
1384
|
+
.request(
|
1385
|
+
Route.new(
|
1386
|
+
"/guilds/#{@id}/vanity-url",
|
1387
|
+
"//guilds/:guild_id/vanity-url",
|
1388
|
+
:get
|
1389
|
+
)
|
1390
|
+
)
|
1391
|
+
.wait
|
1392
|
+
VanityInvite.new(@client, self, data)
|
1393
|
+
end
|
1394
|
+
end
|
1395
|
+
|
1396
|
+
#
|
1397
|
+
# Fetch the welcome screen of the guild.
|
1398
|
+
# @async
|
1399
|
+
#
|
1400
|
+
# @return [Async::Task<Discorb::WelcomeScreen>] The welcome screen.
|
1401
|
+
#
|
1402
|
+
def fetch_welcome_screen
|
1403
|
+
Async do
|
1404
|
+
_resp, data =
|
1405
|
+
@client
|
1406
|
+
.http
|
1407
|
+
.request(
|
1408
|
+
Route.new(
|
1409
|
+
"/guilds/#{@id}/welcome-screen",
|
1410
|
+
"//guilds/:guild_id/welcome-screen",
|
1411
|
+
:get
|
1412
|
+
)
|
1413
|
+
)
|
1414
|
+
.wait
|
1415
|
+
WelcomeScreen.new(@client, self, data)
|
1416
|
+
end
|
1417
|
+
end
|
1418
|
+
|
1419
|
+
#
|
1420
|
+
# Fetch stickers in the guild.
|
1421
|
+
# @async
|
1422
|
+
#
|
1423
|
+
# @return [Async::Task<Array<Discorb::Sticker::GuildSticker>>] The stickers.
|
1424
|
+
#
|
1425
|
+
def fetch_stickers
|
1426
|
+
Async do
|
1427
|
+
_resp, data =
|
1428
|
+
@client
|
1429
|
+
.http
|
1430
|
+
.request(
|
1431
|
+
Route.new(
|
1432
|
+
"/guilds/#{@id}/stickers",
|
1433
|
+
"//guilds/:guild_id/stickers",
|
1434
|
+
:get
|
1435
|
+
)
|
1436
|
+
)
|
1437
|
+
.wait
|
1438
|
+
data.map { |d| Sticker::GuildSticker.new(@client, d) }
|
1439
|
+
end
|
1440
|
+
end
|
1441
|
+
|
1442
|
+
#
|
1443
|
+
# Fetch the sticker by ID.
|
1444
|
+
# @async
|
1445
|
+
#
|
1446
|
+
# @param [#to_s] id The ID of the sticker.
|
1447
|
+
#
|
1448
|
+
# @return [Async::Task<Discorb::Sticker::GuildSticker>] The sticker.
|
1449
|
+
# @return [Async::Task<nil>] If the sticker does not exist.
|
1450
|
+
#
|
1451
|
+
def fetch_sticker(id)
|
1452
|
+
Async do
|
1453
|
+
_resp, data =
|
1454
|
+
@client
|
1455
|
+
.http
|
1456
|
+
.request(
|
1457
|
+
Route.new(
|
1458
|
+
"/guilds/#{@id}/stickers/#{id}",
|
1459
|
+
"//guilds/:guild_id/stickers/:sticker_id",
|
1460
|
+
:get
|
1461
|
+
)
|
1462
|
+
)
|
1463
|
+
.wait
|
1464
|
+
rescue Discorb::NotFoundError
|
1465
|
+
nil
|
1466
|
+
else
|
1467
|
+
Sticker::GuildSticker.new(@client, data)
|
1468
|
+
end
|
1469
|
+
end
|
1470
|
+
|
1471
|
+
#
|
1472
|
+
# Fetch templates in the guild.
|
1473
|
+
# @async
|
1474
|
+
#
|
1475
|
+
# @return [Async::Task<Discorb::GuildTemplate>] The templates.
|
1476
|
+
#
|
1477
|
+
def fetch_templates
|
1478
|
+
Async do
|
1479
|
+
_resp, data =
|
1480
|
+
@client
|
1481
|
+
.http
|
1482
|
+
.request(
|
1483
|
+
Route.new(
|
1484
|
+
"/guilds/#{@id}/templates",
|
1485
|
+
"//guilds/:guild_id/templates",
|
1486
|
+
:get
|
1487
|
+
)
|
1488
|
+
)
|
1489
|
+
.wait
|
1490
|
+
data.map { |d| GuildTemplate.new(@client, d) }
|
1491
|
+
end
|
1492
|
+
end
|
1493
|
+
|
1494
|
+
#
|
1495
|
+
# Almost the same as {#fetch_templates}, but returns a single template.
|
1496
|
+
#
|
1497
|
+
# @return [Discorb::GuildTemplate] The template.
|
1498
|
+
# @return [Async::Task<nil>] If the template does not exist.
|
1499
|
+
#
|
1500
|
+
def fetch_template
|
1501
|
+
Async { fetch_templates.wait.first }
|
1502
|
+
end
|
1503
|
+
|
1504
|
+
#
|
1505
|
+
# Create a new template in the guild.
|
1506
|
+
#
|
1507
|
+
# @param [String] name The name of the template.
|
1508
|
+
# @param [String] description The description of the template.
|
1509
|
+
# @param [String] reason The reason for creating the template.
|
1510
|
+
#
|
1511
|
+
# @return [Async::Task<Discorb::GuildTemplate>] The template.
|
1512
|
+
#
|
1513
|
+
def create_template(name, description = nil, reason: nil)
|
1514
|
+
Async do
|
1515
|
+
_resp, data =
|
1516
|
+
@client
|
1517
|
+
.http
|
1518
|
+
.request(
|
1519
|
+
Route.new(
|
1520
|
+
"/guilds/#{@id}/templates",
|
1521
|
+
"//guilds/:guild_id/templates",
|
1522
|
+
:post
|
1523
|
+
),
|
1524
|
+
{ name: name, description: description },
|
1525
|
+
audit_log_reason: reason
|
1526
|
+
)
|
1527
|
+
.wait
|
1528
|
+
GuildTemplate.new(@client, data)
|
1529
|
+
end
|
1530
|
+
end
|
1531
|
+
|
1532
|
+
#
|
1533
|
+
# Fetch the automod rules in the guild.
|
1534
|
+
# @async
|
1535
|
+
#
|
1536
|
+
# @return [Async::Task<Array<Discorb::AutoModRule>>] The automod rules.
|
1537
|
+
#
|
1538
|
+
def fetch_automod_rules
|
1539
|
+
Async do
|
1540
|
+
_resp, data =
|
1541
|
+
@client.http.request(
|
1542
|
+
Route.new(
|
1543
|
+
"/guilds/#{@id}/auto-moderation/rules",
|
1544
|
+
"//guilds/:guild_id/auto-moderation/rules",
|
1545
|
+
:get
|
1546
|
+
)
|
1547
|
+
)
|
1548
|
+
data.map { |d| AutoModRule.new(@client, d) }
|
1549
|
+
end
|
1550
|
+
end
|
1551
|
+
|
1552
|
+
alias fetch_automod_rule_list fetch_automod_rules
|
1553
|
+
|
1554
|
+
#
|
1555
|
+
# Fetch the automod rule by ID.
|
1556
|
+
#
|
1557
|
+
# @param [#to_s] id The ID of the automod rule.
|
1558
|
+
#
|
1559
|
+
# @return [Async::Task<Array<Discord::AutoModRule>>] The automod rule.
|
1560
|
+
#
|
1561
|
+
def fetch_automod_rule(id)
|
1562
|
+
Async do
|
1563
|
+
_resp, data =
|
1564
|
+
@client
|
1565
|
+
.http
|
1566
|
+
.request(
|
1567
|
+
Route.new(
|
1568
|
+
"/guilds/#{@id}/auto-moderation/rules/#{id}",
|
1569
|
+
"//guilds/:guild_id/auto-moderation/rules/:rule_id",
|
1570
|
+
:get
|
1571
|
+
)
|
1572
|
+
)
|
1573
|
+
.wait
|
1574
|
+
AutoModRule.new(@client, data)
|
1575
|
+
end
|
1576
|
+
end
|
1577
|
+
|
1578
|
+
#
|
1579
|
+
# Create a new automod rule in the guild.
|
1580
|
+
# @async
|
1581
|
+
#
|
1582
|
+
# @param [String] name The name of the rule.
|
1583
|
+
# @param [Symbol] trigger_type The trigger type of the rule. See {Discorb::AutoModRule::TRIGGER_TYPES}.
|
1584
|
+
# @param [Array<Discorb::AutoModRule::Action>] actions The actions of the rule.
|
1585
|
+
# @param [Symbol] event_type The event type of the rule. See {Discorb::AutoModRule::EVENT_TYPES}.
|
1586
|
+
# @param [Boolean] enabled Whether the rule is enabled or not.
|
1587
|
+
# @param [Array<Discorb::Role>] exempt_roles The roles that are exempt from the rule.
|
1588
|
+
# @param [Array<Discorb::Channel>] exempt_channels The channels that are exempt from the rule.
|
1589
|
+
# @param [Array<String>] keyword_filter The keywords to filter.
|
1590
|
+
# @param [Array<String>] allow_list Substrings which will be exempt from triggering the preset trigger type.
|
1591
|
+
# @param [Integer] mention_total_limit The total number of mentions allowed per message.
|
1592
|
+
# @param [Symbol] presets The preset of the rule. See {Discorb::AutoModRule::PRESET_TYPES}.
|
1593
|
+
# @param [String] reason The reason for creating the rule.
|
1594
|
+
#
|
1595
|
+
# @return [Async::Task<Discorb::AutoModRule>] The automod rule.
|
1596
|
+
#
|
1597
|
+
def create_automod_rule(
|
1598
|
+
name,
|
1599
|
+
trigger_type,
|
1600
|
+
actions,
|
1601
|
+
event_type = :message_send,
|
1602
|
+
enabled: false,
|
1603
|
+
exempt_roles: [],
|
1604
|
+
exempt_channels: [],
|
1605
|
+
keyword_filter: nil,
|
1606
|
+
mention_total_limit: nil,
|
1607
|
+
allow_list: nil,
|
1608
|
+
presets: nil,
|
1609
|
+
reason: nil
|
1610
|
+
)
|
1611
|
+
Async do
|
1612
|
+
payload = {
|
1613
|
+
name: name,
|
1614
|
+
event_type: Discorb::AutoModRule::EVENT_TYPES.key(event_type),
|
1615
|
+
trigger_type: Discorb::AutoModRule::TRIGGER_TYPES.key(trigger_type),
|
1616
|
+
metadata: {
|
1617
|
+
keyword_filter: keyword_filter,
|
1618
|
+
presets: presets && Discorb::AutoModRule::PRESET_TYPES.key(presets),
|
1619
|
+
allow_list: allow_list,
|
1620
|
+
mention_total_limit: mention_total_limit
|
1621
|
+
},
|
1622
|
+
actions: actions.map(&:to_hash),
|
1623
|
+
enabled: enabled,
|
1624
|
+
exempt_roles: exempt_roles.map(&:id),
|
1625
|
+
exempt_channels: exempt_channels.map(&:id)
|
1626
|
+
}
|
1627
|
+
|
1628
|
+
_resp, data =
|
1629
|
+
@client.http.request(
|
1630
|
+
Route.new(
|
1631
|
+
"/guilds/#{@id}/auto-moderation/rules",
|
1632
|
+
"//guilds/:guild_id/auto-moderation/rules",
|
1633
|
+
:post
|
1634
|
+
),
|
1635
|
+
payload,
|
1636
|
+
audit_log_reason: reason
|
1637
|
+
)
|
1638
|
+
Discorb::AutoModRule.new(@client, data)
|
1639
|
+
end
|
1640
|
+
end
|
1641
|
+
|
1642
|
+
#
|
1643
|
+
# Represents a vanity invite.
|
1644
|
+
#
|
1645
|
+
class VanityInvite < DiscordModel
|
1646
|
+
# @return [String] The vanity invite code.
|
1647
|
+
attr_reader :code
|
1648
|
+
# @return [Integer] The number of uses.
|
1649
|
+
attr_reader :uses
|
1650
|
+
|
1651
|
+
# @!attribute [r] url
|
1652
|
+
# @return [String] The vanity URL.
|
1653
|
+
|
1654
|
+
#
|
1655
|
+
# Initialize a new instance of the {VanityInvite} class.
|
1656
|
+
# @private
|
1657
|
+
#
|
1658
|
+
# @param [Discorb::Client] client The client.
|
1659
|
+
# @param [Discorb::Guild] guild The guild.
|
1660
|
+
# @param [Hash] data The data of the invite.
|
1661
|
+
#
|
1662
|
+
def initialize(client, guild, data)
|
1663
|
+
@client = client
|
1664
|
+
@guild = guild
|
1665
|
+
@code = data[:code]
|
1666
|
+
@uses = data[:uses]
|
1667
|
+
end
|
1668
|
+
|
1669
|
+
def url
|
1670
|
+
"https://discord.gg/#{@code}"
|
1671
|
+
end
|
1672
|
+
end
|
1673
|
+
|
1674
|
+
#
|
1675
|
+
# Represents a guild widget.
|
1676
|
+
#
|
1677
|
+
class Widget < DiscordModel
|
1678
|
+
# @return [Discorb::Snowflake] The guild ID.
|
1679
|
+
attr_reader :guild_id
|
1680
|
+
# @return [Discorb::Snowflake] The channel ID.
|
1681
|
+
attr_reader :channel_id
|
1682
|
+
# @return [Boolean] Whether the widget is enabled.
|
1683
|
+
attr_reader :enabled
|
1684
|
+
alias enabled? enabled
|
1685
|
+
alias enable? enabled
|
1686
|
+
|
1687
|
+
# @!attribute [r] channel
|
1688
|
+
# @macro client_cache
|
1689
|
+
# @return [Discorb::Channel] The channel.
|
1690
|
+
# @!attribute [r] guild
|
1691
|
+
# @macro client_cache
|
1692
|
+
# @return [Discorb::Guild] The guild.
|
1693
|
+
# @!attribute [r] json_url
|
1694
|
+
# @return [String] The JSON URL.
|
1695
|
+
|
1696
|
+
#
|
1697
|
+
# Initialize a new instance of the {Widget} class.
|
1698
|
+
# @private
|
1699
|
+
#
|
1700
|
+
# @param [Discorb::Client] client The client.
|
1701
|
+
# @param [Discorb::Snowflake] guild_id The guild ID.
|
1702
|
+
# @param [Hash] data The data from Discord.
|
1703
|
+
#
|
1704
|
+
def initialize(client, guild_id, data)
|
1705
|
+
@client = client
|
1706
|
+
@enabled = data[:enabled]
|
1707
|
+
@guild_id = Snowflake.new(guild_id)
|
1708
|
+
@channel_id = Snowflake.new(data[:channel_id])
|
1709
|
+
end
|
1710
|
+
|
1711
|
+
def channel
|
1712
|
+
@client.channels[@channel_id]
|
1713
|
+
end
|
1714
|
+
|
1715
|
+
#
|
1716
|
+
# Edit the widget.
|
1717
|
+
# @async
|
1718
|
+
# @macro edit
|
1719
|
+
#
|
1720
|
+
# @param [Boolean] enabled Whether the widget is enabled.
|
1721
|
+
# @param [Discorb::GuildChannel] channel The channel.
|
1722
|
+
# @param [String] reason The reason for editing the widget.
|
1723
|
+
#
|
1724
|
+
# @return [Async::Task<void>] The task.
|
1725
|
+
#
|
1726
|
+
def edit(enabled: nil, channel: nil, reason: nil)
|
1727
|
+
Async do
|
1728
|
+
payload = {}
|
1729
|
+
payload[:enabled] = enabled unless enabled.nil?
|
1730
|
+
payload[:channel_id] = channel.id if channel_id
|
1731
|
+
@client
|
1732
|
+
.http
|
1733
|
+
.request(
|
1734
|
+
Route.new(
|
1735
|
+
"/guilds/#{@guild_id}/widget",
|
1736
|
+
"//guilds/:guild_id/widget",
|
1737
|
+
:patch
|
1738
|
+
),
|
1739
|
+
payload,
|
1740
|
+
audit_log_reason: reason
|
1741
|
+
)
|
1742
|
+
.wait
|
1743
|
+
end
|
1744
|
+
end
|
1745
|
+
|
1746
|
+
alias modify edit
|
1747
|
+
|
1748
|
+
def json_url
|
1749
|
+
"#{Discorb::API_BASE_URL}/guilds/#{@guild_id}/widget.json"
|
1750
|
+
end
|
1751
|
+
|
1752
|
+
#
|
1753
|
+
# Return iframe HTML of the widget.
|
1754
|
+
#
|
1755
|
+
# @param ["dark", "light"] theme The theme of the widget.
|
1756
|
+
# @param [Integer] width The width of the widget.
|
1757
|
+
# @param [Integer] height The height of the widget.
|
1758
|
+
#
|
1759
|
+
# @return [String] The iframe HTML.
|
1760
|
+
#
|
1761
|
+
def iframe(theme: "dark", width: 350, height: 500)
|
1762
|
+
# rubocop:disable Layout/LineLength
|
1763
|
+
[
|
1764
|
+
%(<iframe src="https://canary.discord.com/widget?id=#{@guild_id}&theme=#{theme}" width="#{width}" height="#{height}"),
|
1765
|
+
%(allowtransparency="true" frameborder="0" sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"></iframe>)
|
1766
|
+
].join
|
1767
|
+
# rubocop:enable Layout/LineLength
|
1768
|
+
end
|
1769
|
+
end
|
1770
|
+
|
1771
|
+
#
|
1772
|
+
# Represents a ban.
|
1773
|
+
#
|
1774
|
+
class Ban < DiscordModel
|
1775
|
+
# @return [Discorb::User] The user.
|
1776
|
+
attr_reader :user
|
1777
|
+
# @return [String] The reason for the ban.
|
1778
|
+
attr_reader :reason
|
1779
|
+
|
1780
|
+
#
|
1781
|
+
# Initialize a new instance of the {Ban} class.
|
1782
|
+
# @private
|
1783
|
+
#
|
1784
|
+
# @param [Discorb::Client] client The client.
|
1785
|
+
# @param [Discorb::Guild] guild The guild.
|
1786
|
+
# @param [Hash] data The data from Discord.
|
1787
|
+
#
|
1788
|
+
def initialize(client, guild, data)
|
1789
|
+
@client = client
|
1790
|
+
@guild = guild
|
1791
|
+
@reason = data[:reason]
|
1792
|
+
@user =
|
1793
|
+
@client.users[data[:user][:id]] || User.new(@client, data[:user])
|
1794
|
+
end
|
1795
|
+
|
1796
|
+
def inspect
|
1797
|
+
"<#{self.class.name} #{@user}>"
|
1798
|
+
end
|
1799
|
+
end
|
1800
|
+
|
1801
|
+
class << self
|
1802
|
+
#
|
1803
|
+
# Returns a banner url from the guild's ID.
|
1804
|
+
#
|
1805
|
+
# @param [#to_s] guild_id The ID of the guild.
|
1806
|
+
# @param [:shield, :banner1, :banner2, :banner3, :banner4] style The style of the banner.
|
1807
|
+
#
|
1808
|
+
# @return [String] The url of the banner.
|
1809
|
+
#
|
1810
|
+
def banner(guild_id, style: :banner)
|
1811
|
+
"#{Discorb::API_BASE_URL}/guilds/#{guild_id}/widget.png&style=#{style}"
|
1812
|
+
end
|
1813
|
+
end
|
1814
|
+
|
1815
|
+
private
|
1816
|
+
|
1817
|
+
def _set_data(data, is_create_event)
|
1818
|
+
@id = Snowflake.new(data[:id])
|
1819
|
+
if data[:unavailable]
|
1820
|
+
@unavailable = true
|
1821
|
+
return
|
1822
|
+
end
|
1823
|
+
@client.guilds[@id] = self unless data[:no_cache]
|
1824
|
+
@icon = data[:icon] && Asset.new(self, data[:icon])
|
1825
|
+
@unavailable = false
|
1826
|
+
@name = data[:name]
|
1827
|
+
@members = Discorb::Dictionary.new
|
1828
|
+
data[:members]&.each { |m| Member.new(@client, @id, m[:user], m) }
|
1829
|
+
@splash =
|
1830
|
+
data[:splash] && Asset.new(self, data[:splash], path: "splashes/#{@id}")
|
1831
|
+
@discovery_splash =
|
1832
|
+
data[:discovery_splash] &&
|
1833
|
+
Asset.new(
|
1834
|
+
self,
|
1835
|
+
data[:discovery_splash],
|
1836
|
+
path: "discovery-splashes/#{@id}"
|
1837
|
+
)
|
1838
|
+
@owner_id = data[:owner_id]
|
1839
|
+
@permissions = Permission.new(data[:permissions].to_i)
|
1840
|
+
@afk_channel_id = data[:afk_channel_id]
|
1841
|
+
@afk_timeout = data[:afk_timeout]
|
1842
|
+
@widget_enabled = data[:widget_enabled]
|
1843
|
+
@widget_channel_id = data[:widget_channel_id]
|
1844
|
+
@roles = Dictionary.new
|
1845
|
+
data[:roles].each { |r| @roles[r[:id]] = Role.new(@client, self, r) }
|
1846
|
+
@emojis = Dictionary.new
|
1847
|
+
data[:emojis].map do |e|
|
1848
|
+
@emojis[e[:id]] = CustomEmoji.new(@client, self, e)
|
1849
|
+
end
|
1850
|
+
@features = data[:features].map { |f| f.downcase.to_sym }
|
1851
|
+
@mfa_level = MFA_LEVELS[data[:mfa_level]]
|
1852
|
+
@verification_level = VERIFICATION_LEVELS[data[:verification_level]]
|
1853
|
+
@default_message_notifications =
|
1854
|
+
DEFAULT_MESSAGE_NOTIFICATIONS[data[:default_message_notifications]]
|
1855
|
+
@explicit_content_filter =
|
1856
|
+
EXPLICIT_CONTENT_FILTER[data[:explicit_content_filter]]
|
1857
|
+
@system_channel_id = data[:system_channel_id]
|
1858
|
+
@system_channel_flag =
|
1859
|
+
SystemChannelFlag.new(0b111 - data[:system_channel_flags])
|
1860
|
+
@rules_channel_id = data[:rules_channel_id]
|
1861
|
+
@vanity_url_code = data[:vanity_url_code]
|
1862
|
+
@description = data[:description]
|
1863
|
+
@banner =
|
1864
|
+
data[:banner] && Asset.new(self, data[:banner], path: "banners/#{@id}")
|
1865
|
+
@premium_tier = data[:premium_tier]
|
1866
|
+
@premium_subscription_count = data[:premium_tier_count].to_i
|
1867
|
+
@preferred_locale = data[:preferred_locale].gsub("-", "_").to_sym
|
1868
|
+
@public_updates_channel_id = data[:public_updates_channel_id]
|
1869
|
+
@max_video_channel_users = data[:max_video_channel_users]
|
1870
|
+
@approximate_member_count = data[:approximate_member_count]
|
1871
|
+
@approximate_presence_count = data[:approximate_presence_count]
|
1872
|
+
@welcome_screen =
|
1873
|
+
(
|
1874
|
+
if data[:welcome_screen].nil?
|
1875
|
+
nil
|
1876
|
+
else
|
1877
|
+
WelcomeScreen.new(@client, self, data[:welcome_screen])
|
1878
|
+
end
|
1879
|
+
)
|
1880
|
+
@nsfw_level = NSFW_LEVELS[data[:nsfw_level]]
|
1881
|
+
return unless is_create_event
|
1882
|
+
|
1883
|
+
@stickers =
|
1884
|
+
(
|
1885
|
+
if data[:stickers].nil?
|
1886
|
+
[]
|
1887
|
+
else
|
1888
|
+
data[:stickers].map { |s| Sticker::GuildSticker.new(@client, s) }
|
1889
|
+
end
|
1890
|
+
)
|
1891
|
+
@joined_at = Time.iso8601(data[:joined_at])
|
1892
|
+
@large = data[:large]
|
1893
|
+
@member_count = data[:member_count]
|
1894
|
+
tmp_channels =
|
1895
|
+
data[:channels]
|
1896
|
+
.filter { |c| !c.key?(:thread_metadata) }
|
1897
|
+
.map { |c| Channel.make_channel(@client, c.merge({ guild_id: @id })) }
|
1898
|
+
@channels =
|
1899
|
+
Dictionary.new(
|
1900
|
+
tmp_channels.to_h { |c| [c.id, c] },
|
1901
|
+
sort: ->(c) { c[1].position }
|
1902
|
+
)
|
1903
|
+
@voice_states =
|
1904
|
+
Dictionary.new(
|
1905
|
+
data[:voice_states].to_h do |v|
|
1906
|
+
[
|
1907
|
+
Snowflake.new(v[:user_id]),
|
1908
|
+
VoiceState.new(@client, v.merge({ guild_id: @id }))
|
1909
|
+
]
|
1910
|
+
end
|
1911
|
+
)
|
1912
|
+
@threads =
|
1913
|
+
(
|
1914
|
+
if data[:threads]
|
1915
|
+
data[:threads].map { |t| Channel.make_channel(@client, t) }
|
1916
|
+
else
|
1917
|
+
[]
|
1918
|
+
end
|
1919
|
+
)
|
1920
|
+
@presences =
|
1921
|
+
Dictionary.new(
|
1922
|
+
data[:presences].to_h do |pr|
|
1923
|
+
[Snowflake.new(pr[:user][:id]), Presence.new(@client, pr)]
|
1924
|
+
end
|
1925
|
+
)
|
1926
|
+
@max_presences = data[:max_presences]
|
1927
|
+
@stage_instances =
|
1928
|
+
Dictionary.new(
|
1929
|
+
data[:stage_instances].to_h do |s|
|
1930
|
+
[Snowflake.new(s[:id]), StageInstance.new(@client, s)]
|
1931
|
+
end
|
1932
|
+
)
|
1933
|
+
@scheduled_events =
|
1934
|
+
Dictionary.new(
|
1935
|
+
data[:guild_scheduled_events].to_h do |s|
|
1936
|
+
[Snowflake.new(s[:id]), ScheduledEvent.new(@client, s)]
|
1937
|
+
end
|
1938
|
+
)
|
1939
|
+
@data.update(data)
|
1940
|
+
end
|
1941
|
+
end
|
1942
|
+
|
1943
|
+
#
|
1944
|
+
# Represents a system channel flag.
|
1945
|
+
# ## Flag fields
|
1946
|
+
# |Field|Value|
|
1947
|
+
# |-|-|
|
1948
|
+
# |`1 << 0`|`:member_join`|
|
1949
|
+
# |`1 << 1`|`:server_boost`|
|
1950
|
+
# |`1 << 2`|`:setup_tips`|
|
1951
|
+
# |`1 << 3`|`:join_stickers`|
|
1952
|
+
#
|
1953
|
+
class SystemChannelFlag < Flag
|
1954
|
+
@bits = {
|
1955
|
+
member_join: 0,
|
1956
|
+
server_boost: 1,
|
1957
|
+
setup_tips: 2,
|
1958
|
+
join_stickers: 3
|
1959
|
+
}.freeze
|
1960
|
+
end
|
1961
|
+
|
1962
|
+
#
|
1963
|
+
# Represents a welcome screen.
|
1964
|
+
#
|
1965
|
+
class WelcomeScreen < DiscordModel
|
1966
|
+
# @return [String] The description of the welcome screen.
|
1967
|
+
attr_reader :description
|
1968
|
+
# @return [Array<Discorb::WelcomeScreen::Channel>] The channels to display the welcome screen.
|
1969
|
+
attr_reader :channels
|
1970
|
+
# @return [Discorb::Guild] The guild the welcome screen belongs to.
|
1971
|
+
attr_reader :guild
|
1972
|
+
|
1973
|
+
#
|
1974
|
+
# Initializes the welcome screen.
|
1975
|
+
# @private
|
1976
|
+
#
|
1977
|
+
# @param [Discorb::Client] client The client.
|
1978
|
+
# @param [Discorb::Guild] guild The guild the welcome screen belongs to.
|
1979
|
+
# @param [Hash] data The data of the welcome screen.
|
1980
|
+
#
|
1981
|
+
def initialize(client, guild, data)
|
1982
|
+
@client = client
|
1983
|
+
@description = data[:description]
|
1984
|
+
@guild = guild
|
1985
|
+
@channels =
|
1986
|
+
data[:channels].map do |c|
|
1987
|
+
WelcomeScreen::Channel.new(
|
1988
|
+
client.channels[c[:channel_id]],
|
1989
|
+
c,
|
1990
|
+
c[:emoji_name] &&
|
1991
|
+
if c[:emoji_id]
|
1992
|
+
(
|
1993
|
+
client.emojis[c[:emoji_id]] ||
|
1994
|
+
Discorb::PartialEmoji.new(
|
1995
|
+
{ name: c[:emoji_name], id: c[:emoji_id] }
|
1996
|
+
)
|
1997
|
+
)
|
1998
|
+
else
|
1999
|
+
Discorb::UnicodeEmoji.new(c[:emoji_name])
|
2000
|
+
end
|
2001
|
+
)
|
2002
|
+
end
|
2003
|
+
end
|
2004
|
+
|
2005
|
+
#
|
2006
|
+
# Represents a channel to display the welcome screen.
|
2007
|
+
#
|
2008
|
+
class Channel < DiscordModel
|
2009
|
+
# @return [String] The channel's name.
|
2010
|
+
attr_reader :description
|
2011
|
+
|
2012
|
+
# @!attribute [r] emoji
|
2013
|
+
# @return [Discorb::Emoji] The emoji to display.
|
2014
|
+
# @!attribute [r] channel
|
2015
|
+
# @macro client_cache
|
2016
|
+
# @return [Discorb::Channel] The channel to display the welcome screen.
|
2017
|
+
|
2018
|
+
#
|
2019
|
+
# Initialize a new welcome screen channel.
|
2020
|
+
#
|
2021
|
+
# @param [Discorb::TextChannel] channel The channel to display the welcome screen.
|
2022
|
+
# @param [String] description The channel's name.
|
2023
|
+
# @param [Discorb::Emoji] emoji The emoji to display.
|
2024
|
+
#
|
2025
|
+
def initialize(channel, description, emoji)
|
2026
|
+
if description.is_a?(Hash)
|
2027
|
+
@screen = channel
|
2028
|
+
data = description
|
2029
|
+
@channel_id = Snowflake.new(data[:channel_id])
|
2030
|
+
@description = data[:description]
|
2031
|
+
@emoji_id = Snowflake.new(data[:emoji_id])
|
2032
|
+
@emoji_name = data[:emoji_name]
|
2033
|
+
else
|
2034
|
+
@channel_id = channel.id
|
2035
|
+
@description = description
|
2036
|
+
if emoji.is_a?(UnicodeEmoji)
|
2037
|
+
@emoji_id = nil
|
2038
|
+
@emoji_name = emoji.value
|
2039
|
+
else
|
2040
|
+
@emoji_id = emoji.id
|
2041
|
+
@emoji_name = emoji.name
|
2042
|
+
end
|
2043
|
+
end
|
2044
|
+
end
|
2045
|
+
|
2046
|
+
#
|
2047
|
+
# Converts the channel to a hash.
|
2048
|
+
#
|
2049
|
+
# @return [Hash] The hash.
|
2050
|
+
# @see https://discord.com/developers/docs/resources/guild#welcome-screen-object
|
2051
|
+
#
|
2052
|
+
def to_hash
|
2053
|
+
{
|
2054
|
+
channel_id: @channel_id,
|
2055
|
+
description: @description,
|
2056
|
+
emoji_id: @emoji_id,
|
2057
|
+
emoji_name: @emoji_name
|
2058
|
+
}
|
2059
|
+
end
|
2060
|
+
|
2061
|
+
def channel
|
2062
|
+
@screen.guild.channels[@channel_id]
|
2063
|
+
end
|
2064
|
+
|
2065
|
+
def emoji
|
2066
|
+
if @emoji_id.nil?
|
2067
|
+
UnicodeEmoji.new(@emoji_name)
|
2068
|
+
else
|
2069
|
+
@screen.guild.emojis[@emoji_id]
|
2070
|
+
end
|
2071
|
+
end
|
2072
|
+
|
2073
|
+
#
|
2074
|
+
# Edits the welcome screen.
|
2075
|
+
# @async
|
2076
|
+
# @macro edit
|
2077
|
+
#
|
2078
|
+
# @param [Boolean] enabled Whether the welcome screen is enabled.
|
2079
|
+
# @param [Array<Discorb::WelcomeScreen::Channel>] channels The channels to display the welcome screen.
|
2080
|
+
# @param [String] description The description of the welcome screen.
|
2081
|
+
# @param [String] reason The reason for editing the welcome screen.
|
2082
|
+
#
|
2083
|
+
# @return [Async::Task<void>] The task.
|
2084
|
+
#
|
2085
|
+
def edit(
|
2086
|
+
enabled: Discorb::Unset,
|
2087
|
+
channels: Discorb::Unset,
|
2088
|
+
description: Discorb::Unset,
|
2089
|
+
reason: nil
|
2090
|
+
)
|
2091
|
+
Async do
|
2092
|
+
payload = {}
|
2093
|
+
payload[:enabled] = enabled unless enabled == Discorb::Unset
|
2094
|
+
payload[:welcome_channels] = channels.map(
|
2095
|
+
&:to_hash
|
2096
|
+
) unless channels == Discorb::Unset
|
2097
|
+
payload[:description] = description unless description ==
|
2098
|
+
Discorb::Unset
|
2099
|
+
@client
|
2100
|
+
.http
|
2101
|
+
.request(
|
2102
|
+
Route.new(
|
2103
|
+
"/guilds/#{@guild.id}/welcome-screen",
|
2104
|
+
"//guilds/:guild_id/welcome-screen",
|
2105
|
+
:patch
|
2106
|
+
),
|
2107
|
+
payload,
|
2108
|
+
audit_log_reason: reason
|
2109
|
+
)
|
2110
|
+
.wait
|
2111
|
+
end
|
2112
|
+
end
|
2113
|
+
end
|
2114
|
+
end
|
2115
|
+
end
|