1
1
import 'discord_channel.dart' ;
2
2
import 'discord_emoji.dart' ;
3
3
import 'discord_guild_premium_tier.dart' ;
4
+ import 'discord_guild_scheduled_event.dart' ;
4
5
import 'discord_mfa_level.dart' ;
5
6
import 'discord_nsfw_level.dart' ;
6
7
import 'discord_presence_update.dart' ;
7
8
import 'discord_stage_instance.dart' ;
9
+ import 'discord_sticker.dart' ;
8
10
import 'discord_system_channel_flag.dart' ;
9
11
import 'discord_explicit_content_filter_level.dart' ;
10
12
import 'discord_guild_feature.dart' ;
@@ -48,6 +50,8 @@ class DiscordGuild {
48
50
/// true if [the user] (https://discord.com/developers/docs/resources/user#get-current-user-guilds)
49
51
/// is the owner of the guild
50
52
///
53
+ /// * This field is only sent when using the [GET Current User Guilds] (https://discord.com/developers/docs/resources/user#get-current-user-guilds) endpoint and are relative to the requested user
54
+ ///
51
55
/// is not always returned, hence the nullable property
52
56
final bool ? owner;
53
57
@@ -57,12 +61,16 @@ class DiscordGuild {
57
61
/// total permissions for [the user] (https://discord.com/developers/docs/resources/user#get-current-user-guilds)
58
62
/// in the guild (excludes overwrites)
59
63
///
64
+ /// * This field is only sent when using the [GET Current User Guilds] (https://discord.com/developers/docs/resources/user#get-current-user-guilds) endpoint and are relative to the requested user
65
+ ///
60
66
/// is not always returned, hence the nullable property
61
67
final String ? permissions;
62
68
63
69
/// [voice region] (https://discord.com/developers/docs/resources/voice#voice-region-object)
64
70
/// id for the guild (deprecated)
65
71
///
72
+ /// * This field is deprecated and is replaced by [channel.rtc_region] (https://discord.com/developers/docs/resources/channel#channel-object-channel-structure)
73
+ ///
66
74
/// is not always returned, and can be null
67
75
final String ? region;
68
76
@@ -94,7 +102,7 @@ class DiscordGuild {
94
102
/// default [message notifications level] (https://discord.com/developers/docs/resources/guild#guild-object-default-message-notification-level)
95
103
final int defaultMessageNotifications;
96
104
97
- late final DiscordMessageNotificationsLevel
105
+ late final DiscordMessageNotificationsLevel ?
98
106
_defaultMessageNotificationsAsEnum;
99
107
100
108
/// [explicit content filter level] (https://discord.com/developers/docs/resources/guild#guild-object-explicit-content-filter-level)
@@ -141,50 +149,68 @@ class DiscordGuild {
141
149
/// when this guild was joined at
142
150
/// as an ISO 8601 datetime string
143
151
///
152
+ /// * This field is only sent within the [GUILD_CREATE] (https://discord.com/developers/docs/topics/gateway#guild-create) event
153
+ ///
144
154
/// is not always returned, hence the nullable property
145
155
final String ? joinedAt;
146
156
147
157
late final DateTime ? _joinedAtAsDateTime;
148
158
149
159
/// true if this is considered a large guild
150
160
///
161
+ /// * This field is only sent within the [GUILD_CREATE] (https://discord.com/developers/docs/topics/gateway#guild-create) event
162
+ ///
151
163
/// is not always returned, hence the nullable property
152
164
final bool ? large;
153
165
154
166
/// true if this guild is unavailable due to an outage
155
167
///
168
+ /// * This field is only sent within the [GUILD_CREATE] (https://discord.com/developers/docs/topics/gateway#guild-create) event
169
+ ///
156
170
/// is not always returned, hence the nullable property
157
171
final bool ? unavailable;
158
172
159
173
/// total number of members in this guild
160
174
///
175
+ /// * This field is only sent within the [GUILD_CREATE] (https://discord.com/developers/docs/topics/gateway#guild-create) event
176
+ ///
161
177
/// is not always returned, hence the nullable property
162
178
final int ? memberCount;
163
179
164
180
/// states of members currently in voice channels;
165
181
/// lacks the `guild_id` key
166
182
///
183
+ /// * This field is only sent within the [GUILD_CREATE] (https://discord.com/developers/docs/topics/gateway#guild-create) event
184
+ ///
167
185
/// is not always returned, hence the nullable property
168
186
final List <DiscordVoiceState >? voiceStates;
169
187
170
188
/// users in the guild
171
189
///
190
+ /// * This field is only sent within the [GUILD_CREATE] (https://discord.com/developers/docs/topics/gateway#guild-create) event
191
+ ///
172
192
/// is not always returned, hence the nullable property
173
193
final List <DiscordGuildMember >? members;
174
194
175
195
/// channels in the guild
176
196
///
197
+ /// * This field is only sent within the [GUILD_CREATE] (https://discord.com/developers/docs/topics/gateway#guild-create) event
198
+ ///
177
199
/// is not always returned, hence the nullable property
178
200
final List <DiscordChannel >? channels;
179
201
180
202
/// all active threads in the guild that current user has permission to view
181
203
///
204
+ /// * This field is only sent within the [GUILD_CREATE] (https://discord.com/developers/docs/topics/gateway#guild-create) event
205
+ ///
182
206
/// is not always returned, hence the nullable property
183
207
final List <DiscordChannel >? threads;
184
208
185
209
/// presences of the members in the guild, will only include
186
210
/// non-offline members if the size is greater than `large threshold`
187
211
///
212
+ /// * This field is only sent within the [GUILD_CREATE] (https://discord.com/developers/docs/topics/gateway#guild-create) event
213
+ ///
188
214
/// is not always returned, hence the nullable property
189
215
final List <DiscordPresenceUpdate >? presences;
190
216
@@ -218,7 +244,7 @@ class DiscordGuild {
218
244
/// (Server Boost level)
219
245
final int premiumTier;
220
246
221
- late final DiscordGuildPremiumTier _premiumTierAsEnum;
247
+ late final DiscordGuildPremiumTier ? _premiumTierAsEnum;
222
248
223
249
/// the number of boosts this guild currently has
224
250
///
@@ -264,10 +290,12 @@ class DiscordGuild {
264
290
/// [guild NSFW level] (https://discord.com/developers/docs/resources/guild#guild-object-guild-nsfw-level)
265
291
final int nsfwLevel;
266
292
267
- late final DiscordNsfwLevel _nsfwLevelAsEnum;
293
+ late final DiscordNsfwLevel ? _nsfwLevelAsEnum;
268
294
269
295
/// Stage instances in the guild
270
296
///
297
+ /// * This field is only sent within the [GUILD_CREATE] (https://discord.com/developers/docs/topics/gateway#guild-create) event
298
+ ///
271
299
/// is not always returned, hence the nullable property
272
300
final List <DiscordStageInstance >? stageInstances;
273
301
@@ -278,6 +306,8 @@ class DiscordGuild {
278
306
279
307
/// the scheduled events in the guild
280
308
///
309
+ /// * This field is only sent within the [GUILD_CREATE] (https://discord.com/developers/docs/topics/gateway#guild-create) event
310
+ ///
281
311
/// is not always returned, hence the nullable property
282
312
final List <DiscordGuildScheduledEvent >? guildScheduledEvents;
283
313
@@ -389,6 +419,210 @@ class DiscordGuild {
389
419
required this .nsfwLevel,
390
420
this .stageInstances,
391
421
this .stickers,
422
+ this .guildScheduledEvents,
392
423
required this .premiumProgressBarEnabled,
393
424
});
425
+
426
+ DiscordVerificationLevel get verificationLevelAsEnum =>
427
+ _verificationLevelAsEnum ?? =
428
+ DiscordVerificationLevel .values[verificationLevel];
429
+
430
+ DiscordMessageNotificationsLevel get defaultMessageNotificationsAsEnum =>
431
+ _defaultMessageNotificationsAsEnum ?? =
432
+ DiscordMessageNotificationsLevel .values[defaultMessageNotifications];
433
+
434
+ DiscordExplicitContentFilterLevel get explicitContentFilterAsEnum =>
435
+ _explicitContentFilterAsEnum ?? =
436
+ DiscordExplicitContentFilterLevel .values[explicitContentFilter];
437
+
438
+ DiscordMfaLevel get mfaLevelAsEnum =>
439
+ _mfaLevelAsEnum ?? = DiscordMfaLevel .values[mfaLevel];
440
+
441
+ // TODO: Unbitset the mask and convert them to a List of Enum for usage
442
+ // List<DiscordSystemChannelFlag> get systemChannelFlagsAsEnum =>
443
+ // _systemChannelFlagsAsEnum ??=
444
+
445
+ DateTime ? get joinedAtAsDateTime {
446
+ if (joinedAt == null ) return null ;
447
+ return _joinedAtAsDateTime ?? = DateTime .parse (joinedAt! );
448
+ }
449
+
450
+ DiscordGuildPremiumTier get premiumTierAsEnum =>
451
+ _premiumTierAsEnum ?? = DiscordGuildPremiumTier .values[premiumTier];
452
+
453
+ DiscordNsfwLevel get nsfwLevelAsEnum =>
454
+ _nsfwLevelAsEnum ?? = DiscordNsfwLevel .values[nsfwLevel];
455
+
456
+ static List <DiscordGuildFeature > _createListFromJson (List <String > features) {
457
+ final list = < DiscordGuildFeature > [];
458
+ for (final feature in features) {
459
+ switch (feature) {
460
+ case "ANIMATED_ICON" :
461
+ list.add (DiscordGuildFeature .animatedIcon);
462
+ break ;
463
+ case "BANNER" :
464
+ list.add (DiscordGuildFeature .banner);
465
+ break ;
466
+ case "COMMERCE" :
467
+ list.add (DiscordGuildFeature .commerce);
468
+ break ;
469
+ case "COMMUNITY" :
470
+ list.add (DiscordGuildFeature .community);
471
+ break ;
472
+ case "DISCOVERABLE" :
473
+ list.add (DiscordGuildFeature .discoverable);
474
+ break ;
475
+ case "FEATURABLE" :
476
+ list.add (DiscordGuildFeature .featurable);
477
+ break ;
478
+ case "INVITE_SPLASH" :
479
+ list.add (DiscordGuildFeature .inviteSplash);
480
+ break ;
481
+ case "MEMBER_VERIFICATION_GATE_ENABLED" :
482
+ list.add (DiscordGuildFeature .memberVerificationGateEnable);
483
+ break ;
484
+ case "MONETIZATION_ENABLED" :
485
+ list.add (DiscordGuildFeature .monetizationEnabled);
486
+ break ;
487
+ case "MORE_STICKERS" :
488
+ list.add (DiscordGuildFeature .moreStickers);
489
+ break ;
490
+ case "NEWS" :
491
+ list.add (DiscordGuildFeature .news);
492
+ break ;
493
+ case "PARTNERED" :
494
+ list.add (DiscordGuildFeature .partnered);
495
+ break ;
496
+ case "PREVIEW_ENABLED" :
497
+ list.add (DiscordGuildFeature .previewEnabled);
498
+ break ;
499
+ case "PRIVATE_THREADS" :
500
+ list.add (DiscordGuildFeature .privateThreads);
501
+ break ;
502
+ case "ROLE_ICONS" :
503
+ list.add (DiscordGuildFeature .roleIcons);
504
+ break ;
505
+ case "SEVEN_DAY_THREAD_ARCHIVE" :
506
+ list.add (DiscordGuildFeature .sevenDayThreadArchive);
507
+ break ;
508
+ case "THREE_DAY_THREAD_ARCHIVE" :
509
+ list.add (DiscordGuildFeature .threeDayThreadArchive);
510
+ break ;
511
+ case "TICKETED_EVENTS_ENABLED" :
512
+ list.add (DiscordGuildFeature .ticketedEventsEnabled);
513
+ break ;
514
+ case "VANITY_URL" :
515
+ list.add (DiscordGuildFeature .vanityUrl);
516
+ break ;
517
+ case "VERIFIED" :
518
+ list.add (DiscordGuildFeature .verified);
519
+ break ;
520
+ case "VIP_REGIONS" :
521
+ list.add (DiscordGuildFeature .vipRegions);
522
+ break ;
523
+ case "WELCOME_SCREEN_ENABLED" :
524
+ list.add (DiscordGuildFeature .welcomeScreenEnabled);
525
+ break ;
526
+ }
527
+ }
528
+ return list;
529
+ }
530
+
531
+ factory DiscordGuild .fromJson (Map <String , dynamic > json) => DiscordGuild (
532
+ id: DiscordSnowflake (json[idEntry] as String ),
533
+ name: json[nameEntry] as String ,
534
+ icon: json[iconEntry] as String ? ,
535
+ iconHash: json[iconHashEntry] as String ? ,
536
+ splash: json[splashEntry] as String ? ,
537
+ discoverySplash: json[discoverySplashEntry] as String ? ,
538
+ owner: json[ownerEntry] as bool ? ,
539
+ ownerId: DiscordSnowflake (json[ownerIdEntry] as String ),
540
+ permissions: json[permissionsEntry] as String ? ,
541
+ region: json[regionEntry] as String ,
542
+ afkChannelId: json[afkChannelIdEntry] != null
543
+ ? DiscordSnowflake (json[afkChannelIdEntry] as String )
544
+ : null ,
545
+ afkTimeout: json[afkTimeoutEntry] as int ,
546
+ widgetEnabled: json[widgetEnabledEntry] as bool ? ,
547
+ widgetChannelId: json[widgetChannelIdEntry] != null
548
+ ? DiscordSnowflake (json[widgetChannelIdEntry] as String )
549
+ : null ,
550
+ verificationLevel: json[verificationLevelEntry] as int ,
551
+ defaultMessageNotifications:
552
+ json[defaultMessageNotificationsEntry] as int ,
553
+ explicitContentFilter: json[explicitContentFilterEntry] as int ,
554
+ roles: List <DiscordRole >.from (
555
+ (json[rolesEntry]).map (DiscordRole .fromJson)),
556
+ emojis: List <DiscordEmoji >.from (
557
+ (json[emojisEntry]).map (DiscordEmoji .fromJson)),
558
+ features: _createListFromJson (json[featuresEntry] as List <String >),
559
+ mfaLevel: json[mfaLevelEntry] as int ,
560
+ applicationId: json[applicationIdEntry] != null
561
+ ? DiscordSnowflake (json[applicationIdEntry] as String )
562
+ : null ,
563
+ systemChannelId: json[systemChannelIdEntry] != null
564
+ ? DiscordSnowflake (json[systemChannelIdEntry] as String )
565
+ : null ,
566
+ systemChannelFlags: json[systemChannelFlagsEntry] as int ,
567
+ rulesChannelId: json[rulesChannelIdEntry] != null
568
+ ? DiscordSnowflake (json[rulesChannelIdEntry] as String )
569
+ : null ,
570
+ joinedAt: json[joinedAtEntry] as String ? ,
571
+ large: json[largeEntry] as bool ? ,
572
+ unavailable: json[unavailableEntry] as bool ? ,
573
+ memberCount: json[memberCountEntry] as int ? ,
574
+ voiceStates: json[voiceStatesEntry] != null
575
+ ? List <DiscordVoiceState >.from (
576
+ (json[voiceStatesEntry]).map (DiscordVoiceState .fromJson))
577
+ : null ,
578
+ members: json[membersEntry] != null
579
+ ? List <DiscordGuildMember >.from (
580
+ (json[membersEntry]).map (DiscordGuildMember .fromJson))
581
+ : null ,
582
+ channels: json[channelsEntry] != null
583
+ ? List <DiscordChannel >.from (
584
+ (json[channelsEntry]).map (DiscordChannel .fromJson))
585
+ : null ,
586
+ threads: json[presencesEntry] != null
587
+ ? List <DiscordChannel >.from (
588
+ (json[presencesEntry]).map (DiscordChannel .fromJson))
589
+ : null ,
590
+ presences: json[presencesEntry] != null
591
+ ? List <DiscordPresenceUpdate >.from (
592
+ (json[presencesEntry]).map (DiscordPresenceUpdate .fromJson))
593
+ : null ,
594
+ maxPresences: json[maxPresencesEntry] as int ? ,
595
+ maxMembers: json[maxMembersEntry] as int ? ,
596
+ vanityUrlCode: json[vanityUrlCodeEntry] as String ? ,
597
+ description: json[descriptionEntry] as String ? ,
598
+ banner: json[bannerEntry] as String ? ,
599
+ premiumTier: json[premiumTierEntry] as int ,
600
+ premiumSubscriptionCount: json[premiumSubscriptionCountEntry] as int ? ,
601
+ preferredLocale: json[preferredLocaleEntry] as String ,
602
+ publicUpdatesChannelId: json[publicUpdatesChannelIdEntry] != null
603
+ ? DiscordSnowflake (json[publicUpdatesChannelIdEntry] as String )
604
+ : null ,
605
+ maxVideoChannelUsers: json[maxVideoChannelUsersEntry] as int ? ,
606
+ approximateMemberCount: json[approximateMemberCountEntry] as int ? ,
607
+ approximatePresenceCount: json[approximatePresenceCountEntry] as int ? ,
608
+ welcomeScreen: json[welcomeScreenEntry] != null
609
+ ? DiscordWelcomeScreen .fromJson (
610
+ json[welcomeScreenEntry] as Map <String , dynamic >)
611
+ : null ,
612
+ nsfwLevel: json[nsfwLevelEntry] as int ,
613
+ stageInstances: json[stageInstancesEntry] != null
614
+ ? List <DiscordStageInstance >.from (
615
+ (json[stageInstancesEntry]).map (DiscordStageInstance .fromJson))
616
+ : null ,
617
+ stickers: json[stickersEntry] != null
618
+ ? List <DiscordSticker >.from (
619
+ (json[stickersEntry]).map (DiscordSticker .fromJson))
620
+ : null ,
621
+ guildScheduledEvents: json[guildScheduledEventsEntry] != null
622
+ ? List <DiscordGuildScheduledEvent >.from (
623
+ (json[guildScheduledEventsEntry])
624
+ .map (DiscordGuildScheduledEvent .fromJson))
625
+ : null ,
626
+ premiumProgressBarEnabled: json[premiumProgressBarEnabledEntry] as bool ,
627
+ );
394
628
}
0 commit comments