Guild.from constructor

Guild.from({
  1. required EmojiManager emojiManager,
  2. required MemberManager memberManager,
  3. required GuildRoleManager roleManager,
  4. required ChannelManager channelManager,
  5. required ModerationRuleManager moderationRuleManager,
  6. required WebhookManager webhookManager,
  7. required GuildScheduledEventService guildScheduledEventService,
  8. required dynamic payload,
})

Implementation

factory Guild.from({
  required EmojiManager emojiManager,
  required MemberManager memberManager,
  required GuildRoleManager roleManager,
  required ChannelManager channelManager,
  required ModerationRuleManager moderationRuleManager,
  required WebhookManager webhookManager,
  required GuildScheduledEventService guildScheduledEventService,
  required dynamic payload
}) {
  StickerManager stickerManager = StickerManager();

  final List<GuildFeature> features = List<GuildFeature>.from(payload['features'].fold([], (acc, element) {
    GuildFeature? feature = GuildFeature.values.firstWhereOrNull((feature) => feature.value == element);
    if (feature != null) {
      return acc..add(feature);
    }

    ioc.use<ConsoleService>().warn('Guild feature $element don\'t exist! Please report this to our team.');
    return acc;
  }));

  return Guild(
    payload['id'],
    payload['name'],
    payload['owner_id'],
    payload['icon'] != null ? ImageFormater(payload['icon'], 'icons/${payload['id']}') : null,
    payload['icon_hash'],
    payload['splash'] != null ? ImageFormater(payload['splash'], 'splashes/${payload['id']}') : null,
    payload['discovery_splash'] != null ? ImageFormater(payload['discovery_splash'], 'discovery-splashes/${payload['id']}') : null,
    payload['permissions'],
    payload['afk_channel_id'],
    payload['afk_timeout'],
    payload['widget_enabled'] ?? false,
    payload['widget_channel_id'],
    VerificationLevel.values.firstWhere((level) => level.value == payload['verification_level']),
    payload['default_message_notifications'],
    payload['explicit_content_filter'],
    roleManager,
    payload['mfa_level'],
    payload['application_id'],
    payload['system_channel_id'],
    payload['system_channel_flags'],
    payload['rules_channel_id'],
    payload['max_presences'],
    payload['max_members'],
    payload['description'],
    payload['banner'] != null ? ImageFormater(payload['banner'], 'banners/${payload['id']}') : null,
    payload['premium_tier'],
    payload['premium_subscription_count'],
    payload['preferred_locale'],
    payload['public_updates_channel_id'],
    payload['max_video_channel_users'],
    payload['approximate_member_count'],
    payload['approximate_presence_count'],
    payload['welcome_screen'] != null ? WelcomeScreen.from(payload['welcome_screen']) : null,
    payload['nsfw_level'],
    stickerManager,
    payload['premium_progress_bar_enabled'],
    memberManager,
    channelManager,
    emojiManager,
    features,
    moderationRuleManager,
    GuildWebhookManager.fromManager(webhookManager: webhookManager),
    guildScheduledEventService,
    CommandService(payload['id']),
    GuildInviteManager(payload['id'])
  );
}