2021-11-27 02:10:56 +00:00
|
|
|
namespace PluralKit.Core;
|
2020-07-07 22:46:58 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public enum SystemPrivacySubject
|
2020-07-07 22:46:58 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
Description,
|
2022-03-23 18:20:16 +00:00
|
|
|
Pronouns,
|
2021-11-27 02:10:56 +00:00
|
|
|
MemberList,
|
|
|
|
GroupList,
|
|
|
|
Front,
|
|
|
|
FrontHistory
|
|
|
|
}
|
2020-07-07 22:46:58 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public static class SystemPrivacyUtils
|
|
|
|
{
|
|
|
|
public static SystemPatch WithPrivacy(this SystemPatch system, SystemPrivacySubject subject, PrivacyLevel level)
|
2020-07-07 22:46:58 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
// what do you mean switch expressions can't be statements >.>
|
|
|
|
_ = subject switch
|
2020-07-07 22:46:58 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
SystemPrivacySubject.Description => system.DescriptionPrivacy = level,
|
2022-03-23 18:20:16 +00:00
|
|
|
SystemPrivacySubject.Pronouns => system.PronounPrivacy = level,
|
2021-11-27 02:10:56 +00:00
|
|
|
SystemPrivacySubject.Front => system.FrontPrivacy = level,
|
|
|
|
SystemPrivacySubject.FrontHistory => system.FrontHistoryPrivacy = level,
|
|
|
|
SystemPrivacySubject.MemberList => system.MemberListPrivacy = level,
|
|
|
|
SystemPrivacySubject.GroupList => system.GroupListPrivacy = level,
|
|
|
|
_ => throw new ArgumentOutOfRangeException($"Unknown privacy subject {subject}")
|
|
|
|
};
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
return system;
|
|
|
|
}
|
2020-07-07 22:46:58 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public static SystemPatch WithAllPrivacy(this SystemPatch system, PrivacyLevel level)
|
|
|
|
{
|
|
|
|
foreach (var subject in Enum.GetValues(typeof(SystemPrivacySubject)))
|
|
|
|
WithPrivacy(system, (SystemPrivacySubject)subject, level);
|
|
|
|
return system;
|
|
|
|
}
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public static bool TryParseSystemPrivacy(string input, out SystemPrivacySubject subject)
|
|
|
|
{
|
|
|
|
switch (input.ToLowerInvariant())
|
2020-07-07 22:46:58 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
case "description":
|
|
|
|
case "desc":
|
|
|
|
case "text":
|
|
|
|
case "info":
|
|
|
|
subject = SystemPrivacySubject.Description;
|
|
|
|
break;
|
2022-03-23 18:20:16 +00:00
|
|
|
case "pronouns":
|
|
|
|
case "prns":
|
|
|
|
subject = SystemPrivacySubject.Pronouns;
|
|
|
|
break;
|
2021-11-27 02:10:56 +00:00
|
|
|
case "members":
|
|
|
|
case "memberlist":
|
|
|
|
case "list":
|
|
|
|
case "mlist":
|
|
|
|
subject = SystemPrivacySubject.MemberList;
|
|
|
|
break;
|
|
|
|
case "fronter":
|
|
|
|
case "fronters":
|
|
|
|
case "front":
|
|
|
|
subject = SystemPrivacySubject.Front;
|
|
|
|
break;
|
|
|
|
case "switch":
|
|
|
|
case "switches":
|
|
|
|
case "fronthistory":
|
|
|
|
case "fh":
|
|
|
|
subject = SystemPrivacySubject.FrontHistory;
|
|
|
|
break;
|
|
|
|
case "groups":
|
|
|
|
case "gs":
|
|
|
|
subject = SystemPrivacySubject.GroupList;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
subject = default;
|
|
|
|
return false;
|
2021-08-27 15:03:47 +00:00
|
|
|
}
|
2021-11-27 02:10:56 +00:00
|
|
|
|
|
|
|
return true;
|
2020-07-07 22:46:58 +00:00
|
|
|
}
|
|
|
|
}
|