feat: system pronouns (#429)

This commit is contained in:
Jake Fulmine
2022-03-23 19:20:16 +01:00
committed by GitHub
parent 062835e0c5
commit 7efe6f1f97
11 changed files with 99 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ public partial class CommandTree
public static Command SystemDesc = new Command("system description", "system [system] description [description]", "Changes your system's description");
public static Command SystemColor = new Command("system color", "system [system] color [color]", "Changes your system's color");
public static Command SystemTag = new Command("system tag", "system [system] tag [tag]", "Changes your system's tag");
public static Command SystemPronouns = new Command("system pronouns", "system [system] pronouns [pronouns]", "Changes your system's pronouns");
public static Command SystemServerTag = new Command("system servertag", "system [system] servertag [tag|enable|disable]", "Changes your system's tag in the current server");
public static Command SystemAvatar = new Command("system icon", "system [system] icon [url|@mention]", "Changes your system's icon");
public static Command SystemBannerImage = new Command("system banner", "system [system] banner [url]", "Set the system's banner image");

View File

@@ -213,6 +213,8 @@ public partial class CommandTree
await ctx.CheckSystem(target).Execute<SystemEdit>(SystemServerTag, m => m.ServerTag(ctx, target));
else if (ctx.Match("description", "desc", "bio"))
await ctx.CheckSystem(target).Execute<SystemEdit>(SystemDesc, m => m.Description(ctx, target));
else if (ctx.Match("pronouns", "prns"))
await ctx.CheckSystem(target).Execute<SystemEdit>(SystemPronouns, m => m.Pronouns(ctx, target));
else if (ctx.Match("color", "colour"))
await ctx.CheckSystem(target).Execute<SystemEdit>(SystemColor, m => m.Color(ctx, target));
else if (ctx.Match("banner", "splash", "cover"))

View File

@@ -339,6 +339,58 @@ public class SystemEdit
await Set();
}
public async Task Pronouns(Context ctx, PKSystem target)
{
ctx.CheckSystemPrivacy(target.Id, target.PronounPrivacy);
var isOwnSystem = ctx.System.Id == target.Id;
var noPronounsSetMessage = "This system does not have pronouns set.";
if (isOwnSystem)
noPronounsSetMessage += " To set some, type `pk;system pronouns <pronouns>`";
if (ctx.MatchRaw())
{
if (target.Pronouns == null)
await ctx.Reply(noPronounsSetMessage);
else
await ctx.Reply($"```\n{target.Pronouns}\n```");
return;
}
if (!ctx.HasNext(false))
{
if (target.Pronouns == null)
await ctx.Reply(noPronounsSetMessage);
else
await ctx.Reply($"{(isOwnSystem ? "Your" : "This system's")} current pronouns are **{target.Pronouns}**.\nTo print the pronouns with formatting, type `pk;system pronouns -raw`."
+ (isOwnSystem ? " To clear them, type `pk;system pronouns -clear`."
: "" ));
return;
}
ctx.CheckSystem().CheckOwnSystem(target);
if (await ctx.MatchClear("your system's pronouns"))
{
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { Pronouns = null });
await ctx.Reply($"{Emojis.Success} System pronouns cleared.");
}
else
{
var newPronouns = ctx.RemainderOrNull(false).NormalizeLineEndSpacing();
if (newPronouns != null)
if (newPronouns.Length > Limits.MaxPronounsLength)
throw Errors.StringTooLongError("Pronouns", newPronouns.Length, Limits.MaxPronounsLength);
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { Pronouns = newPronouns });
await ctx.Reply(
$"{Emojis.Success} System pronouns changed.");
}
}
public async Task Avatar(Context ctx, PKSystem target)
{
async Task ClearIcon()
@@ -525,6 +577,7 @@ public class SystemEdit
var eb = new EmbedBuilder()
.Title("Current privacy settings for your system")
.Field(new Embed.Field("Description", target.DescriptionPrivacy.Explanation()))
.Field(new Embed.Field("Pronouns", target.PronounPrivacy.Explanation()))
.Field(new Embed.Field("Member list", target.MemberListPrivacy.Explanation()))
.Field(new Embed.Field("Group list", target.GroupListPrivacy.Explanation()))
.Field(new Embed.Field("Current fronter(s)", target.FrontPrivacy.Explanation()))
@@ -548,6 +601,7 @@ public class SystemEdit
var subjectStr = subject switch
{
SystemPrivacySubject.Description => "description",
SystemPrivacySubject.Pronouns => "pronouns",
SystemPrivacySubject.Front => "front",
SystemPrivacySubject.FrontHistory => "front history",
SystemPrivacySubject.MemberList => "member list",

View File

@@ -103,6 +103,9 @@ public class EmbedService
"*(tag is disabled in this server)*"));
}
if (system.PronounPrivacy.CanAccess(ctx) && system.Pronouns != null)
eb.Field(new Embed.Field("Pronouns", system.Pronouns, true));
if (!system.Color.EmptyOrNull()) eb.Field(new Embed.Field("Color", $"#{system.Color}", true));
eb.Field(new Embed.Field("Linked accounts", string.Join("\n", users).Truncate(1000), true));