parse method

  1. @override
User parse(
  1. Map<String, Object?> raw
)
override

Parse the raw data received from the API into an instance of the type of this manager.

Implementation

@override
User parse(Map<String, Object?> raw) {
  final hasAccentColor = raw['accent_color'] != null;
  final hasLocale = raw['locale'] != null;
  final hasFlags = raw['flags'] != null;
  final hasPremiumType = raw['premium_type'] != null;
  final hasPublicFlags = raw['public_flags'] != null;

  return User(
    manager: this,
    id: Snowflake.parse(raw['id']!),
    username: raw['username'] as String,
    discriminator: raw['discriminator'] as String,
    globalName: raw['global_name'] as String?,
    avatarHash: raw['avatar'] as String?,
    isBot: raw['bot'] as bool? ?? false,
    isSystem: raw['system'] as bool? ?? false,
    hasMfaEnabled: raw['mfa_enabled'] as bool? ?? false,
    bannerHash: raw['banner'] as String?,
    accentColor: hasAccentColor ? DiscordColor(raw['accent_color'] as int) : null,
    locale: hasLocale ? Locale.parse(raw['locale'] as String) : null,
    flags: hasFlags ? UserFlags(raw['flags'] as int) : null,
    nitroType: hasPremiumType ? NitroType.parse(raw['premium_type'] as int) : NitroType.none,
    publicFlags: hasPublicFlags ? UserFlags(raw['public_flags'] as int) : null,
    avatarDecorationHash: raw['avatar_decoration'] as String?,
  );
}