PluralKit/PluralKit.Core/Models/Privacy/MemberPrivacySubject.cs

93 lines
3.1 KiB
C#
Raw Normal View History

2021-08-27 15:03:47 +00:00
using System;
2020-06-17 21:06:49 +00:00
namespace PluralKit.Core
{
public enum MemberPrivacySubject
{
2020-06-17 21:06:49 +00:00
Visibility,
Name,
Description,
2020-06-20 14:00:50 +00:00
Avatar,
2020-06-17 21:06:49 +00:00
Birthday,
Pronouns,
Metadata
}
public static class MemberPrivacyUtils
{
public static MemberPatch WithPrivacy(this MemberPatch member, MemberPrivacySubject subject, PrivacyLevel level)
2020-06-17 21:06:49 +00:00
{
// what do you mean switch expressions can't be statements >.>
_ = subject switch
{
MemberPrivacySubject.Name => member.NamePrivacy = level,
MemberPrivacySubject.Description => member.DescriptionPrivacy = level,
MemberPrivacySubject.Avatar => member.AvatarPrivacy = level,
MemberPrivacySubject.Pronouns => member.PronounPrivacy = level,
MemberPrivacySubject.Birthday => member.BirthdayPrivacy = level,
MemberPrivacySubject.Metadata => member.MetadataPrivacy = level,
MemberPrivacySubject.Visibility => member.Visibility = level,
2020-06-17 21:06:49 +00:00
_ => throw new ArgumentOutOfRangeException($"Unknown privacy subject {subject}")
};
2021-08-27 15:03:47 +00:00
return member;
2020-06-17 21:06:49 +00:00
}
public static MemberPatch WithAllPrivacy(this MemberPatch member, PrivacyLevel level)
2020-06-17 21:06:49 +00:00
{
foreach (var subject in Enum.GetValues(typeof(MemberPrivacySubject)))
2021-08-27 15:03:47 +00:00
member.WithPrivacy((MemberPrivacySubject)subject, level);
return member;
2020-06-17 21:06:49 +00:00
}
2020-06-17 21:06:49 +00:00
public static bool TryParseMemberPrivacy(string input, out MemberPrivacySubject subject)
{
switch (input.ToLowerInvariant())
{
case "name":
subject = MemberPrivacySubject.Name;
break;
case "description":
case "desc":
case "text":
case "info":
subject = MemberPrivacySubject.Description;
break;
2020-06-20 14:00:50 +00:00
case "avatar":
case "pfp":
case "pic":
case "icon":
subject = MemberPrivacySubject.Avatar;
break;
2020-06-17 21:06:49 +00:00
case "birthday":
case "birth":
case "bday":
case "birthdate":
case "bdate":
2020-06-17 21:06:49 +00:00
subject = MemberPrivacySubject.Birthday;
break;
case "pronouns":
case "pronoun":
subject = MemberPrivacySubject.Pronouns;
break;
case "meta":
case "metadata":
case "created":
subject = MemberPrivacySubject.Metadata;
break;
case "visibility":
case "hidden":
2020-06-17 21:06:49 +00:00
case "shown":
case "visible":
case "list":
subject = MemberPrivacySubject.Visibility;
break;
default:
subject = MemberPrivacySubject.Name;
return false;
}
2020-06-17 21:06:49 +00:00
return true;
}
2020-06-17 21:06:49 +00:00
}
}