예제 #1
0
 /// <summary>
 /// Converts an existing <see cref="SocketUserMessage"/> to an abstracted <see cref="ISocketUserMessage"/> value.
 /// </summary>
 /// <param name="socketUserMessage">The existing <see cref="SocketUserMessage"/> to be abstracted.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="socketUserMessage"/>.</exception>
 /// <returns>An <see cref="ISocketUserMessage"/> that abstracts <paramref name="socketUserMessage"/>.</returns>
 public static ISocketUserMessage Abstract(this SocketUserMessage socketUserMessage)
 => new SocketUserMessageAbstraction(socketUserMessage);
예제 #2
0
 /// <inheritdoc />
 public Task UnpinAsync(RequestOptions options = null)
 => SocketUserMessage.UnpinAsync(options);
예제 #3
0
 public Task ModifySuppressionAsync(bool suppressEmbeds, RequestOptions options = null)
 => SocketUserMessage.ModifySuppressionAsync(suppressEmbeds, options);
예제 #4
0
 /// <inheritdoc />
 public string Resolve(TagHandling userHandling = TagHandling.Name, TagHandling channelHandling = TagHandling.Name, TagHandling roleHandling = TagHandling.Name, TagHandling everyoneHandling = TagHandling.Ignore, TagHandling emojiHandling = TagHandling.Name)
 => SocketUserMessage.Resolve(userHandling, channelHandling, roleHandling, everyoneHandling, emojiHandling);
예제 #5
0
 /// <inheritdoc />
 public Task ModifyAsync(Action <MessageProperties> func, RequestOptions options = null)
 => SocketUserMessage.ModifyAsync(func, options);
예제 #6
0
 /// <summary>
 /// Constructs a new <see cref="SocketUserMessageAbstraction"/> around an existing <see cref="WebSocket.SocketUserMessage"/>.
 /// </summary>
 /// <param name="socketUserMessage">The value to use for <see cref="WebSocket.SocketUserMessage"/>.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="socketUserMessage"/>.</exception>
 public SocketUserMessageAbstraction(SocketUserMessage socketUserMessage)
     : base(socketUserMessage)
 {
 }
예제 #7
0
        internal override void Update(ClientState state, Model model)
        {
            base.Update(state, model);

            SocketGuild guild = (Channel as SocketGuildChannel)?.Guild;

            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)
            {
                _roleMentions = model.RoleMentions.Value.Select(x => guild.GetRole(x)).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.Content.IsSpecified)
            {
                var text = model.Content.Value;
                _tags         = MessageHelper.ParseTags(text, Channel, guild, MentionedUsers);
                model.Content = text;
            }

            if (model.ReferencedMessage.IsSpecified && model.ReferencedMessage.Value != null)
            {
                var        refMsg       = model.ReferencedMessage.Value;
                ulong?     webhookId    = refMsg.WebhookId.ToNullable();
                SocketUser refMsgAuthor = null;
                if (refMsg.Author.IsSpecified)
                {
                    if (guild != null)
                    {
                        if (webhookId != null)
                        {
                            refMsgAuthor = SocketWebhookUser.Create(guild, state, refMsg.Author.Value, webhookId.Value);
                        }
                        else
                        {
                            refMsgAuthor = guild.GetUser(refMsg.Author.Value.Id);
                        }
                    }
                    else
                    {
                        refMsgAuthor = (Channel as SocketChannel).GetUser(refMsg.Author.Value.Id);
                    }
                    if (refMsgAuthor == null)
                    {
                        refMsgAuthor = SocketUnknownUser.Create(Discord, state, refMsg.Author.Value);
                    }
                }
                else
                {
                    // Message author wasn't specified in the payload, so create a completely anonymous unknown user
                    refMsgAuthor = new SocketUnknownUser(Discord, id: 0);
                }
                _referencedMessage = SocketUserMessage.Create(Discord, state, refMsgAuthor, Channel, refMsg);
            }

            if (model.StickerItems.IsSpecified)
            {
                var value = model.StickerItems.Value;
                if (value.Length > 0)
                {
                    var stickers = ImmutableArray.CreateBuilder <SocketSticker>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        var           stickerItem = value[i];
                        SocketSticker sticker     = null;

                        if (guild != null)
                        {
                            sticker = guild.GetSticker(stickerItem.Id);
                        }

                        if (sticker == null)
                        {
                            sticker = Discord.GetSticker(stickerItem.Id);
                        }

                        // if they want to auto resolve
                        if (Discord.AlwaysResolveStickers)
                        {
                            sticker = Task.Run(async() => await Discord.GetStickerAsync(stickerItem.Id).ConfigureAwait(false)).GetAwaiter().GetResult();
                        }

                        // if its still null, create an unknown
                        if (sticker == null)
                        {
                            sticker = SocketUnknownSticker.Create(Discord, stickerItem);
                        }

                        stickers.Add(sticker);
                    }

                    _stickers = stickers.ToImmutable();
                }
                else
                {
                    _stickers = ImmutableArray.Create <SocketSticker>();
                }
            }
        }
예제 #8
0
 /// <inheritdoc />
 public Task CrosspostAsync(RequestOptions options = null)
 => SocketUserMessage.CrosspostAsync(options);