parse method

  1. @override
Guild 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
Guild parse(Map<String, Object?> raw) {
  final id = Snowflake.parse(raw['id']!);

  return Guild(
    id: id,
    manager: this,
    name: raw['name'] as String,
    iconHash: (raw['icon'] ?? raw['icon_hash']) as String?,
    splashHash: raw['splash'] as String?,
    discoverySplashHash: raw['discovery_splash'] as String?,
    isOwnedByCurrentUser: raw['owner'] as bool?,
    ownerId: Snowflake.parse(raw['owner_id']!),
    currentUserPermissions: maybeParse(raw['permissions'], (String permissions) => Permissions(int.parse(permissions))),
    afkChannelId: maybeParse(raw['afk_channel_id'], Snowflake.parse),
    afkTimeout: Duration(seconds: raw['afk_timeout'] as int),
    isWidgetEnabled: raw['widget_enabled'] as bool? ?? false,
    widgetChannelId: maybeParse(raw['widget_channel_id'], Snowflake.parse),
    verificationLevel: VerificationLevel.parse(raw['verification_level'] as int),
    defaultMessageNotificationLevel: MessageNotificationLevel.parse(raw['default_message_notifications'] as int),
    explicitContentFilterLevel: ExplicitContentFilterLevel.parse(raw['explicit_content_filter'] as int),
    roleList: parseMany(raw['roles'] as List, this[id].roles.parse),
    features: parseGuildFeatures(raw['features'] as List),
    mfaLevel: MfaLevel.parse(raw['mfa_level'] as int),
    applicationId: maybeParse(raw['application_id'], Snowflake.parse),
    systemChannelId: maybeParse(raw['system_channel_id'], Snowflake.parse),
    systemChannelFlags: SystemChannelFlags(raw['system_channel_flags'] as int),
    rulesChannelId: maybeParse(raw['rules_channel_id'], Snowflake.parse),
    maxPresences: raw['max_presences'] as int?,
    maxMembers: raw['max_members'] as int?,
    vanityUrlCode: raw['vanity_url_code'] as String?,
    description: raw['description'] as String?,
    bannerHash: raw['banner'] as String?,
    premiumTier: PremiumTier.parse(raw['premium_tier'] as int),
    premiumSubscriptionCount: raw['premium_subscription_count'] as int?,
    preferredLocale: Locale.parse(raw['preferred_locale'] as String),
    publicUpdatesChannelId: maybeParse(raw['public_updates_channel_id'], Snowflake.parse),
    maxVideoChannelUsers: raw['max_video_channel_users'] as int?,
    maxStageChannelUsers: raw['max_stage_video_channel_users'] as int?,
    approximateMemberCount: raw['approximate_member_count'] as int?,
    approximatePresenceCount: raw['approximate_presence_count'] as int?,
    welcomeScreen: maybeParse(raw['welcome_screen'], parseWelcomeScreen),
    nsfwLevel: NsfwLevel.parse(raw['nsfw_level'] as int),
    hasPremiumProgressBarEnabled: raw['premium_progress_bar_enabled'] as bool,
    emojiList: parseMany(raw['emojis'] as List, this[id].emojis.parse),
    stickerList: parseMany(raw['stickers'] as List? ?? [], this[id].stickers.parse),
    safetyAlertsChannelId: maybeParse(raw['safety_alerts_channel_id'], Snowflake.parse),
  );
}