DmMessage.from constructor

DmMessage.from({
  1. required DmChannel channel,
  2. required dynamic payload,
})

Implementation

factory DmMessage.from({ required DmChannel channel, required dynamic payload }) {
  MineralClient client = ioc.use<MineralClient>();
  User? user = client.users.cache.get(payload['author']['id']);

  List<EmbedBuilder> embeds = [];
  if (payload['embeds'] != null) {
    for (dynamic element in payload['embeds']) {
      embeds.add(EmbedBuilder.from(element));
    }
  }
  List<MessageStickerItem> stickers = [];
  if (payload['sticker_items'] != null) {
    for (dynamic element in payload['sticker_items']) {
      MessageStickerItem sticker = MessageStickerItem.from(element);
      stickers.add(sticker);
    }
  }

  List<MessageAttachment> messageAttachments = [];
  if (payload['attachments'] != null) {
    for (dynamic element in payload['attachments']) {
      MessageAttachment attachment = MessageAttachment.from(element);
      messageAttachments.add(attachment);
    }
  }

  ComponentBuilder componentBuilder = ComponentBuilder();
  if (payload['components'] != null) {
    for (dynamic element in payload['components']) {
      componentBuilder.rows.add(ComponentWrapper.wrap(element, payload['guild_id']));
    }
  }

  final message = DmMessage(
    payload['id'],
    payload['content'],
    payload['tts'] ?? false,
    embeds,
    payload['allow_mentions'] ?? false,
    payload['reference'],
    componentBuilder,
    stickers,
    payload['payload'],
    messageAttachments,
    payload['flags'],
    payload['pinned'],
    null,
    channel.id,
    MessageReactionManager<DmChannel, DmMessage>(channel),
    payload['timestamp'],
    payload['edited_timestamp'],
    user!,
  );

  message.reactions.message = message;

  return message;
}