Skip to content

Commit 5d854e0

Browse files
committed
Kept adding even more Models (WIP)
1 parent 5f41ee5 commit 5d854e0

18 files changed

+1418
-7
lines changed

lib/src/models/discord_audit_logs.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'discord_channel.dart';
2+
import 'discord_guild_scheduled_event.dart';
23
import 'discord_user.dart';
34

45
class DiscordAuditLogs {

lib/src/models/discord_guild.dart

Lines changed: 237 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import 'discord_channel.dart';
22
import 'discord_emoji.dart';
33
import 'discord_guild_premium_tier.dart';
4+
import 'discord_guild_scheduled_event.dart';
45
import 'discord_mfa_level.dart';
56
import 'discord_nsfw_level.dart';
67
import 'discord_presence_update.dart';
78
import 'discord_stage_instance.dart';
9+
import 'discord_sticker.dart';
810
import 'discord_system_channel_flag.dart';
911
import 'discord_explicit_content_filter_level.dart';
1012
import 'discord_guild_feature.dart';
@@ -48,6 +50,8 @@ class DiscordGuild {
4850
/// true if [the user](https://discord.com/developers/docs/resources/user#get-current-user-guilds)
4951
/// is the owner of the guild
5052
///
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+
///
5155
/// is not always returned, hence the nullable property
5256
final bool? owner;
5357

@@ -57,12 +61,16 @@ class DiscordGuild {
5761
/// total permissions for [the user](https://discord.com/developers/docs/resources/user#get-current-user-guilds)
5862
/// in the guild (excludes overwrites)
5963
///
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+
///
6066
/// is not always returned, hence the nullable property
6167
final String? permissions;
6268

6369
/// [voice region](https://discord.com/developers/docs/resources/voice#voice-region-object)
6470
/// id for the guild (deprecated)
6571
///
72+
/// * This field is deprecated and is replaced by [channel.rtc_region](https://discord.com/developers/docs/resources/channel#channel-object-channel-structure)
73+
///
6674
/// is not always returned, and can be null
6775
final String? region;
6876

@@ -94,7 +102,7 @@ class DiscordGuild {
94102
/// default [message notifications level](https://discord.com/developers/docs/resources/guild#guild-object-default-message-notification-level)
95103
final int defaultMessageNotifications;
96104

97-
late final DiscordMessageNotificationsLevel
105+
late final DiscordMessageNotificationsLevel?
98106
_defaultMessageNotificationsAsEnum;
99107

100108
/// [explicit content filter level](https://discord.com/developers/docs/resources/guild#guild-object-explicit-content-filter-level)
@@ -141,50 +149,68 @@ class DiscordGuild {
141149
/// when this guild was joined at
142150
/// as an ISO 8601 datetime string
143151
///
152+
/// * This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event
153+
///
144154
/// is not always returned, hence the nullable property
145155
final String? joinedAt;
146156

147157
late final DateTime? _joinedAtAsDateTime;
148158

149159
/// true if this is considered a large guild
150160
///
161+
/// * This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event
162+
///
151163
/// is not always returned, hence the nullable property
152164
final bool? large;
153165

154166
/// true if this guild is unavailable due to an outage
155167
///
168+
/// * This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event
169+
///
156170
/// is not always returned, hence the nullable property
157171
final bool? unavailable;
158172

159173
/// total number of members in this guild
160174
///
175+
/// * This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event
176+
///
161177
/// is not always returned, hence the nullable property
162178
final int? memberCount;
163179

164180
/// states of members currently in voice channels;
165181
/// lacks the `guild_id` key
166182
///
183+
/// * This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event
184+
///
167185
/// is not always returned, hence the nullable property
168186
final List<DiscordVoiceState>? voiceStates;
169187

170188
/// users in the guild
171189
///
190+
/// * This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event
191+
///
172192
/// is not always returned, hence the nullable property
173193
final List<DiscordGuildMember>? members;
174194

175195
/// channels in the guild
176196
///
197+
/// * This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event
198+
///
177199
/// is not always returned, hence the nullable property
178200
final List<DiscordChannel>? channels;
179201

180202
/// all active threads in the guild that current user has permission to view
181203
///
204+
/// * This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event
205+
///
182206
/// is not always returned, hence the nullable property
183207
final List<DiscordChannel>? threads;
184208

185209
/// presences of the members in the guild, will only include
186210
/// non-offline members if the size is greater than `large threshold`
187211
///
212+
/// * This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event
213+
///
188214
/// is not always returned, hence the nullable property
189215
final List<DiscordPresenceUpdate>? presences;
190216

@@ -218,7 +244,7 @@ class DiscordGuild {
218244
/// (Server Boost level)
219245
final int premiumTier;
220246

221-
late final DiscordGuildPremiumTier _premiumTierAsEnum;
247+
late final DiscordGuildPremiumTier? _premiumTierAsEnum;
222248

223249
/// the number of boosts this guild currently has
224250
///
@@ -264,10 +290,12 @@ class DiscordGuild {
264290
/// [guild NSFW level](https://discord.com/developers/docs/resources/guild#guild-object-guild-nsfw-level)
265291
final int nsfwLevel;
266292

267-
late final DiscordNsfwLevel _nsfwLevelAsEnum;
293+
late final DiscordNsfwLevel? _nsfwLevelAsEnum;
268294

269295
/// Stage instances in the guild
270296
///
297+
/// * This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event
298+
///
271299
/// is not always returned, hence the nullable property
272300
final List<DiscordStageInstance>? stageInstances;
273301

@@ -278,6 +306,8 @@ class DiscordGuild {
278306

279307
/// the scheduled events in the guild
280308
///
309+
/// * This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event
310+
///
281311
/// is not always returned, hence the nullable property
282312
final List<DiscordGuildScheduledEvent>? guildScheduledEvents;
283313

@@ -389,6 +419,210 @@ class DiscordGuild {
389419
required this.nsfwLevel,
390420
this.stageInstances,
391421
this.stickers,
422+
this.guildScheduledEvents,
392423
required this.premiumProgressBarEnabled,
393424
});
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+
);
394628
}

0 commit comments

Comments
 (0)