示例#1
0
        public virtual void Update(MessageJsonModel model)
        {
            if (_transientAuthor != null)
            {
                if (model.Member.HasValue)
                {
                    model.Member.Value.User = model.Author;
                    _transientAuthor        = new TransientMember(Client, GuildId.Value, model.Member.Value);
                }
                else
                {
                    _transientAuthor = new TransientUser(Client, model.Author);
                }
            }
            Content        = model.Content;
            MentionedUsers = model.Mentions.ToReadOnlyList(Client, (x, client) =>
            {
                var user = client.GetUser(x.Id);
                if (user != null)
                {
                    return(user);
                }

                return(new TransientUser(client, x) as IUser);
            });
            Reactions = Optional.Convert(model.Reactions, x => x.ToReadOnlyDictionary(x => Emoji.Create(x.Emoji), x => new Reaction(x)));
        }
示例#2
0
 public CachedUserMessage(IGatewayClient client, CachedMember author, MessageJsonModel model)
     : base(client, author, model)
 {
     WebhookId      = model.WebhookId.GetValueOrNullable();
     IsTextToSpeech = model.Tts;
     Nonce          = model.Nonce;
 }
示例#3
0
        /// <summary>
        ///     Creates either a <see cref="TransientGatewayUserMessage"/> or a <see cref="TransientSystemMessage"/> based on the type.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static new IGatewayMessage Create(IClient client, MessageJsonModel model)
        {
            switch ((MessageType)model.Type)
            {
            case MessageType.Default:
            case MessageType.Reply:
            case MessageType.ApplicationCommand:
                return(new TransientGatewayUserMessage(client, model));

            default:
                return(new TransientGatewaySystemMessage(client, model));
            }
        }
        public override void Update(MessageJsonModel model)
        {
            base.Update(model);

            EditedAt          = model.EditedTimestamp;
            IsPinned          = model.Pinned;
            MentionsEveryone  = model.MentionEveryone;
            MentionedRoleIds  = model.MentionRoles.ReadOnly();
            Attachments       = model.Attachments.ToReadOnlyList(model => new TransientAttachment(model));
            Embeds            = model.Embeds.ToReadOnlyList(model => new TransientEmbed(model));
            Activity          = Optional.ConvertOrDefault(model.Activity, model => new TransientMessageActivity(model));
            Application       = Optional.ConvertOrDefault(model.Application, model => new TransientMessageApplication(model));
            Reference         = Optional.ConvertOrDefault(model.MessageReference, model => new TransientMessageReference(model));
            ReferencedMessage = Optional.Convert(model.ReferencedMessage, model => new TransientUserMessage(Client, model) as IUserMessage);

            Components = Optional.ConvertOrDefault(model.Components, (models, client) => models.ToReadOnlyList(client, (model, client) => new TransientRowComponent(client, model) as IRowComponent), Client) ?? Array.Empty <IRowComponent>();
            Stickers   = Optional.ConvertOrDefault(model.StickerItems, models => models.ToReadOnlyList(model => new TransientMessageSticker(model) as IMessageSticker), Array.Empty <IMessageSticker>());
        }
示例#5
0
        public override void Update(MessageJsonModel model)
        {
            base.Update(model);

            EditedAt         = model.EditedTimestamp;
            IsPinned         = model.Pinned;
            MentionsEveryone = model.MentionEveryone;
            MentionedRoleIds = model.MentionRoles.ReadOnly();
            Attachments      = model.Attachments.ToReadOnlyList(x => new Attachment(x));
            Embeds           = model.Embeds.ToReadOnlyList(x => new Embed(x));
            Activity         = Optional.ConvertOrDefault(model.Activity, x => new MessageActivity(x));
            Application      = Optional.ConvertOrDefault(model.Application, x => new MessageApplication(x));
            Reference        = Optional.ConvertOrDefault(model.MessageReference, x => new MessageReference(x));
            Flags            = model.Flags.GetValueOrDefault();
            Stickers         = Optional.ConvertOrDefault(model.Stickers, x => x.ToReadOnlyList(y => new Sticker(y)), Array.Empty <Sticker>());

            if (model.Type == MessageType.Reply || model.ReferencedMessage.GetValueOrDefault() != null)
            {
                // Fix for Discord always sending an empty property.
                ReferencedMessage = Optional.Convert(model.ReferencedMessage, x => new TransientUserMessage(Client, x) as IUserMessage);
            }
        }
示例#6
0
        protected CachedMessage(IGatewayClient client, CachedMember author, MessageJsonModel model)
            : base(client, model.Id)
        {
            ChannelId = model.ChannelId;
            GuildId   = model.GuildId.GetValueOrNullable();
            if (author != null)
            {
                _cachedAuthor = author;
            }
            else
            {
                if (model.Member.HasValue)
                {
                    model.Member.Value.User = model.Author;
                    _transientAuthor        = new TransientMember(Client, GuildId.Value, model.Member.Value);
                }
                else
                {
                    _transientAuthor = new TransientUser(Client, model.Author);
                }
            }

            Update(model);
        }
示例#7
0
 public TransientSystemMessage(IClient client, MessageJsonModel model)
     : base(client, model)
 {
     Type = (SystemMessageType)(model.Type - 1);
 }
示例#8
0
 protected TransientGatewayMessage(IClient client, MessageJsonModel model)
     : base(client, model)
 {
 }
示例#9
0
 public TransientGatewaySystemMessage(IClient client, MessageJsonModel model)
     : base(client, model)
 {
 }
示例#10
0
 public TransientUserMessage(IClient client, MessageJsonModel model)
     : base(client, model)
 {
 }