Added .stickeradd command

Updated docs for medusa
This commit is contained in:
Kwoth
2023-01-11 23:39:14 +00:00
parent 67c156e40f
commit 80efb954f1
5 changed files with 112 additions and 8 deletions

View File

@@ -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>

View File

@@ -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)

View File

@@ -728,6 +728,9 @@ showemojis:
emojiadd:
- emojiadd
- ea
stickeradd:
- stickeradd
- sa
emojiremove:
- emojiremove
- emojirm

View File

@@ -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:

View File

@@ -977,14 +977,14 @@
"created_by": "Created by {0}",
"module_footer": "{0}cmds {1}",
"module_page_empty": "No module on this page.",
"module_description_help": "Get command help, descriptions and usage examples",
"module_description_gambling": "Bet on dice rolls, blackjack, slots, coinflips and others",
"module_description_games": "Play trivia, nunchi, hangman, connect4 and other games",
"module_description_nsfw": "NSFW commands.",
"module_description_music": "Play music from youtube, local files soundcloud and radio streams",
"module_description_utility": "Manage custom quotes, repeating messages and check facts about the server",
"module_description_help": "Get command help, descriptions and usage examples",
"module_description_gambling": "Bet on dice rolls, blackjack, slots, coinflips and others",
"module_description_games": "Play trivia, nunchi, hangman, connect4 and other games",
"module_description_nsfw": "NSFW commands.",
"module_description_music": "Play music from youtube, local files soundcloud and radio streams",
"module_description_utility": "Manage custom quotes, repeating messages and check facts about the server",
"module_description_administration": "Moderation, punish users, setup self assignable roles and greet messages",
"module_description_expressions": "Setup custom bot responses to certain words or phrases",
"module_description_expressions": "Setup custom bot responses to certain words or phrases",
"module_description_permissions": "Setup perms for commands, filter words and set up command cooldowns",
"module_description_searches": "Search for jokes, images of animals, anime and manga",
"module_description_xp": "Gain xp based on chat activity, check users' xp cards",
@@ -1005,7 +1005,7 @@
"linkonly_disable": "This channel is no longer link-only.",
"deleted_x_servers": "Deleted {0} servers.",
"curtr_gift": "Gift from {0} [{1}]",
"curtr_award": "Awarded by bot owner {0} [{1}]",
"curtr_award": "Awarded by bot owner {0} [{1}]",
"curtr_take": "Taken by bot owner {0} [{1}]",
"list_of_medusae": "List of Medusae",
"list_of_unloaded": "List of Available Medusae",
@@ -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"
}