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

@@ -103,5 +103,29 @@ namespace PluralKit.Bot {
}
public static async Task<bool> HasPermission(this ICommandContext ctx, ChannelPermission permission) => (await Permissions(ctx)).Has(permission);
public static async Task BusyIndicator(this ICommandContext ctx, Func<Task> f, string emoji = "\u23f3" /* hourglass */)
{
await ctx.BusyIndicator<object>(async () =>
{
await f();
return null;
}, emoji);
}
public static async Task<T> BusyIndicator<T>(this ICommandContext ctx, Func<Task<T>> f, string emoji = "\u23f3" /* hourglass */)
{
var task = f();
try
{
await Task.WhenAll(ctx.Message.AddReactionAsync(new Emoji(emoji)), task);
return await task;
}
finally
{
ctx.Message.RemoveReactionAsync(new Emoji(emoji), ctx.Client.CurrentUser);
}
}
}
}