Add avatar preview with no arguments

This commit is contained in:
Ske 2019-12-28 12:23:52 +01:00
parent 30c0fc9b43
commit 468241c92f
4 changed files with 39 additions and 13 deletions

View File

@ -31,7 +31,7 @@ namespace PluralKit.Bot.Commands
public static Command MemberBirthday = new Command("member birthday", "member <member> birthday [birthday]", "Changes a member's birthday");
public static Command MemberProxy = new Command("member proxy", "member <member> proxy [add|remove] [example proxy]", "Changes, adds, or removes a member's proxy tags");
public static Command MemberDelete = new Command("member delete", "member <member> delete", "Deletes a member");
public static Command MemberAvatar = new Command("member avatar", "member <member> avatar [url|@mention]", "Changes a member's avatar");
public static Command MemberAvatar = new Command("member avatar", "member <member> avatar <url|@mention|clear>", "Changes a member's avatar");
public static Command MemberDisplayName = new Command("member displayname", "member <member> displayname [display name]", "Changes a member's display name");
public static Command MemberServerName = new Command("member servername", "member <member> servername [server name]", "Changes a member's display name in the current server");
public static Command MemberKeepProxy = new Command("member keepproxy", "member <member> keepproxy [on|off]", "Sets whether to include a member's proxy tags when proxying");

View File

@ -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);
}

View File

@ -208,9 +208,13 @@ To clear a member color, use the command with no color code argument (eg. `pk;me
If you want your member to have an associated avatar to display on the member information card and on proxied messages, you can set the member avatar. To do so, use the `pk;member avatar` command. You can either supply it with an direct URL to an image, or attach an image directly. For example.
pk;member John avatar http://placebeard.it/512.jpg
pk;member "Craig Johnson" avatar [with attached image]
pk;member "Craig Johnson" avatar (with an attached image)
To clear your avatar, simply use the command with no attachment or link (eg. `pk;member John avatar`).
To preview the current avatar (if one is set), use the command with no arguments:
pk;member John avatar
To clear your avatar, use the subcommand `avatar clear` (eg. `pk;member John avatar clear`).
### Member pronouns
If you want to list a member's preferred pronouns, you can use the pronouns field on a member profile. This is a free text field, so you can put whatever you'd like in there (with a 100 character limit), like so:

View File

@ -33,7 +33,7 @@ Words in \<angle brackets> are *required parameters*. Words in [square brackets]
- `pk;member <name> displayname <new display name>` - Changes the display name of a member.
- `pk;member <name> servername <new server name>` - Changes the display name of a member, only in the current serve.
- `pk;member <name> description [description]` - Changes the description of a member.
- `pk;member <name> avatar [avatar url]` - Changes the avatar of a member.
- `pk;member <name> avatar <avatar url|@mention|clear>` - Changes the avatar of a member.
- `pk;member <name> proxy [tags]` - Changes the proxy tags of a member. use below add/remove commands for members with multiple tag pairs.
- `pk;member <name> proxy add [tags]` - Adds a proxy tag pair to a member.
- `pk;member <name> proxy remove [tags]` - Removes a proxy tag from a member.