Add banner (large) image
This commit is contained in:
@@ -218,7 +218,60 @@ namespace PluralKit.Bot
|
||||
else
|
||||
await ShowIcon();
|
||||
}
|
||||
|
||||
|
||||
public async Task BannerImage(Context ctx)
|
||||
{
|
||||
ctx.CheckSystem();
|
||||
|
||||
async Task ClearImage()
|
||||
{
|
||||
await _db.Execute(c => _repo.UpdateSystem(c, ctx.System.Id, new SystemPatch {BannerImage = null}));
|
||||
await ctx.Reply($"{Emojis.Success} System banner image cleared.");
|
||||
}
|
||||
|
||||
async Task SetImage(ParsedImage img)
|
||||
{
|
||||
await AvatarUtils.VerifyAvatarOrThrow(img.Url, isFullSizeImage: true);
|
||||
|
||||
await _db.Execute(c => _repo.UpdateSystem(c, ctx.System.Id, new SystemPatch {BannerImage = img.Url}));
|
||||
|
||||
var msg = img.Source switch
|
||||
{
|
||||
AvatarSource.Url => $"{Emojis.Success} System banner image changed to the image at the given URL.",
|
||||
AvatarSource.Attachment => $"{Emojis.Success} System banner image changed to attached image.\n{Emojis.Warn} If you delete the message containing the attachment, the banner image will stop working.",
|
||||
AvatarSource.User => throw new PKError("Cannot set a banner image to an user's avatar."),
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
// The attachment's already right there, no need to preview it.
|
||||
var hasEmbed = img.Source != AvatarSource.Attachment;
|
||||
await (hasEmbed
|
||||
? ctx.Reply(msg, embed: new EmbedBuilder().Image(new(img.Url)).Build())
|
||||
: ctx.Reply(msg));
|
||||
}
|
||||
|
||||
async Task ShowImage()
|
||||
{
|
||||
if ((ctx.System.BannerImage?.Trim() ?? "").Length > 0)
|
||||
{
|
||||
var eb = new EmbedBuilder()
|
||||
.Title("System banner image")
|
||||
.Image(new(ctx.System.BannerImage))
|
||||
.Description("To clear, use `pk;system banner clear`.");
|
||||
await ctx.Reply(embed: eb.Build());
|
||||
}
|
||||
else
|
||||
throw new PKSyntaxError("This system does not have a banner image set. Set one by attaching an image to this command, or by passing an image URL or @mention.");
|
||||
}
|
||||
|
||||
if (await ctx.MatchClear("your system's banner image"))
|
||||
await ClearImage();
|
||||
else if (await ctx.MatchImage() is {} img)
|
||||
await SetImage(img);
|
||||
else
|
||||
await ShowImage();
|
||||
}
|
||||
|
||||
public async Task Delete(Context ctx) {
|
||||
ctx.CheckSystem();
|
||||
|
||||
|
Reference in New Issue
Block a user