mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
Add group privacy command/structures
This commit is contained in:
parent
47d5ad0004
commit
5e28e0aba1
6 changed files with 163 additions and 6 deletions
|
|
@ -27,5 +27,11 @@ namespace PluralKit.Core
|
|||
|
||||
public static int MessageCountFor(this PKMember member, LookupContext ctx) =>
|
||||
member.MetadataPrivacy.Get(ctx, member.MessageCount);
|
||||
|
||||
public static string DescriptionFor(this PKGroup group, LookupContext ctx) =>
|
||||
group.DescriptionPrivacy.Get(ctx, group.Description);
|
||||
|
||||
public static string IconFor(this PKGroup group, LookupContext ctx) =>
|
||||
group.IconPrivacy.Get(ctx, group.Icon);
|
||||
}
|
||||
}
|
||||
66
PluralKit.Core/Models/Privacy/GroupPrivacySubject.cs
Normal file
66
PluralKit.Core/Models/Privacy/GroupPrivacySubject.cs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public enum GroupPrivacySubject
|
||||
{
|
||||
Description,
|
||||
Icon,
|
||||
Visibility
|
||||
}
|
||||
|
||||
public static class GroupPrivacyUtils
|
||||
{
|
||||
public static GroupPatch WithPrivacy(this GroupPatch group, GroupPrivacySubject subject, PrivacyLevel level)
|
||||
{
|
||||
// what do you mean switch expressions can't be statements >.>
|
||||
_ = subject switch
|
||||
{
|
||||
GroupPrivacySubject.Description => group.DescriptionPrivacy = level,
|
||||
GroupPrivacySubject.Icon => group.IconPrivacy = level,
|
||||
GroupPrivacySubject.Visibility => group.Visibility = level,
|
||||
_ => throw new ArgumentOutOfRangeException($"Unknown privacy subject {subject}")
|
||||
};
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
public static GroupPatch WithAllPrivacy(this GroupPatch member, PrivacyLevel level)
|
||||
{
|
||||
foreach (var subject in Enum.GetValues(typeof(GroupPrivacySubject)))
|
||||
member.WithPrivacy((GroupPrivacySubject) subject, level);
|
||||
return member;
|
||||
}
|
||||
|
||||
public static bool TryParseGroupPrivacy(string input, out GroupPrivacySubject subject)
|
||||
{
|
||||
switch (input.ToLowerInvariant())
|
||||
{
|
||||
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":
|
||||
case "list":
|
||||
subject = GroupPrivacySubject.Visibility;
|
||||
break;
|
||||
default:
|
||||
subject = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue