feat(bot): add -plaintext flag alongside -raw

This commit is contained in:
Petal Ladenson 2024-10-03 02:23:33 -06:00 committed by GitHub
parent 3d9be096cb
commit 23fe904464
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 322 additions and 162 deletions

View file

@ -70,30 +70,41 @@ public class MemberEdit
noDescriptionSetMessage +=
$" To set one, type `pk;member {target.Reference(ctx)} description <description>`.";
if (ctx.MatchRaw())
{
var format = ctx.MatchFormat();
// if there's nothing next or what's next is "raw"/"plaintext" we're doing a query, so check for null
if (!ctx.HasNext(false) || format != ReplyFormat.Standard)
if (target.Description == null)
{
await ctx.Reply(noDescriptionSetMessage);
else
await ctx.Reply($"```\n{target.Description}\n```");
return;
}
if (format == ReplyFormat.Raw)
{
await ctx.Reply($"```\n{target.Description}\n```");
return;
}
if (format == ReplyFormat.Plaintext)
{
var eb = new EmbedBuilder()
.Description($"Showing description for member {target.Reference(ctx)}");
await ctx.Reply(target.Description, embed: eb.Build());
return;
}
if (!ctx.HasNext(false))
{
if (target.Description == null)
await ctx.Reply(noDescriptionSetMessage);
else
await ctx.Reply(embed: new EmbedBuilder()
.Title("Member description")
.Description(target.Description)
.Field(new Embed.Field("\u200B",
$"To print the description with formatting, type `pk;member {target.Reference(ctx)} description -raw`."
+ (ctx.System?.Id == target.System
? $" To clear it, type `pk;member {target.Reference(ctx)} description -clear`."
: "")
+ $" Using {target.Description.Length}/{Limits.MaxDescriptionLength} characters."))
.Build());
await ctx.Reply(embed: new EmbedBuilder()
.Title("Member description")
.Description(target.Description)
.Field(new Embed.Field("\u200B",
$"To print the description with formatting, type `pk;member {target.Reference(ctx)} description -raw`."
+ (ctx.System?.Id == target.System
? $" To clear it, type `pk;member {target.Reference(ctx)} description -clear`."
: "")
+ $" Using {target.Description.Length}/{Limits.MaxDescriptionLength} characters."))
.Build());
return;
}
@ -126,26 +137,37 @@ public class MemberEdit
ctx.CheckSystemPrivacy(target.System, target.PronounPrivacy);
if (ctx.MatchRaw())
{
var format = ctx.MatchFormat();
// if there's nothing next or what's next is "raw"/"plaintext" we're doing a query, so check for null
if (!ctx.HasNext(false) || format != ReplyFormat.Standard)
if (target.Pronouns == null)
{
await ctx.Reply(noPronounsSetMessage);
else
await ctx.Reply($"```\n{target.Pronouns}\n```");
return;
}
if (format == ReplyFormat.Raw)
{
await ctx.Reply($"```\n{target.Pronouns}\n```");
return;
}
if (format == ReplyFormat.Plaintext)
{
var eb = new EmbedBuilder()
.Description($"Showing pronouns for member {target.Reference(ctx)}");
await ctx.Reply(target.Pronouns, embed: eb.Build());
return;
}
if (!ctx.HasNext(false))
{
if (target.Pronouns == null)
await ctx.Reply(noPronounsSetMessage);
else
await ctx.Reply(
$"**{target.NameFor(ctx)}**'s pronouns are **{target.Pronouns}**.\nTo print the pronouns with formatting, type `pk;member {target.Reference(ctx)} pronouns -raw`."
+ (ctx.System?.Id == target.System
? $" To clear them, type `pk;member {target.Reference(ctx)} pronouns -clear`."
: "")
+ $" Using {target.Pronouns.Length}/{Limits.MaxPronounsLength} characters.");
await ctx.Reply(
$"**{target.NameFor(ctx)}**'s pronouns are **{target.Pronouns}**.\nTo print the pronouns with formatting, type `pk;member {target.Reference(ctx)} pronouns -raw`."
+ (ctx.System?.Id == target.System
? $" To clear them, type `pk;member {target.Reference(ctx)} pronouns -clear`."
: "")
+ $" Using {target.Pronouns.Length}/{Limits.MaxPronounsLength} characters.");
return;
}
@ -232,7 +254,7 @@ public class MemberEdit
public async Task Color(Context ctx, PKMember target)
{
var isOwnSystem = ctx.System?.Id == target.System;
var matchedRaw = ctx.MatchRaw();
var matchedFormat = ctx.MatchFormat();
var matchedClear = ctx.MatchClear();
if (!isOwnSystem || !(ctx.HasNext() || matchedClear))
@ -240,8 +262,10 @@ public class MemberEdit
if (target.Color == null)
await ctx.Reply(
"This member does not have a color set." + (isOwnSystem ? $" To set one, type `pk;member {target.Reference(ctx)} color <color>`." : ""));
else if (matchedRaw)
else if (matchedFormat == ReplyFormat.Raw)
await ctx.Reply("```\n#" + target.Color + "\n```");
else if (matchedFormat == ReplyFormat.Plaintext)
await ctx.Reply(target.Color);
else
await ctx.Reply(embed: new EmbedBuilder()
.Title("Member color")
@ -388,12 +412,26 @@ public class MemberEdit
// No perms check, display name isn't covered by member privacy
if (ctx.MatchRaw())
{
var format = ctx.MatchFormat();
// if what's next is "raw"/"plaintext" we need to check for null
if (format != ReplyFormat.Standard)
if (target.DisplayName == null)
{
await ctx.Reply(noDisplayNameSetMessage);
else
await ctx.Reply($"```\n{target.DisplayName}\n```");
return;
}
if (format == ReplyFormat.Raw)
{
await ctx.Reply($"```\n{target.DisplayName}\n```");
return;
}
if (format == ReplyFormat.Plaintext)
{
var eb = new EmbedBuilder()
.Description($"Showing displayname for member {target.Reference(ctx)}");
await ctx.Reply(target.DisplayName, embed: eb.Build());
return;
}
@ -450,12 +488,26 @@ public class MemberEdit
// No perms check, display name isn't covered by member privacy
var memberGuildConfig = await ctx.Repository.GetMemberGuild(ctx.Guild.Id, target.Id);
if (ctx.MatchRaw())
{
var format = ctx.MatchFormat();
// if what's next is "raw"/"plaintext" we need to check for null
if (format != ReplyFormat.Standard)
if (memberGuildConfig.DisplayName == null)
{
await ctx.Reply(noServerNameSetMessage);
else
await ctx.Reply($"```\n{memberGuildConfig.DisplayName}\n```");
return;
}
if (format == ReplyFormat.Raw)
{
await ctx.Reply($"```\n{memberGuildConfig.DisplayName}\n```");
return;
}
if (format == ReplyFormat.Plaintext)
{
var eb = new EmbedBuilder()
.Description($"Showing servername for member {target.Reference(ctx)}");
await ctx.Reply(memberGuildConfig.DisplayName, embed: eb.Build());
return;
}