public async Task AddEmote(CommandContext ctx, [Description("Name like `Kappa`")] string name, [Description("Url of the thing")] SdImage url) { var lang = await Language.GetLanguageFromCtxAsync(ctx); var bytes = await url.GetBytesAsync(HttpClient); var st = new MemoryStream(bytes); try { if (bytes.Length > 256000) { await ctx.RespondAsync(string.Format(lang.EmoteWasLargerThan256K, FileSizeUtils.FormatSize(st.Length))); st = (await ImageModule.ResizeAsync(bytes, new Size(128, 128))).Item1; } var emote = await ctx.Guild.CreateEmojiAsync(name, st, reason : "Added via silverbot by " + ctx.User.Username); await ctx.RespondAsync(emote.ToString()); } finally { await st.DisposeAsync(); } }
public SdImage Image() { if (ImageF is null) { ImageF = new SdImage(Url); } return(ImageF); }
public async Task AddEmote(CommandContext ctx, [Description("Name like `Kappa`")] string name) { var lang = await Language.GetLanguageFromCtxAsync(ctx); try { var image = SdImage.FromContext(ctx); await AddEmote(ctx, name, image); } catch (AttachmentCountIncorrectException acie) { if (acie.AttachmentCount is AttachmentCountIncorrect.TooLittleAttachments) { await ctx.RespondAsync(lang.NoImageGeneric); } else if (acie.AttachmentCount is AttachmentCountIncorrect.TooManyAttachments) { await ctx.RespondAsync(lang.MoreThanOneImageGeneric); } } }