[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>
|
/// <returns>
|
||||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||||
/// </returns>
|
/// </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>
|
/// <summary>
|
||||||
/// Creates a new sticker in this guild.
|
/// Creates a new sticker in this guild.
|
||||||
@@ -1117,7 +1117,7 @@ namespace Discord
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||||
/// </returns>
|
/// </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>
|
/// <summary>
|
||||||
/// Creates a new sticker in this guild.
|
/// Creates a new sticker in this guild.
|
||||||
@@ -1131,7 +1131,7 @@ namespace Discord
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||||
/// </returns>
|
/// </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>
|
/// <summary>
|
||||||
/// Gets a specific sticker within this guild.
|
/// Gets a specific sticker within this guild.
|
||||||
|
|||||||
@@ -17,10 +17,14 @@ namespace Discord.API.Rest
|
|||||||
var d = new Dictionary<string, object>
|
var d = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
["name"] = $"{Name}",
|
["name"] = $"{Name}",
|
||||||
["description"] = Description,
|
|
||||||
["tags"] = Tags
|
["tags"] = Tags
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (Description is not null)
|
||||||
|
d["description"] = Description;
|
||||||
|
else
|
||||||
|
d["description"] = string.Empty;
|
||||||
|
|
||||||
string contentType;
|
string contentType;
|
||||||
if (File is FileStream fileStream)
|
if (File is FileStream fileStream)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -708,49 +708,67 @@ namespace Discord.Rest
|
|||||||
public static Task DeleteEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options)
|
public static Task DeleteEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options)
|
||||||
=> client.ApiClient.DeleteGuildEmoteAsync(guild.Id, id, 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,
|
public static async Task<API.Sticker> CreateStickerAsync(BaseDiscordClient client, IGuild guild, string name, Image image, IEnumerable<string> tags,
|
||||||
Image image, RequestOptions options = null)
|
string description = null, RequestOptions options = null)
|
||||||
{
|
{
|
||||||
Preconditions.NotNull(name, nameof(name));
|
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(name.Length, 2, nameof(name));
|
||||||
Preconditions.AtLeast(description.Length, 2, nameof(description));
|
|
||||||
|
|
||||||
Preconditions.AtMost(name.Length, 30, nameof(name));
|
Preconditions.AtMost(name.Length, 30, nameof(name));
|
||||||
Preconditions.AtMost(description.Length, 100, nameof(name));
|
|
||||||
|
|
||||||
var apiArgs = new CreateStickerParams()
|
var apiArgs = new CreateStickerParams()
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
Description = description,
|
Description = description,
|
||||||
File = image.Stream,
|
File = image.Stream,
|
||||||
Tags = string.Join(", ", tags)
|
Tags = tagString
|
||||||
};
|
};
|
||||||
|
|
||||||
return await client.ApiClient.CreateGuildStickerAsync(apiArgs, guild.Id, options).ConfigureAwait(false);
|
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,
|
public static async Task<API.Sticker> CreateStickerAsync(BaseDiscordClient client, IGuild guild, string name, Stream file, string filename, IEnumerable<string> tags,
|
||||||
Stream file, string filename, RequestOptions options = null)
|
string description = null, RequestOptions options = null)
|
||||||
{
|
{
|
||||||
Preconditions.NotNull(name, nameof(name));
|
Preconditions.NotNull(name, nameof(name));
|
||||||
Preconditions.NotNull(description, nameof(description));
|
|
||||||
Preconditions.NotNull(file, nameof(file));
|
Preconditions.NotNull(file, nameof(file));
|
||||||
Preconditions.NotNull(filename, nameof(filename));
|
Preconditions.NotNull(filename, nameof(filename));
|
||||||
|
|
||||||
Preconditions.AtLeast(name.Length, 2, nameof(name));
|
Preconditions.AtLeast(name.Length, 2, nameof(name));
|
||||||
Preconditions.AtLeast(description.Length, 2, nameof(description));
|
|
||||||
|
|
||||||
Preconditions.AtMost(name.Length, 30, nameof(name));
|
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()
|
var apiArgs = new CreateStickerParams()
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
Description = description,
|
Description = description,
|
||||||
File = file,
|
File = file,
|
||||||
Tags = string.Join(", ", tags),
|
Tags = tagString,
|
||||||
FileName = filename
|
FileName = filename
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1051,9 +1051,9 @@ namespace Discord.Rest
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||||
/// </returns>
|
/// </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);
|
return CustomSticker.Create(Discord, model, this, model.User.IsSpecified ? model.User.Value.Id : null);
|
||||||
}
|
}
|
||||||
@@ -1068,11 +1068,11 @@ namespace Discord.Rest
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||||
/// </returns>
|
/// </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)
|
RequestOptions options = null)
|
||||||
{
|
{
|
||||||
var fs = File.OpenRead(path);
|
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>
|
/// <summary>
|
||||||
/// Creates a new sticker in this guild
|
/// Creates a new sticker in this guild
|
||||||
@@ -1086,10 +1086,10 @@ namespace Discord.Rest
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public async Task<CustomSticker> CreateStickerAsync(string name, string description, IEnumerable<string> tags, Stream stream,
|
public async Task<CustomSticker> CreateStickerAsync(string name, Stream stream, string filename, IEnumerable<string> tags,
|
||||||
string filename, RequestOptions options = null)
|
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);
|
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)
|
async Task<IReadOnlyCollection<IApplicationCommand>> IGuild.GetApplicationCommandsAsync(bool withLocalizations, string locale, RequestOptions options)
|
||||||
=> await GetApplicationCommandsAsync(withLocalizations, locale, options).ConfigureAwait(false);
|
=> await GetApplicationCommandsAsync(withLocalizations, locale, options).ConfigureAwait(false);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, string description, IEnumerable<string> tags, Image image, RequestOptions options)
|
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, Image image, IEnumerable<string> tags, string description, RequestOptions options)
|
||||||
=> await CreateStickerAsync(name, description, tags, image, options);
|
=> await CreateStickerAsync(name, image, tags, description, options);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, string description, IEnumerable<string> tags, Stream stream, string filename, RequestOptions options)
|
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, Stream stream, string filename, IEnumerable<string> tags, string description, RequestOptions options)
|
||||||
=> await CreateStickerAsync(name, description, tags, stream, filename, options);
|
=> await CreateStickerAsync(name, stream, filename, tags, description, options);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, string description, IEnumerable<string> tags, string path, RequestOptions options)
|
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, string path, IEnumerable<string> tags, string description, RequestOptions options)
|
||||||
=> await CreateStickerAsync(name, description, tags, path, options);
|
=> await CreateStickerAsync(name, path, tags, description, options);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
async Task<ICustomSticker> IGuild.GetStickerAsync(ulong id, CacheMode mode, RequestOptions options)
|
async Task<ICustomSticker> IGuild.GetStickerAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1540,10 +1540,10 @@ namespace Discord.WebSocket
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||||
/// </returns>
|
/// </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)
|
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);
|
return AddOrUpdateSticker(model);
|
||||||
}
|
}
|
||||||
@@ -1558,11 +1558,11 @@ namespace Discord.WebSocket
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||||
/// </returns>
|
/// </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)
|
RequestOptions options = null)
|
||||||
{
|
{
|
||||||
var fs = File.OpenRead(path);
|
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>
|
/// <summary>
|
||||||
/// Creates a new sticker in this guild
|
/// Creates a new sticker in this guild
|
||||||
@@ -1576,10 +1576,10 @@ namespace Discord.WebSocket
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
/// A task that represents the asynchronous creation operation. The task result contains the created sticker.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public async Task<SocketCustomSticker> CreateStickerAsync(string name, string description, IEnumerable<string> tags, Stream stream,
|
public async Task<SocketCustomSticker> CreateStickerAsync(string name, Stream stream, string filename, IEnumerable<string> tags, string description = null,
|
||||||
string filename, RequestOptions options = 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);
|
return AddOrUpdateSticker(model);
|
||||||
}
|
}
|
||||||
@@ -2111,15 +2111,14 @@ namespace Discord.WebSocket
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
async Task<IReadOnlyCollection<IApplicationCommand>> IGuild.GetApplicationCommandsAsync(bool withLocalizations, string locale, RequestOptions options)
|
async Task<IReadOnlyCollection<IApplicationCommand>> IGuild.GetApplicationCommandsAsync(bool withLocalizations, string locale, RequestOptions options)
|
||||||
=> await GetApplicationCommandsAsync(withLocalizations, locale, options).ConfigureAwait(false);
|
=> 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 />
|
/// <inheritdoc />
|
||||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, string description, IEnumerable<string> tags, Image image, RequestOptions options)
|
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, Stream stream, string filename, IEnumerable<string> tags, string description, RequestOptions options)
|
||||||
=> await CreateStickerAsync(name, description, tags, image, options);
|
=> await CreateStickerAsync(name, stream, filename, tags, description, options);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, string description, IEnumerable<string> tags, Stream stream, string filename, RequestOptions options)
|
async Task<ICustomSticker> IGuild.CreateStickerAsync(string name, string path, IEnumerable<string> tags, string description, RequestOptions options)
|
||||||
=> await CreateStickerAsync(name, description, tags, stream, filename, options);
|
=> await CreateStickerAsync(name, path, 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);
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
async Task<ICustomSticker> IGuild.GetStickerAsync(ulong id, CacheMode mode, RequestOptions options)
|
async Task<ICustomSticker> IGuild.GetStickerAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||||
=> await GetStickerAsync(id, mode, options);
|
=> await GetStickerAsync(id, mode, options);
|
||||||
|
|||||||
Reference in New Issue
Block a user