using System; using System.Collections.Generic; using System.Collections.Immutable; using Model = Discord.API.Rpc.Message; namespace Discord.Rpc { public abstract class RpcMessage : RpcEntity, IMessage { private long _timestampTicks; public IMessageChannel Channel { get; } public RpcUser Author { get; } public string Content { get; private set; } public Color AuthorColor { get; private set; } public DateTimeOffset CreatedAt => DateTimeUtils.FromSnowflake(Id); public virtual bool IsTTS => false; public virtual bool IsPinned => false; public virtual bool IsBlocked => false; public virtual DateTimeOffset? EditedTimestamp => null; public virtual IReadOnlyCollection Attachments => ImmutableArray.Create(); public virtual IReadOnlyCollection Embeds => ImmutableArray.Create(); public virtual IReadOnlyCollection MentionedChannelIds => ImmutableArray.Create(); public virtual IReadOnlyCollection MentionedRoleIds => ImmutableArray.Create(); public virtual IReadOnlyCollection MentionedUserIds => ImmutableArray.Create(); public virtual IReadOnlyCollection Tags => ImmutableArray.Create(); public virtual ulong? WebhookId => null; public bool IsWebhook => WebhookId != null; public DateTimeOffset Timestamp => DateTimeUtils.FromTicks(_timestampTicks); internal RpcMessage(DiscordRpcClient discord, ulong id, IMessageChannel channel, RpcUser author) : base(discord, id) { Channel = channel; Author = author; } internal static RpcMessage Create(DiscordRpcClient discord, ulong channelId, Model model) { //model.ChannelId is always 0, needs to be passed from the event if (model.Type == MessageType.Default) return RpcUserMessage.Create(discord, channelId, model); else return RpcSystemMessage.Create(discord, channelId, model); } internal virtual void Update(Model model) { if (model.Timestamp.IsSpecified) _timestampTicks = model.Timestamp.Value.UtcTicks; if (model.Content.IsSpecified) Content = model.Content.Value; if (model.AuthorColor.IsSpecified) AuthorColor = new Color(Convert.ToUInt32(model.AuthorColor.Value.Substring(1), 16)); } public override string ToString() => Content; MessageType IMessage.Type => MessageType.Default; IUser IMessage.Author => Author; IReadOnlyCollection IMessage.Attachments => Attachments; IReadOnlyCollection IMessage.Embeds => Embeds; } }