Exemple #1
0
        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.WebhookId.IsSpecified)
            {
                _webhookId = model.WebhookId.Value;
            }

            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>();
                }
            }

            ImmutableArray <IUser> mentions = ImmutableArray.Create <IUser>();

            if (model.UserMentions.IsSpecified)
            {
                var value = model.UserMentions.Value;
                if (value.Length > 0)
                {
                    var newMentions = ImmutableArray.CreateBuilder <IUser>(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));
                        }
                    }
                    mentions = newMentions.ToImmutable();
                }
            }

            if (model.Reactions.IsSpecified)
            {
                var value = model.Reactions.Value;
                if (value.Length > 0)
                {
                    var reactions = ImmutableArray.CreateBuilder <RestReaction>(value.Length);
                    for (int i = 0; i < value.Length; i++)
                    {
                        reactions.Add(RestReaction.Create(value[i]));
                    }
                    _reactions = reactions.ToImmutable();
                }
                else
                {
                    _reactions = ImmutableArray.Create <RestReaction>();
                }
            }
            else
            {
                _reactions = ImmutableArray.Create <RestReaction>();
            }

            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, mentions);
                model.Content = text;
            }
        }
Exemple #2
0
 public Task <IReadOnlyCollection <IUser> > GetReactionUsersAsync(string emoji, int limit = 100, ulong?afterUserId = null, RequestOptions options = null)
 => MessageHelper.GetReactionUsersAsync(this, emoji, x => { x.Limit = limit; x.AfterUserId = afterUserId.HasValue ? afterUserId.Value : Optional.Create <ulong>(); }, Discord, options);
Exemple #3
0
 public Task UnpinAsync(RequestOptions options)
 => MessageHelper.UnpinAsync(this, Discord, options);
Exemple #4
0
 public Task RemoveReactionAsync(string emoji, IUser user, RequestOptions options = null)
 => MessageHelper.RemoveReactionAsync(this, user, emoji, Discord, options);
Exemple #5
0
 public Task RemoveAllReactionsAsync(RequestOptions options = null)
 => MessageHelper.RemoveAllReactionsAsync(this, Discord, options);
Exemple #6
0
        public async Task ModifyAsync(Action <MessageProperties> func, RequestOptions options)
        {
            var model = await MessageHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false);

            Update(model);
        }
Exemple #7
0
 public Task AddReactionAsync(string emoji, RequestOptions options = null)
 => MessageHelper.AddReactionAsync(this, emoji, Discord, options);
Exemple #8
0
 /// <inheritdoc />
 public Task RemoveReactionAsync(IEmote emote, ulong userId, RequestOptions options = null)
 => MessageHelper.RemoveReactionAsync(this, userId, emote, Discord, options);
Exemple #9
0
 /// <inheritdoc />
 public IAsyncEnumerable <IReadOnlyCollection <IUser> > GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null)
 => MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, options);
Exemple #10
0
 /// <inheritdoc />
 public Task DeleteAsync(RequestOptions options = null)
 => MessageHelper.DeleteAsync(this, Discord, options);
Exemple #11
0
 /// <inheritdoc />
 public Task AddReactionAsync(IEmote emote, RequestOptions options = null)
 => MessageHelper.AddReactionAsync(this, emote, Discord, options);
 public Task RemoveAllReactionsForEmoteAsync(ulong channelId, ulong messageId, IEmote emote, RequestOptions options = null)
 => MessageHelper.RemoveAllReactionsForEmoteAsync(channelId, messageId, emote, this, options);
 public Task AddReactionAsync(ulong channelId, ulong messageId, IEmote emote, RequestOptions options = null)
 => MessageHelper.AddReactionAsync(channelId, messageId, emote, this, options);
        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();
                }
            }

            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, _userMentions);
                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);
            }
        }
 /// <inheritdoc />
 public Task ModifySuppressionAsync(bool suppressEmbeds, RequestOptions options = null)
 => MessageHelper.SuppressEmbedsAsync(this, Discord, suppressEmbeds, options);
 /// <inheritdoc />
 public Task RemoveAllReactionsForEmoteAsync(IEmote emote, RequestOptions options = null)
 => MessageHelper.RemoveAllReactionsForEmoteAsync(this, emote, Discord, options);