Add avatar preview with no arguments
This commit is contained in:
@@ -275,10 +275,37 @@ namespace PluralKit.Bot.Commands
|
||||
|
||||
public async Task MemberAvatar(Context ctx, PKMember target)
|
||||
{
|
||||
if (ctx.RemainderOrNull() == null && ctx.Message.Attachments.Count == 0)
|
||||
{
|
||||
if ((target.AvatarUrl?.Trim() ?? "").Length > 0)
|
||||
{
|
||||
var eb = new EmbedBuilder()
|
||||
.WithTitle($"{target.Name.SanitizeMentions()}'s avatar")
|
||||
.WithImageUrl(target.AvatarUrl);
|
||||
if (target.System == ctx.System?.Id)
|
||||
eb.WithDescription($"To clear, use `pk;member {target.Hid} avatar clear`.");
|
||||
await ctx.Reply(embed: eb.Build());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (target.System == ctx.System?.Id)
|
||||
throw new PKSyntaxError($"This member does not have an avatar set. Set one by attaching an image to this command, or by passing an image URL.");
|
||||
throw new PKError($"This member does not have an avatar set.");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.System == null) throw Errors.NoSystemError;
|
||||
if (target.System != ctx.System.Id) throw Errors.NotOwnMemberError;
|
||||
|
||||
if (await ctx.MatchUser() is IUser user)
|
||||
|
||||
if (ctx.Match("clear", "remove"))
|
||||
{
|
||||
target.AvatarUrl = null;
|
||||
await _data.SaveMember(target);
|
||||
await ctx.Reply($"{Emojis.Success} Member avatar cleared.");
|
||||
}
|
||||
else if (await ctx.MatchUser() is IUser user)
|
||||
{
|
||||
if (user.AvatarId == null) throw Errors.UserHasNoAvatar;
|
||||
target.AvatarUrl = user.GetAvatarUrl(ImageFormat.Png, size: 256);
|
||||
@@ -307,13 +334,8 @@ namespace PluralKit.Bot.Commands
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} Member avatar changed to attached image. Please note that if you delete the message containing the attachment, the avatar will stop working.");
|
||||
}
|
||||
else
|
||||
{
|
||||
target.AvatarUrl = null;
|
||||
await _data.SaveMember(target);
|
||||
await ctx.Reply($"{Emojis.Success} Member avatar cleared.");
|
||||
}
|
||||
|
||||
// No-arguments no-attachment case covered by conditional at the very top
|
||||
|
||||
await _proxyCache.InvalidateResultsForSystem(ctx.System);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user