internal static RestFollowupMessage Create(BaseDiscordClient discord, Model model, string token, IMessageChannel channel) { var entity = new RestFollowupMessage(discord, model.Id, model.Author.IsSpecified ? RestUser.Create(discord, model.Author.Value) : discord.CurrentUser, token, channel); entity.Update(model); return(entity); }
public static async Task<RestFollowupMessage> SendFollowupAsync(BaseDiscordClient client, UploadWebhookFileParams args, string token, IMessageChannel channel, RequestOptions options = null) { var model = await client.ApiClient.CreateInteractionFollowupMessageAsync(args, token, options).ConfigureAwait(false); var entity = RestFollowupMessage.Create(client, model, token, channel); return entity; }
public static async Task DeleteFollowupMessageAsync(BaseDiscordClient client, RestFollowupMessage message, RequestOptions options = null) => await client.ApiClient.DeleteInteractionFollowupMessageAsync(message.Id, message.Token, options);
public static async Task <Message> ModifyFollowupMessageAsync(BaseDiscordClient client, RestFollowupMessage message, Action <MessageProperties> func, RequestOptions options = null) { var args = new MessageProperties(); func(args); var embed = args.Embed; var embeds = args.Embeds; bool hasText = args.Content.IsSpecified ? !string.IsNullOrEmpty(args.Content.Value) : !string.IsNullOrEmpty(message.Content); bool hasEmbeds = embed.IsSpecified && embed.Value != null || embeds.IsSpecified && embeds.Value?.Length > 0 || message.Embeds.Any(); bool hasComponents = args.Components.IsSpecified && args.Components.Value != null; if (!hasComponents && !hasText && !hasEmbeds) { Preconditions.NotNullOrEmpty(args.Content.IsSpecified ? args.Content.Value : string.Empty, nameof(args.Content)); } var apiEmbeds = embed.IsSpecified || embeds.IsSpecified ? new List <API.Embed>() : null; if (embed.IsSpecified && embed.Value != null) { apiEmbeds.Add(embed.Value.ToModel()); } if (embeds.IsSpecified && embeds.Value != null) { apiEmbeds.AddRange(embeds.Value.Select(x => x.ToModel())); } Preconditions.AtMost(apiEmbeds?.Count ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed."); var apiArgs = new ModifyInteractionResponseParams { Content = args.Content, Embeds = apiEmbeds?.ToArray() ?? Optional <API.Embed[]> .Unspecified, AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional <API.AllowedMentions> .Unspecified, Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional <API.ActionRowComponent[]> .Unspecified }; return(await client.ApiClient.ModifyInteractionFollowupMessageAsync(apiArgs, message.Id, message.Token, options).ConfigureAwait(false)); }