mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 17:58:26 -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,8 +459,10 @@ 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;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
if (ctx.Message.Stickers.Count is 1 && ctx.Message.Stickers.First() is SocketSticker ss)
|
if (ctx.Message.Stickers.Count is 1 && ctx.Message.Stickers.First() is SocketSticker ss)
|
||||||
{
|
{
|
||||||
name ??= ss.Name;
|
name ??= ss.Name;
|
||||||
@@ -471,6 +473,40 @@ public partial class Utility : NadekoModule
|
|||||||
using var http = _httpFactory.CreateClient();
|
using var http = _httpFactory.CreateClient();
|
||||||
stream = await http.GetStreamAsync(ss.GetStickerUrl());
|
stream = await http.GetStreamAsync(ss.GetStickerUrl());
|
||||||
}
|
}
|
||||||
|
else if (ctx.Message.Attachments.Count is 1 && name is not null)
|
||||||
|
{
|
||||||
|
if (tags.Length == 0)
|
||||||
|
tags = [name];
|
||||||
|
|
||||||
|
if (ctx.Message.Attachments.Count != 1)
|
||||||
|
{
|
||||||
|
await Response().Error(strs.sticker_error).SendAsync();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
else
|
||||||
{
|
{
|
||||||
await Response().Error(strs.sticker_error).SendAsync();
|
await Response().Error(strs.sticker_error).SendAsync();
|
||||||
@@ -479,9 +515,6 @@ public partial class Utility : NadekoModule
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (tags.Length == 0)
|
|
||||||
tags = [name];
|
|
||||||
|
|
||||||
await ctx.Guild.CreateStickerAsync(
|
await ctx.Guild.CreateStickerAsync(
|
||||||
name,
|
name,
|
||||||
stream,
|
stream,
|
||||||
@@ -492,14 +525,16 @@ public partial class Utility : NadekoModule
|
|||||||
|
|
||||||
await ctx.OkAsync();
|
await ctx.OkAsync();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch
|
||||||
|
(Exception ex)
|
||||||
{
|
{
|
||||||
Log.Warning(ex, "Error occurred while adding a sticker: {Message}", ex.Message);
|
Log.Warning(ex, "Error occurred while adding a sticker: {Message}", ex.Message);
|
||||||
await Response().Error(strs.error_occured).SendAsync();
|
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