Add member avatar edit command

This also refactors a large portion of the DI toolchain, since
I discovered that you shouldn't be reusing IDbConnection objects.

Instead, most services and stores are now declared transient, and
the webhook cache has been moved to a database-independent storage
singleton by itself.
This commit is contained in:
Ske
2019-05-17 01:23:09 +02:00
parent 1824bfd6bb
commit 08afa2543b
9 changed files with 169 additions and 40 deletions

View File

@@ -1,3 +1,6 @@
using System.Net;
using Humanizer;
namespace PluralKit.Bot {
public static class Errors {
// TODO: is returning constructed errors and throwing them at call site a good idea, or should these be methods that insta-throw instead?
@@ -20,5 +23,10 @@ namespace PluralKit.Bot {
public static PKError ProxyMultipleText => new PKSyntaxError("Example proxy message must contain the string 'text' exactly once.");
public static PKError MemberDeleteCancelled => new PKError($"Member deletion cancelled. Stay safe! {Emojis.ThumbsUp}");
public static PKError AvatarServerError(HttpStatusCode statusCode) => new PKError($"Server responded with status code {(int) statusCode}, are you sure your link is working?");
public static PKError AvatarFileSizeLimit(long size) => new PKError($"File size too large ({size.Bytes().ToString("#.#")} > {Limits.AvatarFileSizeLimit.Bytes().ToString("#.#")}), try shrinking or compressing the image.");
public static PKError AvatarNotAnImage(string mimeType) => new PKError($"The given link does not point to an image{(mimeType != null ? $" ({mimeType})" : "")}. Make sure you're using a direct link (ending in .jpg, .png, .gif).");
public static PKError AvatarDimensionsTooLarge(int width, int height) => new PKError($"Image too large ({width}x{height} > {Limits.AvatarDimensionLimit}x{Limits.AvatarDimensionLimit}), try resizing the image.");
public static PKError InvalidUrl(string url) => new PKError($"The given URL is invalid.");
}
}