2021-08-27 15:03:47 +00:00
|
|
|
using PluralKit.Core;
|
2020-07-07 22:46:58 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace PluralKit.Bot;
|
|
|
|
|
|
|
|
public static class ContextPrivacyExt
|
2020-07-07 22:46:58 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
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`)");
|
|
|
|
|
|
|
|
throw new PKSyntaxError(
|
|
|
|
$"Invalid privacy level {ctx.PopArgument().AsCode()} (must be `public` or `private`).");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static SystemPrivacySubject PopSystemPrivacySubject(this Context ctx)
|
|
|
|
{
|
|
|
|
if (!SystemPrivacyUtils.TryParseSystemPrivacy(ctx.PeekArgument(), out var subject))
|
|
|
|
throw new PKSyntaxError(
|
|
|
|
$"Invalid privacy subject {ctx.PopArgument().AsCode()} (must be `description`, `members`, `front`, `fronthistory`, `groups`, or `all`).");
|
|
|
|
|
|
|
|
ctx.PopArgument();
|
|
|
|
return subject;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static MemberPrivacySubject PopMemberPrivacySubject(this Context ctx)
|
|
|
|
{
|
|
|
|
if (!MemberPrivacyUtils.TryParseMemberPrivacy(ctx.PeekArgument(), out var subject))
|
|
|
|
throw new PKSyntaxError(
|
|
|
|
$"Invalid privacy subject {ctx.PopArgument().AsCode()} (must be `name`, `description`, `avatar`, `birthday`, `pronouns`, `metadata`, `visibility`, or `all`).");
|
|
|
|
|
|
|
|
ctx.PopArgument();
|
|
|
|
return subject;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GroupPrivacySubject PopGroupPrivacySubject(this Context ctx)
|
2020-07-07 22:46:58 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
if (!GroupPrivacyUtils.TryParseGroupPrivacy(ctx.PeekArgument(), out var subject))
|
|
|
|
throw new PKSyntaxError(
|
2022-01-15 03:30:02 +00:00
|
|
|
$"Invalid privacy subject {ctx.PopArgument().AsCode()} (must be `name`, `description`, `icon`, `metadata`, `visibility`, or `all`).");
|
2021-11-27 02:10:56 +00:00
|
|
|
|
|
|
|
ctx.PopArgument();
|
|
|
|
return subject;
|
|
|
|
}
|
2021-08-27 15:03:47 +00:00
|
|
|
}
|