mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-12 08:40:11 +00:00
feat: add raw and plaintext formats to member avatar, proxy avatar, and guild avatar
This commit is contained in:
parent
2d17582e05
commit
2c4dea29be
3 changed files with 35 additions and 6 deletions
|
|
@ -98,6 +98,15 @@ public static class ContextArgumentsExt
|
||||||
return ReplyFormat.Standard;
|
return ReplyFormat.Standard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ReplyFormat PeekMatchFormat(this Context ctx)
|
||||||
|
{
|
||||||
|
int ptr1 = ctx.Parameters._ptr;
|
||||||
|
int ptr2 = ctx.Parameters._ptr;
|
||||||
|
if (ctx.PeekMatch(ref ptr1, new[] { "r", "raw" }) || ctx.MatchFlag("r", "raw")) return ReplyFormat.Raw;
|
||||||
|
if (ctx.PeekMatch(ref ptr2, new[] { "pt", "plaintext" }) || ctx.MatchFlag("pt", "plaintext")) return ReplyFormat.Plaintext;
|
||||||
|
return ReplyFormat.Standard;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool MatchToggle(this Context ctx, bool? defaultValue = null)
|
public static bool MatchToggle(this Context ctx, bool? defaultValue = null)
|
||||||
{
|
{
|
||||||
var value = ctx.MatchToggleOrNull(defaultValue);
|
var value = ctx.MatchToggleOrNull(defaultValue);
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,10 @@ public static class ContextAvatarExt
|
||||||
return new ParsedImage { Url = url, Source = AvatarSource.User, SourceUser = user };
|
return new ParsedImage { Url = url, Source = AvatarSource.User, SourceUser = user };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we have raw or plaintext, don't try to parse as a URL
|
||||||
|
if (ctx.PeekMatchFormat() != ReplyFormat.Standard)
|
||||||
|
return null;
|
||||||
|
|
||||||
// If we have a positional argument, try to parse it as a URL
|
// If we have a positional argument, try to parse it as a URL
|
||||||
var arg = ctx.RemainderOrNull();
|
var arg = ctx.RemainderOrNull();
|
||||||
if (arg != null)
|
if (arg != null)
|
||||||
|
|
|
||||||
|
|
@ -86,12 +86,28 @@ public class MemberAvatar
|
||||||
if (location == MemberAvatarLocation.Server)
|
if (location == MemberAvatarLocation.Server)
|
||||||
field += $" (for {ctx.Guild.Name})";
|
field += $" (for {ctx.Guild.Name})";
|
||||||
|
|
||||||
var eb = new EmbedBuilder()
|
var format = ctx.MatchFormat();
|
||||||
.Title($"{target.NameFor(ctx)}'s {field}")
|
if (format == ReplyFormat.Raw)
|
||||||
.Image(new Embed.EmbedImage(currentValue?.TryGetCleanCdnUrl()));
|
{
|
||||||
if (target.System == ctx.System?.Id)
|
await ctx.Reply($"`{currentValue?.TryGetCleanCdnUrl()}`");
|
||||||
eb.Description($"To clear, use `pk;member {target.Reference(ctx)} {location.Command()} clear`.");
|
}
|
||||||
await ctx.Reply(embed: eb.Build());
|
else if (format == ReplyFormat.Plaintext)
|
||||||
|
{
|
||||||
|
var eb = new EmbedBuilder()
|
||||||
|
.Description($"Showing {field} link for member {target.NameFor(ctx)} (`{target.DisplayHid(ctx.Config)}`)");
|
||||||
|
await ctx.Reply($"<{currentValue?.TryGetCleanCdnUrl()}>", embed: eb.Build());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (format == ReplyFormat.Standard)
|
||||||
|
{
|
||||||
|
var eb = new EmbedBuilder()
|
||||||
|
.Title($"{target.NameFor(ctx)}'s {field}")
|
||||||
|
.Image(new Embed.EmbedImage(currentValue?.TryGetCleanCdnUrl()));
|
||||||
|
if (target.System == ctx.System?.Id)
|
||||||
|
eb.Description($"To clear, use `pk;member {target.Reference(ctx)} {location.Command()} clear`.");
|
||||||
|
await ctx.Reply(embed: eb.Build());
|
||||||
|
}
|
||||||
|
else throw new PKError("Format Not Recognized");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ServerAvatar(Context ctx, PKMember target)
|
public async Task ServerAvatar(Context ctx, PKMember target)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue