mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Merge branch 'stickeradd' into 'v4'
See merge request Kwoth/nadekobot!276
This commit is contained in:
@@ -147,6 +147,7 @@ This section will guide you through how to create a simple custom medusa. You ca
|
||||
<!-- Use latest .net features -->
|
||||
<LangVersion>preview</LangVersion>
|
||||
<EnablePreviewFeatures>true</EnablePreviewFeatures>
|
||||
<GenerateRequiresPreviewFeaturesAttribute>true</GenerateRequiresPreviewFeaturesAttribute>
|
||||
|
||||
<!-- tell .net that this library will be used as a plugin -->
|
||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||
|
@@ -402,6 +402,99 @@ public partial class Utility : NadekoModule
|
||||
await ctx.OkAsync();
|
||||
}
|
||||
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[BotPerm(GuildPerm.ManageEmojisAndStickers)]
|
||||
[UserPerm(GuildPerm.ManageEmojisAndStickers)]
|
||||
public async Task StickerAdd(string name = null, string description = null, params string[] tags)
|
||||
{
|
||||
string format;
|
||||
Stream stream;
|
||||
|
||||
if (ctx.Message.Stickers.Count is 1 && ctx.Message.Stickers.First() is SocketSticker ss)
|
||||
{
|
||||
name ??= ss.Name;
|
||||
description = ss.Description;
|
||||
format = FormatToExtension(ss.Format);
|
||||
|
||||
using var http = _httpFactory.CreateClient();
|
||||
stream = await http.GetStreamAsync(ss.GetStickerUrl());
|
||||
}
|
||||
// else if (ctx.Message.Attachments.FirstOrDefault() is { } attachment)
|
||||
// {
|
||||
// var url = attachment?.Url;
|
||||
//
|
||||
// if (url is null)
|
||||
// return;
|
||||
//
|
||||
// if (name is null)
|
||||
// {
|
||||
// await ReplyErrorLocalizedAsync(strs.sticker_missing_name);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// format = Path.GetExtension(attachment.Filename);
|
||||
//
|
||||
// if (attachment is not { Width: 300, Height: 300 })
|
||||
// {
|
||||
// await ReplyErrorLocalizedAsync(strs.sticker_invalid_size);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// using var http = _httpFactory.CreateClient();
|
||||
//
|
||||
// using var res = await http.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
|
||||
// if (res.GetContentLength() > 512.Kilobytes().Bytes)
|
||||
// {
|
||||
// await ReplyErrorLocalizedAsync(strs.invalid_emoji_link);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// stream = await res.Content.ReadAsStreamAsync();
|
||||
// }
|
||||
else
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.sticker_error);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await ctx.Guild.CreateStickerAsync(name,
|
||||
string.IsNullOrWhiteSpace(description) ? "Missing description" : description,
|
||||
tags,
|
||||
stream,
|
||||
$"{name}.{format}");
|
||||
|
||||
await ctx.OkAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Error occurred while adding a sticker: {Message}", ex.Message);
|
||||
await ReplyErrorLocalizedAsync(strs.error_occured);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await stream.DisposeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private static string FormatToExtension(StickerFormatType format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case StickerFormatType.None:
|
||||
case StickerFormatType.Png:
|
||||
case StickerFormatType.Apng:
|
||||
return "png";
|
||||
case StickerFormatType.Lottie:
|
||||
return "lottie";
|
||||
default:
|
||||
throw new ArgumentException(nameof (format));
|
||||
}
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
public async Task ListServers(int page = 1)
|
||||
|
@@ -728,6 +728,9 @@ showemojis:
|
||||
emojiadd:
|
||||
- emojiadd
|
||||
- ea
|
||||
stickeradd:
|
||||
- stickeradd
|
||||
- sa
|
||||
emojiremove:
|
||||
- emojiremove
|
||||
- emojirm
|
||||
|
@@ -1245,6 +1245,10 @@ emojiremove:
|
||||
desc: "Removes the specified emoji or emojis from this server."
|
||||
args:
|
||||
- ":eagleWarrior: :plumedArcher:"
|
||||
stickeradd:
|
||||
desc: "Adds the sticker from your message to this server. Send the sticker along with this command (in the same message)."
|
||||
args:
|
||||
- "optionalname \"optional description\" tag1 tag2 tagN"
|
||||
deckshuffle:
|
||||
desc: "Reshuffles all cards back into the deck."
|
||||
args:
|
||||
|
@@ -1052,6 +1052,9 @@
|
||||
"xpshop_already_owned": "You already own this item.",
|
||||
"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>",
|
||||
"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.",
|
||||
"sticker_missing_name": "Please specify a name for the sticker.",
|
||||
"thread_deleted": "Thread Deleted",
|
||||
"thread_created": "Thread Created"
|
||||
}
|
||||
|
Reference in New Issue
Block a user