2020-07-07 22:46:58 +00:00
|
|
|
|
using PluralKit.Core;
|
|
|
|
|
|
|
|
|
|
namespace PluralKit.Bot
|
|
|
|
|
{
|
|
|
|
|
public static class ContextPrivacyExt
|
|
|
|
|
{
|
|
|
|
|
public static PrivacyLevel PopPrivacyLevel(this Context ctx)
|
|
|
|
|
{
|
|
|
|
|
if (ctx.Match("public", "show", "shown", "visible"))
|
|
|
|
|
return PrivacyLevel.Public;
|
|
|
|
|
|
|
|
|
|
if (ctx.Match("private", "hide", "hidden"))
|
|
|
|
|
return PrivacyLevel.Private;
|
|
|
|
|
|
|
|
|
|
if (!ctx.HasNext())
|
|
|
|
|
throw new PKSyntaxError("You must pass a privacy level (`public` or `private`)");
|
|
|
|
|
|
2020-08-25 20:44:52 +00:00
|
|
|
|
throw new PKSyntaxError($"Invalid privacy level {ctx.PopArgument().AsCode()} (must be `public` or `private`).");
|
2020-07-07 22:46:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static SystemPrivacySubject PopSystemPrivacySubject(this Context ctx)
|
|
|
|
|
{
|
|
|
|
|
if (!SystemPrivacyUtils.TryParseSystemPrivacy(ctx.PeekArgument(), out var subject))
|
2020-08-26 20:01:52 +00:00
|
|
|
|
throw new PKSyntaxError($"Invalid privacy subject {ctx.PopArgument().AsCode()} (must be `description`, `members`, `front`, `fronthistory`, `groups`, or `all`).");
|
2020-07-07 22:46:58 +00:00
|
|
|
|
|
|
|
|
|
ctx.PopArgument();
|
|
|
|
|
return subject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static MemberPrivacySubject PopMemberPrivacySubject(this Context ctx)
|
|
|
|
|
{
|
|
|
|
|
if (!MemberPrivacyUtils.TryParseMemberPrivacy(ctx.PeekArgument(), out var subject))
|
2020-08-25 20:44:52 +00:00
|
|
|
|
throw new PKSyntaxError($"Invalid privacy subject {ctx.PopArgument().AsCode()} (must be `name`, `description`, `avatar`, `birthday`, `pronouns`, `metadata`, `visibility`, or `all).");
|
2020-07-07 22:46:58 +00:00
|
|
|
|
|
|
|
|
|
ctx.PopArgument();
|
|
|
|
|
return subject;
|
|
|
|
|
}
|
2020-07-18 11:53:02 +00:00
|
|
|
|
|
|
|
|
|
public static GroupPrivacySubject PopGroupPrivacySubject(this Context ctx)
|
|
|
|
|
{
|
|
|
|
|
if (!GroupPrivacyUtils.TryParseGroupPrivacy(ctx.PeekArgument(), out var subject))
|
2020-08-25 20:44:52 +00:00
|
|
|
|
throw new PKSyntaxError($"Invalid privacy subject {ctx.PopArgument().AsCode()} (must be `description`, `icon`, `visibility`, or `all).");
|
2020-07-18 11:53:02 +00:00
|
|
|
|
|
|
|
|
|
ctx.PopArgument();
|
|
|
|
|
return subject;
|
|
|
|
|
}
|
2020-07-07 22:46:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|