PluralKit/PluralKit.Core/Models/Privacy/GroupPrivacySubject.cs

81 lines
2.4 KiB
C#
Raw Normal View History

namespace PluralKit.Core;
2020-07-18 11:53:02 +00:00
public enum GroupPrivacySubject
2020-07-18 11:53:02 +00:00
{
Name,
Description,
Icon,
List,
Metadata,
Visibility
}
2021-08-27 15:03:47 +00:00
public static class GroupPrivacyUtils
{
public static GroupPatch WithPrivacy(this GroupPatch group, GroupPrivacySubject subject, PrivacyLevel level)
2020-07-18 11:53:02 +00:00
{
// what do you mean switch expressions can't be statements >.>
_ = subject switch
2020-07-18 11:53:02 +00:00
{
GroupPrivacySubject.Name => group.NamePrivacy = level,
GroupPrivacySubject.Description => group.DescriptionPrivacy = level,
GroupPrivacySubject.Icon => group.IconPrivacy = level,
GroupPrivacySubject.List => group.ListPrivacy = level,
GroupPrivacySubject.Metadata => group.MetadataPrivacy = level,
GroupPrivacySubject.Visibility => group.Visibility = level,
_ => throw new ArgumentOutOfRangeException($"Unknown privacy subject {subject}")
};
2021-08-27 15:03:47 +00:00
return group;
}
2020-07-18 11:53:02 +00:00
public static GroupPatch WithAllPrivacy(this GroupPatch member, PrivacyLevel level)
{
foreach (var subject in Enum.GetValues(typeof(GroupPrivacySubject)))
member.WithPrivacy((GroupPrivacySubject)subject, level);
return member;
}
2020-07-18 11:53:02 +00:00
public static bool TryParseGroupPrivacy(string input, out GroupPrivacySubject subject)
{
switch (input.ToLowerInvariant())
2020-07-18 11:53:02 +00:00
{
case "name":
subject = GroupPrivacySubject.Name;
break;
case "description":
case "desc":
case "text":
case "info":
subject = GroupPrivacySubject.Description;
break;
case "avatar":
case "pfp":
case "pic":
case "icon":
subject = GroupPrivacySubject.Icon;
break;
case "visibility":
case "hidden":
case "shown":
case "visible":
subject = GroupPrivacySubject.Visibility;
break;
case "meta":
case "metadata":
case "created":
subject = GroupPrivacySubject.Metadata;
break;
case "list":
case "listing":
case "members":
subject = GroupPrivacySubject.List;
break;
default:
subject = default;
return false;
2020-07-18 11:53:02 +00:00
}
return true;
2020-07-18 11:53:02 +00:00
}
}