[Fix] Allow creating stickers with no description (#2628)
* fix `CreateStickerAsync` methods * Update src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs Co-authored-by: Dmitry <dimson-n@users.noreply.github.com> * fix some parameter names in precontion checks --------- Co-authored-by: Dmitry <dimson-n@users.noreply.github.com>
This commit is contained in:
@@ -1104,7 +1104,7 @@ namespace Discord
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||
/// </returns>
|
||||
Task<ICustomSticker> CreateStickerAsync(string name, string description, IEnumerable<string> tags, Image image, RequestOptions options = null);
|
||||
Task<ICustomSticker> CreateStickerAsync(string name, Image image, IEnumerable<string> tags, string description = null, RequestOptions options = null);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new sticker in this guild.
|
||||
@@ -1117,7 +1117,7 @@ namespace Discord
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||
/// </returns>
|
||||
Task<ICustomSticker> CreateStickerAsync(string name, string description, IEnumerable<string> tags, string path, RequestOptions options = null);
|
||||
Task<ICustomSticker> CreateStickerAsync(string name, string path, IEnumerable<string> tags, string description = null, RequestOptions options = null);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new sticker in this guild.
|
||||
@@ -1131,7 +1131,7 @@ namespace Discord
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||
/// </returns>
|
||||
Task<ICustomSticker> CreateStickerAsync(string name, string description, IEnumerable<string> tags, Stream stream, string filename, RequestOptions options = null);
|
||||
Task<ICustomSticker> CreateStickerAsync(string name, Stream stream, string filename, IEnumerable<string> tags, string description = null, RequestOptions options = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a specific sticker within this guild.
|
||||
|
||||
@@ -17,10 +17,14 @@ namespace Discord.API.Rest
|
||||
var d = new Dictionary<string, object>
|
||||
{
|
||||
["name"] = $"{Name}",
|
||||
["description"] = Description,
|
||||
["tags"] = Tags
|
||||
};
|
||||
|
||||
if (Description is not null)
|
||||
d["description"] = Description;
|
||||
else
|
||||
d["description"] = string.Empty;
|
||||
|
||||
string contentType;
|
||||
if (File is FileStream fileStream)
|
||||
{
|
||||
|
||||
@@ -708,49 +708,67 @@ namespace Discord.Rest
|
||||
public static Task DeleteEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options)
|
||||
=> client.ApiClient.DeleteGuildEmoteAsync(guild.Id, id, options);
|
||||
|
||||
public static async Task<API.Sticker> CreateStickerAsync(BaseDiscordClient client, IGuild guild, string name, string description, IEnumerable<string> tags,
|
||||
Image image, RequestOptions options = null)
|
||||
public static async Task<API.Sticker> CreateStickerAsync(BaseDiscordClient client, IGuild guild, string name, Image image, IEnumerable<string> tags,
|
||||
string description = null, RequestOptions options = null)
|
||||
{
|
||||
Preconditions.NotNull(name, nameof(name));
|
||||
Preconditions.NotNull(description, nameof(description));
|
||||
|
||||
if (description is not null)
|
||||
{
|
||||
Preconditions.AtLeast(description.Length, 2, nameof(description));
|
||||
Preconditions.AtMost(description.Length, 100, nameof(description));
|
||||
}
|
||||
|
||||
var tagString = string.Join(", ", tags);
|
||||
|
||||
Preconditions.AtLeast(tagString.Length, 1, nameof(tags));
|
||||
Preconditions.AtMost(tagString.Length, 200, nameof(tags));
|
||||
|
||||
|
||||
Preconditions.AtLeast(name.Length, 2, nameof(name));
|
||||
Preconditions.AtLeast(description.Length, 2, nameof(description));
|
||||
|
||||
Preconditions.AtMost(name.Length, 30, nameof(name));
|
||||
Preconditions.AtMost(description.Length, 100, nameof(name));
|
||||
|
||||
var apiArgs = new CreateStickerParams()
|
||||
{
|
||||
Name = name,
|
||||
Description = description,
|
||||
File = image.Stream,
|
||||
Tags = string.Join(", ", tags)
|
||||
Tags = tagString
|
||||
};
|
||||
|
||||
return await client.ApiClient.CreateGuildStickerAsync(apiArgs, guild.Id, options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public static async Task<API.Sticker> CreateStickerAsync(BaseDiscordClient client, IGuild guild, string name, string description, IEnumerable<string> tags,
|
||||
Stream file, string filename, RequestOptions options = null)
|
||||
public static async Task<API.Sticker> CreateStickerAsync(BaseDiscordClient client, IGuild guild, string name, Stream file, string filename, IEnumerable<string> tags,
|
||||
string description = null, RequestOptions options = null)
|
||||
{
|
||||
Preconditions.NotNull(name, nameof(name));
|
||||
Preconditions.NotNull(description, nameof(description));
|
||||
Preconditions.NotNull(file, nameof(file));
|
||||
Preconditions.NotNull(filename, nameof(filename));
|
||||
|
||||
Preconditions.AtLeast(name.Length, 2, nameof(name));
|
||||
Preconditions.AtLeast(description.Length, 2, nameof(description));
|
||||
|
||||
Preconditions.AtMost(name.Length, 30, nameof(name));
|
||||
Preconditions.AtMost(description.Length, 100, nameof(name));
|
||||
|
||||
|
||||
if (description is not null)
|
||||
{
|
||||
Preconditions.AtLeast(description.Length, 2, nameof(description));
|
||||
Preconditions.AtMost(description.Length, 100, nameof(description));
|
||||
}
|
||||
|
||||
var tagString = string.Join(", ", tags);
|
||||
|
||||
Preconditions.AtLeast(tagString.Length, 1, nameof(tags));
|
||||
Preconditions.AtMost(tagString.Length, 200, nameof(tags));
|
||||
|
||||
var apiArgs = new CreateStickerParams()
|
||||
{
|
||||
Name = name,
|
||||
Description = description,
|
||||
File = file,
|
||||
Tags = string.Join(", ", tags),
|
||||
Tags = tagString,
|
||||
FileName = filename
|
||||
};
|
||||
|
||||
|
||||
@@ -1051,9 +1051,9 @@ namespace Discord.Rest
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||
/// </returns>
|
||||
public async Task<CustomSticker> CreateStickerAsync(string name, string description, IEnumerable<string> tags, Image image, RequestOptions options = null)
|
||||
public async Task<CustomSticker> CreateStickerAsync(string name, Image image, IEnumerable<string> tags, string description = null, RequestOptions options = null)
|
||||
{
|
||||
var model = await GuildHelper.CreateStickerAsync(Discord, this, name, description, tags, image, options).ConfigureAwait(false);
|
||||
var model = await GuildHelper.CreateStickerAsync(Discord, this, name, image, tags, description, options).ConfigureAwait(false);
|
||||
|
||||
return CustomSticker.Create(Discord, model, this, model.User.IsSpecified ? model.User.Value.Id : null);
|
||||
}
|
||||
@@ -1068,11 +1068,11 @@ namespace Discord.Rest
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||
/// </returns>
|
||||
public Task<CustomSticker> CreateStickerAsync(string name, string description, IEnumerable<string> tags, string path,
|
||||
public Task<CustomSticker> CreateStickerAsync(string name, string path, IEnumerable<string> tags, string description = null,
|
||||
RequestOptions options = null)
|
||||
{
|
||||
var fs = File.OpenRead(path);
|
||||
return CreateStickerAsync(name, description, tags, fs, Path.GetFileName(fs.Name), options);
|
||||
return CreateStickerAsync(name, fs, Path.GetFileName(fs.Name), tags, description,options);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a new sticker in this guild
|
||||
@@ -1086,10 +1086,10 @@ namespace Discord.Rest
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||
/// </returns>
|
||||
public async Task<CustomSticker> CreateStickerAsync(string name, string description, IEnumerable<string> tags, Stream stream,
|
||||
string filename, RequestOptions options = null)
|
||||
public async Task<CustomSticker> CreateStickerAsync(string name, Stream stream, string filename, IEnumerable<string> tags,
|
||||
string description = null, RequestOptions options = null)
|
||||
{
|
||||
var model = await GuildHelper.CreateStickerAsync(Discord, this, name, description, tags, stream, filename, options).ConfigureAwait(false);
|
||||
var model = await GuildHelper.CreateStickerAsync(Discord, this, name, stream, filename, tags, description, options).ConfigureAwait(false);
|
||||
|
||||
return CustomSticker.Create(Discord, model, this, model.User.IsSpecified ? model.User.Value.Id : null);
|
||||
}
|
||||
@@ -1527,14 +1527,14 @@ namespace Discord.Rest
|
||||
async Task<IReadOnlyCollection<IApplicationCommand>> IGuild.GetApplicationCommandsAsync(bool withLocalizations, string locale, RequestOptions options)
|
||||
=> await GetApplicationCommandsAsync(withLocalizations, locale, options).ConfigureAwait(false);
|
||||
/// <inheritdoc />
|
||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, string description, IEnumerable<string> tags, Image image, RequestOptions options)
|
||||
=> await CreateStickerAsync(name, description, tags, image, options);
|
||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, Image image, IEnumerable<string> tags, string description, RequestOptions options)
|
||||
=> await CreateStickerAsync(name, image, tags, description, options);
|
||||
/// <inheritdoc />
|
||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, string description, IEnumerable<string> tags, Stream stream, string filename, RequestOptions options)
|
||||
=> await CreateStickerAsync(name, description, tags, stream, filename, options);
|
||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, Stream stream, string filename, IEnumerable<string> tags, string description, RequestOptions options)
|
||||
=> await CreateStickerAsync(name, stream, filename, tags, description, options);
|
||||
/// <inheritdoc />
|
||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, string description, IEnumerable<string> tags, string path, RequestOptions options)
|
||||
=> await CreateStickerAsync(name, description, tags, path, options);
|
||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, string path, IEnumerable<string> tags, string description, RequestOptions options)
|
||||
=> await CreateStickerAsync(name, path, tags, description, options);
|
||||
/// <inheritdoc />
|
||||
async Task<ICustomSticker> IGuild.GetStickerAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
|
||||
@@ -1540,10 +1540,10 @@ namespace Discord.WebSocket
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||
/// </returns>
|
||||
public async Task<SocketCustomSticker> CreateStickerAsync(string name, string description, IEnumerable<string> tags, Image image,
|
||||
public async Task<SocketCustomSticker> CreateStickerAsync(string name, Image image, IEnumerable<string> tags, string description = null,
|
||||
RequestOptions options = null)
|
||||
{
|
||||
var model = await GuildHelper.CreateStickerAsync(Discord, this, name, description, tags, image, options).ConfigureAwait(false);
|
||||
var model = await GuildHelper.CreateStickerAsync(Discord, this, name, image, tags, description, options).ConfigureAwait(false);
|
||||
|
||||
return AddOrUpdateSticker(model);
|
||||
}
|
||||
@@ -1558,11 +1558,11 @@ namespace Discord.WebSocket
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||
/// </returns>
|
||||
public Task<SocketCustomSticker> CreateStickerAsync(string name, string description, IEnumerable<string> tags, string path,
|
||||
public Task<SocketCustomSticker> CreateStickerAsync(string name, string path, IEnumerable<string> tags, string description = null,
|
||||
RequestOptions options = null)
|
||||
{
|
||||
var fs = File.OpenRead(path);
|
||||
return CreateStickerAsync(name, description, tags, fs, Path.GetFileName(fs.Name), options);
|
||||
return CreateStickerAsync(name, fs, Path.GetFileName(fs.Name), tags, description, options);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a new sticker in this guild
|
||||
@@ -1576,10 +1576,10 @@ namespace Discord.WebSocket
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||
/// </returns>
|
||||
public async Task<SocketCustomSticker> CreateStickerAsync(string name, string description, IEnumerable<string> tags, Stream stream,
|
||||
string filename, RequestOptions options = null)
|
||||
public async Task<SocketCustomSticker> CreateStickerAsync(string name, Stream stream, string filename, IEnumerable<string> tags, string description = null,
|
||||
RequestOptions options = null)
|
||||
{
|
||||
var model = await GuildHelper.CreateStickerAsync(Discord, this, name, description, tags, stream, filename, options).ConfigureAwait(false);
|
||||
var model = await GuildHelper.CreateStickerAsync(Discord, this, name, stream, filename, tags, description, options).ConfigureAwait(false);
|
||||
|
||||
return AddOrUpdateSticker(model);
|
||||
}
|
||||
@@ -2111,15 +2111,14 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc />
|
||||
async Task<IReadOnlyCollection<IApplicationCommand>> IGuild.GetApplicationCommandsAsync(bool withLocalizations, string locale, RequestOptions options)
|
||||
=> await GetApplicationCommandsAsync(withLocalizations, locale, options).ConfigureAwait(false);
|
||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, Image image, IEnumerable<string> tags, string description, RequestOptions options)
|
||||
=> await CreateStickerAsync(name, image, tags, description, options);
|
||||
/// <inheritdoc />
|
||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, string description, IEnumerable<string> tags, Image image, RequestOptions options)
|
||||
=> await CreateStickerAsync(name, description, tags, image, options);
|
||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, Stream stream, string filename, IEnumerable<string> tags, string description, RequestOptions options)
|
||||
=> await CreateStickerAsync(name, stream, filename, tags, description, options);
|
||||
/// <inheritdoc />
|
||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, string description, IEnumerable<string> tags, Stream stream, string filename, RequestOptions options)
|
||||
=> await CreateStickerAsync(name, description, tags, stream, filename, options);
|
||||
/// <inheritdoc />
|
||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, string description, IEnumerable<string> tags, string path, RequestOptions options)
|
||||
=> await CreateStickerAsync(name, description, tags, path, options);
|
||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, string path, IEnumerable<string> tags, string description, RequestOptions options)
|
||||
=> await CreateStickerAsync(name, path, tags, description, options);
|
||||
/// <inheritdoc />
|
||||
async Task<ICustomSticker> IGuild.GetStickerAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
=> await GetStickerAsync(id, mode, options);
|
||||
|
||||
Reference in New Issue
Block a user