mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
fix: Fixed .stickeradd, it now properly supports 300x300 image uploads. closes #434
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
// namespace NadekoBot.Modules.Administration;
|
namespace NadekoBot.Modules.Administration;
|
||||||
//
|
|
||||||
// public partial class Administration
|
public partial class Administration
|
||||||
// {
|
{
|
||||||
// [Group]
|
[Group]
|
||||||
// public partial class TicketCommands : NadekoModule
|
public partial class TicketCommands : NadekoModule
|
||||||
// {
|
{
|
||||||
// [Cmd]
|
[Cmd]
|
||||||
// public async Task Ticket()
|
public async Task Ticket()
|
||||||
// {
|
{
|
||||||
//
|
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
@@ -459,47 +459,82 @@ public partial class Utility : NadekoModule
|
|||||||
public async Task StickerAdd(string name = null, string description = null, params string[] tags)
|
public async Task StickerAdd(string name = null, string description = null, params string[] tags)
|
||||||
{
|
{
|
||||||
string format;
|
string format;
|
||||||
Stream stream;
|
Stream stream = null;
|
||||||
|
|
||||||
if (ctx.Message.Stickers.Count is 1 && ctx.Message.Stickers.First() is SocketSticker ss)
|
|
||||||
{
|
|
||||||
name ??= ss.Name;
|
|
||||||
description = ss.Description;
|
|
||||||
tags = tags is null or { Length: 0 } ? ss.Tags.ToArray() : tags;
|
|
||||||
format = FormatToExtension(ss.Format);
|
|
||||||
|
|
||||||
using var http = _httpFactory.CreateClient();
|
|
||||||
stream = await http.GetStreamAsync(ss.GetStickerUrl());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await Response().Error(strs.sticker_error).SendAsync();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (tags.Length == 0)
|
if (ctx.Message.Stickers.Count is 1 && ctx.Message.Stickers.First() is SocketSticker ss)
|
||||||
tags = [name];
|
{
|
||||||
|
name ??= ss.Name;
|
||||||
|
description = ss.Description;
|
||||||
|
tags = tags is null or { Length: 0 } ? ss.Tags.ToArray() : tags;
|
||||||
|
format = FormatToExtension(ss.Format);
|
||||||
|
|
||||||
await ctx.Guild.CreateStickerAsync(
|
using var http = _httpFactory.CreateClient();
|
||||||
name,
|
stream = await http.GetStreamAsync(ss.GetStickerUrl());
|
||||||
stream,
|
}
|
||||||
$"{name}.{format}",
|
else if (ctx.Message.Attachments.Count is 1 && name is not null)
|
||||||
tags,
|
{
|
||||||
string.IsNullOrWhiteSpace(description) ? "Missing description" : description
|
if (tags.Length == 0)
|
||||||
);
|
tags = [name];
|
||||||
|
|
||||||
await ctx.OkAsync();
|
if (ctx.Message.Attachments.Count != 1)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
await Response().Error(strs.sticker_error).SendAsync();
|
||||||
{
|
return;
|
||||||
Log.Warning(ex, "Error occurred while adding a sticker: {Message}", ex.Message);
|
}
|
||||||
await Response().Error(strs.error_occured).SendAsync();
|
|
||||||
|
var attach = ctx.Message.Attachments.First();
|
||||||
|
|
||||||
|
|
||||||
|
if (attach.Size > 512_000 || attach.Width != 300 || attach.Height != 300)
|
||||||
|
{
|
||||||
|
await Response().Error(strs.sticker_error).SendAsync();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
format = attach.Filename
|
||||||
|
.Split('.')
|
||||||
|
.Last()
|
||||||
|
.ToLowerInvariant();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(format) || (format != "png" && format != "apng"))
|
||||||
|
{
|
||||||
|
await Response().Error(strs.sticker_error).SendAsync();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var http = _httpFactory.CreateClient();
|
||||||
|
stream = await http.GetStreamAsync(attach.Url);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await Response().Error(strs.sticker_error).SendAsync();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await ctx.Guild.CreateStickerAsync(
|
||||||
|
name,
|
||||||
|
stream,
|
||||||
|
$"{name}.{format}",
|
||||||
|
tags,
|
||||||
|
string.IsNullOrWhiteSpace(description) ? "Missing description" : description
|
||||||
|
);
|
||||||
|
|
||||||
|
await ctx.OkAsync();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
(Exception ex)
|
||||||
|
{
|
||||||
|
Log.Warning(ex, "Error occurred while adding a sticker: {Message}", ex.Message);
|
||||||
|
await Response().Error(strs.error_occured).SendAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
await stream.DisposeAsync();
|
await (stream?.DisposeAsync() ?? ValueTask.CompletedTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2289,7 +2289,11 @@ emojiremove:
|
|||||||
- emotes:
|
- emotes:
|
||||||
desc: "The list of emojis to be removed from the server."
|
desc: "The list of emojis to be removed from the server."
|
||||||
stickeradd:
|
stickeradd:
|
||||||
desc: Adds the sticker from your message to this server. Send the sticker along with this command (in the same message).
|
desc: |-
|
||||||
|
Adds the sticker from your message to this server.
|
||||||
|
Send the sticker along with this command (in the same message).
|
||||||
|
Alternatively you can upload an image along with this command but you have to specify the name.
|
||||||
|
The image must be 300x300 in .png or .apng format and up to 512KB in size.
|
||||||
ex:
|
ex:
|
||||||
- ''
|
- ''
|
||||||
- name "description" tag1 tag2 tagN
|
- name "description" tag1 tag2 tagN
|
||||||
|
@@ -1067,8 +1067,7 @@
|
|||||||
"xpshop_already_owned": "You already own this item.",
|
"xpshop_already_owned": "You already own this item.",
|
||||||
"xpshop_item_not_found": "An item with that key doesn't exist.",
|
"xpshop_item_not_found": "An item with that key doesn't exist.",
|
||||||
"xpshop_website": "You can see the list of all Xp Shop items here: <https://xpshop.nadeko.bot>",
|
"xpshop_website": "You can see the list of all Xp Shop items here: <https://xpshop.nadeko.bot>",
|
||||||
"sticker_invalid_size": "Stickers must be exactly 300x300 pixels.",
|
"sticker_error": "You must either send a sticker along with this command, or upload a 300x300 .png or .apng image. Up to 512KB in size.",
|
||||||
"sticker_error": "You must either send a sticker along with this command, or upload a 300x300 .png or .apng image.",
|
|
||||||
"sticker_missing_name": "Please specify a name for the sticker.",
|
"sticker_missing_name": "Please specify a name for the sticker.",
|
||||||
"thread_deleted": "Thread Deleted",
|
"thread_deleted": "Thread Deleted",
|
||||||
"thread_created": "Thread Created",
|
"thread_created": "Thread Created",
|
||||||
|
Reference in New Issue
Block a user