GuildPreview.from constructor

GuildPreview.from({
  1. required Guild guild,
  2. required dynamic payload,
})

Implementation

factory GuildPreview.from({ required Guild guild, required dynamic payload }) {
  final Map<Snowflake, Emoji> emojis = {};
  for (final payload in payload['emojis']) {
    emojis.putIfAbsent(payload['id'], () => guild.emojis.cache.getOrFail(payload['id']));
  }

  final Map<Snowflake, Sticker> stickers = {};
  for (final payload in payload['stickers']) {
    stickers.putIfAbsent(payload['id'], () => guild.stickers.cache.getOrFail(payload['id']));
  }

  final List<GuildFeature> features = [];
  for (final payload in payload['features']) {
    final feature = GuildFeature.values.firstWhere((feature) => feature.value == payload);
    features.add(feature);
  }

  return GuildPreview(
    payload['id'],
    payload['name'],
    payload['description'],
    payload['icon'],
    payload['splash'],
    payload['discovery_splash'],
    emojis,
    stickers,
    features,
    payload['approximate_member_count'],
    payload['approximate_presence_count']
  );
}