internal override void Update(ClientState state, Model model) { base.Update(state, 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.Attachments.IsSpecified) { API.AttachmentJson[] value = model.Attachments.Value; if (value.Length > 0) { ImmutableArray <Attachment> .Builder 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) { API.EmbedJson[] value = model.Embeds.Value; if (value.Length > 0) { ImmutableArray <Embed> .Builder 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.Stickers.IsSpecified) { StickerJson[] value = model.Stickers.Value; if (value.Length > 0) { ImmutableArray <MessageSticker> .Builder stickers = ImmutableArray.CreateBuilder <MessageSticker>(value.Length); for (int i = 0; i < value.Length; i++) { stickers.Add(value[i].ToEntity()); } _stickers = stickers.ToImmutable(); } else { _stickers = ImmutableArray.Create <MessageSticker>(); } } IReadOnlyCollection <IUser> mentions = ImmutableArray.Create <SocketUnknownUser>(); //Is passed to ParseTags to get real mention collection if (model.UserMentions.IsSpecified) { EntityOrId <UserJson>[] value = model.UserMentions.Value; if (value.Length > 0) { ImmutableArray <SocketUnknownUser> .Builder newMentions = ImmutableArray.CreateBuilder <SocketUnknownUser>(value.Length); for (int i = 0; i < value.Length; i++) { EntityOrId <UserJson> val = value[i]; if (val.Object != null) { newMentions.Add(SocketUnknownUser.Create(Discord, state, val.Object)); } } mentions = newMentions.ToImmutable(); } } if (model.Content.IsSpecified) { string text = model.Content.Value; SocketGuild guild = (Channel as SocketGuildChannel)?.Guild; _tags = MessageHelper.ParseTags(text, Channel, guild, mentions); model.Content = text; } }
internal new static SocketUserMessage Create(DiscordSocketClient discord, ClientState state, SocketUser author, ISocketMessageChannel channel, Model model) { SocketUserMessage entity = new SocketUserMessage(discord, model.Id, channel, author, MessageHelper.GetSource(model)); entity.Update(state, model); return(entity); }
internal new static RestUserMessage Create(BaseDiscordClient discord, IMessageChannel channel, IUser author, Model model) { RestUserMessage entity = new RestUserMessage(discord, model.Id, channel, author, MessageHelper.GetSource(model)); entity.Update(model); return(entity); }
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.Attachments.IsSpecified) { API.AttachmentJson[] value = model.Attachments.Value; if (value.Length > 0) { ImmutableArray <Attachment> .Builder 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) { API.EmbedJson[] value = model.Embeds.Value; if (value.Length > 0) { ImmutableArray <Embed> .Builder 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.Stickers.IsSpecified) { StickerJson[] value = model.Stickers.Value; if (value.Length > 0) { ImmutableArray <MessageSticker> .Builder stickers = ImmutableArray.CreateBuilder <MessageSticker>(value.Length); for (int i = 0; i < value.Length; i++) { stickers.Add(value[i].ToEntity()); } _stickers = stickers.ToImmutable(); } else { _stickers = ImmutableArray.Create <MessageSticker>(); } } ImmutableArray <IUser> mentions = ImmutableArray.Create <IUser>(); if (model.UserMentions.IsSpecified) { EntityOrId <UserJson>[] value = model.UserMentions.Value; if (value.Length > 0) { ImmutableArray <IUser> .Builder newMentions = ImmutableArray.CreateBuilder <IUser>(value.Length); for (int i = 0; i < value.Length; i++) { EntityOrId <UserJson> val = value[i]; if (val.Object != null) { newMentions.Add(RestUser.Create(Discord, val.Object)); } } mentions = newMentions.ToImmutable(); } } if (model.Content.IsSpecified) { string text = model.Content.Value; ulong? guildId = (Channel as IGuildChannel)?.GuildId; IGuild guild = guildId != null ? (Discord as IDiscordClient).GetGuildAsync(guildId.Value, CacheMode.CacheOnly).Result : null; _tags = MessageHelper.ParseTags(text, null, guild, mentions); model.Content = text; } }
/// <inheritdoc /> public async Task ModifyAsync(Action <MessageProperties> func, RequestOptions options = null, AllowedMentions allowedMentions = null) { Model model = await MessageHelper.ModifyAsync(this, Discord, func, options, allowedMentions).ConfigureAwait(false); Update(model); }