internal override void Update(Model model) { base.Update(model); if (model.IsTextToSpeech.IsSpecified) { _isTTS = model.IsTextToSpeech.Value; } if (model.Pinned.IsSpecified) { _isPinned = model.Pinned.Value; } if (model.EditedTimestamp.IsSpecified) { _editedTimestampTicks = model.EditedTimestamp.Value?.UtcTicks; } if (model.MentionEveryone.IsSpecified) { _isMentioningEveryone = model.MentionEveryone.Value; } if (model.Flags.IsSpecified) { _isSuppressed = model.Flags.Value.HasFlag(API.MessageFlags.Suppressed); } if (model.RoleMentions.IsSpecified) { _roleMentionIds = model.RoleMentions.Value.ToImmutableArray(); } if (model.Attachments.IsSpecified) { var value = model.Attachments.Value; if (value.Length > 0) { var attachments = ImmutableArray.CreateBuilder <Attachment>(value.Length); for (int i = 0; i < value.Length; i++) { attachments.Add(Attachment.Create(value[i])); } _attachments = attachments.ToImmutable(); } else { _attachments = ImmutableArray.Create <Attachment>(); } } if (model.Embeds.IsSpecified) { var value = model.Embeds.Value; if (value.Length > 0) { var embeds = ImmutableArray.CreateBuilder <Embed>(value.Length); for (int i = 0; i < value.Length; i++) { embeds.Add(value[i].ToEntity()); } _embeds = embeds.ToImmutable(); } else { _embeds = ImmutableArray.Create <Embed>(); } } if (model.UserMentions.IsSpecified) { var value = model.UserMentions.Value; if (value.Length > 0) { var newMentions = ImmutableArray.CreateBuilder <RestUser>(value.Length); for (int i = 0; i < value.Length; i++) { var val = value[i]; if (val.Object != null) { newMentions.Add(RestUser.Create(Discord, val.Object)); } } _userMentions = newMentions.ToImmutable(); } } if (model.Content.IsSpecified) { var text = model.Content.Value; var guildId = (Channel as IGuildChannel)?.GuildId; var guild = guildId != null ? (Discord as IDiscordClient).GetGuildAsync(guildId.Value, CacheMode.CacheOnly).Result : null; _tags = MessageHelper.ParseTags(text, null, guild, _userMentions); model.Content = text; } }
internal override void Update(Model model) { base.Update(model); if (model.IsTextToSpeech.IsSpecified) { _isTTS = model.IsTextToSpeech.Value; } if (model.Pinned.IsSpecified) { _isPinned = model.Pinned.Value; } if (model.EditedTimestamp.IsSpecified) { _editedTimestampTicks = model.EditedTimestamp.Value?.UtcTicks; } if (model.MentionEveryone.IsSpecified) { _isMentioningEveryone = model.MentionEveryone.Value; } if (model.RoleMentions.IsSpecified) { _roleMentionIds = model.RoleMentions.Value.ToImmutableArray(); } if (model.Attachments.IsSpecified) { var value = model.Attachments.Value; if (value.Length > 0) { var attachments = ImmutableArray.CreateBuilder <Attachment>(value.Length); for (int i = 0; i < value.Length; i++) { attachments.Add(Attachment.Create(value[i])); } _attachments = attachments.ToImmutable(); } else { _attachments = ImmutableArray.Create <Attachment>(); } } if (model.Embeds.IsSpecified) { var value = model.Embeds.Value; if (value.Length > 0) { var embeds = ImmutableArray.CreateBuilder <Embed>(value.Length); for (int i = 0; i < value.Length; i++) { embeds.Add(value[i].ToEntity()); } _embeds = embeds.ToImmutable(); } else { _embeds = ImmutableArray.Create <Embed>(); } } var guildId = (Channel as IGuildChannel)?.GuildId; var guild = guildId != null ? (Discord as IDiscordClient).GetGuildAsync(guildId.Value, CacheMode.CacheOnly).Result : null; if (model.Content.IsSpecified) { var text = model.Content.Value; _tags = MessageHelper.ParseTags(text, null, guild, MentionedUsers); model.Content = text; } if (model.ReferencedMessage.IsSpecified && model.ReferencedMessage.Value != null) { var refMsg = model.ReferencedMessage.Value; IUser refMsgAuthor = MessageHelper.GetAuthor(Discord, guild, refMsg.Author.Value, refMsg.WebhookId.ToNullable()); _referencedMessage = RestUserMessage.Create(Discord, Channel, refMsgAuthor, refMsg); } if (model.StickerItems.IsSpecified) { var value = model.StickerItems.Value; if (value.Length > 0) { var stickers = ImmutableArray.CreateBuilder <StickerItem>(value.Length); for (int i = 0; i < value.Length; i++) { stickers.Add(new StickerItem(Discord, value[i])); } _stickers = stickers.ToImmutable(); } else { _stickers = ImmutableArray.Create <StickerItem>(); } } }