|
|
@@ -36,7 +36,59 @@ namespace Discord.Webhook |
|
|
|
var model = await client.ApiClient.CreateWebhookMessageAsync(client.Webhook.Id, args, options: options).ConfigureAwait(false); |
|
|
|
return model.Id; |
|
|
|
} |
|
|
|
public static async Task<ulong> SendFileAsync(DiscordWebhookClient client, string filePath, string text, bool isTTS, |
|
|
|
public static async Task ModifyMessageAsync(DiscordWebhookClient client, ulong messageId, |
|
|
|
Action<WebhookMessageProperties> func, RequestOptions options) |
|
|
|
{ |
|
|
|
var args = new WebhookMessageProperties(); |
|
|
|
func(args); |
|
|
|
|
|
|
|
if (args.AllowedMentions.IsSpecified) |
|
|
|
{ |
|
|
|
var allowedMentions = args.AllowedMentions.Value; |
|
|
|
Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), |
|
|
|
"A max of 100 role Ids are allowed."); |
|
|
|
Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), |
|
|
|
"A max of 100 user Ids are allowed."); |
|
|
|
|
|
|
|
// check that user flag and user Id list are exclusive, same with role flag and role Id list |
|
|
|
if (allowedMentions?.AllowedTypes != null) |
|
|
|
{ |
|
|
|
if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && |
|
|
|
allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) |
|
|
|
{ |
|
|
|
throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", |
|
|
|
nameof(allowedMentions)); |
|
|
|
} |
|
|
|
|
|
|
|
if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && |
|
|
|
allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) |
|
|
|
{ |
|
|
|
throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", |
|
|
|
nameof(allowedMentions)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var apiArgs = new ModifyWebhookMessageParams |
|
|
|
{ |
|
|
|
Content = args.Content.IsSpecified ? args.Content.Value : Optional.Create<string>(), |
|
|
|
Embeds = |
|
|
|
args.Embeds.IsSpecified |
|
|
|
? args.Embeds.Value.Select(embed => embed.ToModel()).ToArray() |
|
|
|
: Optional.Create<API.Embed[]>(), |
|
|
|
AllowedMentions = args.AllowedMentions.IsSpecified |
|
|
|
? args.AllowedMentions.Value.ToModel() |
|
|
|
: Optional.Create<API.AllowedMentions>() |
|
|
|
}; |
|
|
|
|
|
|
|
await client.ApiClient.ModifyWebhookMessageAsync(client.Webhook.Id, messageId, apiArgs, options) |
|
|
|
.ConfigureAwait(false); |
|
|
|
} |
|
|
|
public static async Task DeleteMessageAsync(DiscordWebhookClient client, ulong messageId, RequestOptions options) |
|
|
|
{ |
|
|
|
await client.ApiClient.DeleteWebhookMessageAsync(client.Webhook.Id, messageId, options).ConfigureAwait(false); |
|
|
|
} |
|
|
|
public static async Task<ulong> SendFileAsync(DiscordWebhookClient client, string filePath, string text, bool isTTS, |
|
|
|
IEnumerable<Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, bool isSpoiler) |
|
|
|
{ |
|
|
|
string filename = Path.GetFileName(filePath); |
|
|
|