mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
feat(bot): add -plaintext flag alongside -raw
This commit is contained in:
parent
3d9be096cb
commit
23fe904464
5 changed files with 322 additions and 162 deletions
|
|
@ -91,8 +91,12 @@ public static class ContextArgumentsExt
|
||||||
public static bool MatchClear(this Context ctx)
|
public static bool MatchClear(this Context ctx)
|
||||||
=> ctx.Match("clear", "reset", "default") || ctx.MatchFlag("c", "clear");
|
=> ctx.Match("clear", "reset", "default") || ctx.MatchFlag("c", "clear");
|
||||||
|
|
||||||
public static bool MatchRaw(this Context ctx) =>
|
public static ReplyFormat MatchFormat(this Context ctx)
|
||||||
ctx.Match("r", "raw") || ctx.MatchFlag("r", "raw");
|
{
|
||||||
|
if (ctx.Match("r", "raw") || ctx.MatchFlag("r", "raw")) return ReplyFormat.Raw;
|
||||||
|
if (ctx.Match("pt", "plaintext") || ctx.MatchFlag("pt", "plaintext")) return ReplyFormat.Plaintext;
|
||||||
|
return ReplyFormat.Standard;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool MatchToggle(this Context ctx, bool? defaultValue = null)
|
public static bool MatchToggle(this Context ctx, bool? defaultValue = null)
|
||||||
{
|
{
|
||||||
|
|
@ -185,3 +189,10 @@ public static class ContextArgumentsExt
|
||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum ReplyFormat
|
||||||
|
{
|
||||||
|
Standard,
|
||||||
|
Raw,
|
||||||
|
Plaintext
|
||||||
|
}
|
||||||
|
|
@ -132,40 +132,47 @@ public class Groups
|
||||||
|
|
||||||
// No perms check, display name isn't covered by member privacy
|
// No perms check, display name isn't covered by member privacy
|
||||||
|
|
||||||
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.DisplayName == null)
|
if (target.DisplayName == null)
|
||||||
|
{
|
||||||
await ctx.Reply(noDisplayNameSetMessage);
|
await ctx.Reply(noDisplayNameSetMessage);
|
||||||
else
|
return;
|
||||||
await ctx.Reply($"```\n{target.DisplayName}\n```");
|
}
|
||||||
|
|
||||||
|
if (format == ReplyFormat.Raw)
|
||||||
|
{
|
||||||
|
await ctx.Reply($"```\n{target.DisplayName}\n```");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (format == ReplyFormat.Plaintext)
|
||||||
|
{
|
||||||
|
var eb = new EmbedBuilder()
|
||||||
|
.Description($"Showing displayname for group {target.Reference(ctx)}");
|
||||||
|
await ctx.Reply(target.DisplayName, embed: eb.Build());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx.HasNext(false))
|
if (!ctx.HasNext(false))
|
||||||
{
|
{
|
||||||
if (target.DisplayName == null)
|
var eb = new EmbedBuilder()
|
||||||
{
|
.Field(new Embed.Field("Name", target.Name))
|
||||||
await ctx.Reply(noDisplayNameSetMessage);
|
.Field(new Embed.Field("Display Name", target.DisplayName));
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var eb = new EmbedBuilder()
|
|
||||||
.Field(new Embed.Field("Name", target.Name))
|
|
||||||
.Field(new Embed.Field("Display Name", target.DisplayName));
|
|
||||||
|
|
||||||
var reference = target.Reference(ctx);
|
var reference = target.Reference(ctx);
|
||||||
|
|
||||||
if (ctx.System?.Id == target.System)
|
if (ctx.System?.Id == target.System)
|
||||||
eb.Description(
|
eb.Description(
|
||||||
$"To change display name, type `pk;group {reference} displayname <display name>`.\n"
|
$"To change display name, type `pk;group {reference} displayname <display name>`.\n"
|
||||||
+ $"To clear it, type `pk;group {reference} displayname -clear`.\n"
|
+ $"To clear it, type `pk;group {reference} displayname -clear`.\n"
|
||||||
+ $"To print the raw display name, type `pk;group {reference} displayname -raw`.");
|
+ $"To print the raw display name, type `pk;group {reference} displayname -raw`.");
|
||||||
|
|
||||||
if (ctx.System?.Id == target.System)
|
if (ctx.System?.Id == target.System)
|
||||||
eb.Footer(new Embed.EmbedFooter($"Using {target.DisplayName.Length}/{Limits.MaxGroupNameLength} characters."));
|
eb.Footer(new Embed.EmbedFooter($"Using {target.DisplayName.Length}/{Limits.MaxGroupNameLength} characters."));
|
||||||
|
|
||||||
await ctx.Reply(embed: eb.Build());
|
await ctx.Reply(embed: eb.Build());
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -201,30 +208,41 @@ public class Groups
|
||||||
noDescriptionSetMessage +=
|
noDescriptionSetMessage +=
|
||||||
$" To set one, type `pk;group {target.Reference(ctx)} description <description>`.";
|
$" To set one, type `pk;group {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)
|
if (target.Description == null)
|
||||||
|
{
|
||||||
await ctx.Reply(noDescriptionSetMessage);
|
await ctx.Reply(noDescriptionSetMessage);
|
||||||
else
|
return;
|
||||||
await ctx.Reply($"```\n{target.Description}\n```");
|
}
|
||||||
|
|
||||||
|
if (format == ReplyFormat.Raw)
|
||||||
|
{
|
||||||
|
await ctx.Reply($"```\n{target.Description}\n```");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (format == ReplyFormat.Plaintext)
|
||||||
|
{
|
||||||
|
var eb = new EmbedBuilder()
|
||||||
|
.Description($"Showing description for group {target.Reference(ctx)}");
|
||||||
|
await ctx.Reply(target.Description, embed: eb.Build());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx.HasNext(false))
|
if (!ctx.HasNext(false))
|
||||||
{
|
{
|
||||||
if (target.Description == null)
|
await ctx.Reply(embed: new EmbedBuilder()
|
||||||
await ctx.Reply(noDescriptionSetMessage);
|
.Title("Group description")
|
||||||
else
|
.Description(target.Description)
|
||||||
await ctx.Reply(embed: new EmbedBuilder()
|
.Field(new Embed.Field("\u200B",
|
||||||
.Title("Group description")
|
$"To print the description with formatting, type `pk;group {target.Reference(ctx)} description -raw`."
|
||||||
.Description(target.Description)
|
+ (ctx.System?.Id == target.System
|
||||||
.Field(new Embed.Field("\u200B",
|
? $" To clear it, type `pk;group {target.Reference(ctx)} description -clear`."
|
||||||
$"To print the description with formatting, type `pk;group {target.Reference(ctx)} description -raw`."
|
: "")
|
||||||
+ (ctx.System?.Id == target.System
|
+ $" Using {target.Description.Length}/{Limits.MaxDescriptionLength} characters."))
|
||||||
? $" To clear it, type `pk;group {target.Reference(ctx)} description -clear`."
|
.Build());
|
||||||
: "")
|
|
||||||
+ $" Using {target.Description.Length}/{Limits.MaxDescriptionLength} characters."))
|
|
||||||
.Build());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -385,7 +403,7 @@ public class Groups
|
||||||
public async Task GroupColor(Context ctx, PKGroup target)
|
public async Task GroupColor(Context ctx, PKGroup target)
|
||||||
{
|
{
|
||||||
var isOwnSystem = ctx.System?.Id == target.System;
|
var isOwnSystem = ctx.System?.Id == target.System;
|
||||||
var matchedRaw = ctx.MatchRaw();
|
var matchedFormat = ctx.MatchFormat();
|
||||||
var matchedClear = ctx.MatchClear();
|
var matchedClear = ctx.MatchClear();
|
||||||
|
|
||||||
if (!isOwnSystem || !(ctx.HasNext() || matchedClear))
|
if (!isOwnSystem || !(ctx.HasNext() || matchedClear))
|
||||||
|
|
@ -393,8 +411,10 @@ public class Groups
|
||||||
if (target.Color == null)
|
if (target.Color == null)
|
||||||
await ctx.Reply(
|
await ctx.Reply(
|
||||||
"This group does not have a color set." + (isOwnSystem ? $" To set one, type `pk;group {target.Reference(ctx)} color <color>`." : ""));
|
"This group does not have a color set." + (isOwnSystem ? $" To set one, type `pk;group {target.Reference(ctx)} color <color>`." : ""));
|
||||||
else if (matchedRaw)
|
else if (matchedFormat == ReplyFormat.Raw)
|
||||||
await ctx.Reply("```\n#" + target.Color + "\n```");
|
await ctx.Reply("```\n#" + target.Color + "\n```");
|
||||||
|
else if (matchedFormat == ReplyFormat.Plaintext)
|
||||||
|
await ctx.Reply(target.Color);
|
||||||
else
|
else
|
||||||
await ctx.Reply(embed: new EmbedBuilder()
|
await ctx.Reply(embed: new EmbedBuilder()
|
||||||
.Title("Group color")
|
.Title("Group color")
|
||||||
|
|
|
||||||
|
|
@ -70,30 +70,41 @@ public class MemberEdit
|
||||||
noDescriptionSetMessage +=
|
noDescriptionSetMessage +=
|
||||||
$" To set one, type `pk;member {target.Reference(ctx)} description <description>`.";
|
$" 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)
|
if (target.Description == null)
|
||||||
|
{
|
||||||
await ctx.Reply(noDescriptionSetMessage);
|
await ctx.Reply(noDescriptionSetMessage);
|
||||||
else
|
return;
|
||||||
await ctx.Reply($"```\n{target.Description}\n```");
|
}
|
||||||
|
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx.HasNext(false))
|
if (!ctx.HasNext(false))
|
||||||
{
|
{
|
||||||
if (target.Description == null)
|
await ctx.Reply(embed: new EmbedBuilder()
|
||||||
await ctx.Reply(noDescriptionSetMessage);
|
.Title("Member description")
|
||||||
else
|
.Description(target.Description)
|
||||||
await ctx.Reply(embed: new EmbedBuilder()
|
.Field(new Embed.Field("\u200B",
|
||||||
.Title("Member description")
|
$"To print the description with formatting, type `pk;member {target.Reference(ctx)} description -raw`."
|
||||||
.Description(target.Description)
|
+ (ctx.System?.Id == target.System
|
||||||
.Field(new Embed.Field("\u200B",
|
? $" To clear it, type `pk;member {target.Reference(ctx)} description -clear`."
|
||||||
$"To print the description with formatting, type `pk;member {target.Reference(ctx)} description -raw`."
|
: "")
|
||||||
+ (ctx.System?.Id == target.System
|
+ $" Using {target.Description.Length}/{Limits.MaxDescriptionLength} characters."))
|
||||||
? $" To clear it, type `pk;member {target.Reference(ctx)} description -clear`."
|
.Build());
|
||||||
: "")
|
|
||||||
+ $" Using {target.Description.Length}/{Limits.MaxDescriptionLength} characters."))
|
|
||||||
.Build());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,26 +137,37 @@ public class MemberEdit
|
||||||
|
|
||||||
ctx.CheckSystemPrivacy(target.System, target.PronounPrivacy);
|
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)
|
if (target.Pronouns == null)
|
||||||
|
{
|
||||||
await ctx.Reply(noPronounsSetMessage);
|
await ctx.Reply(noPronounsSetMessage);
|
||||||
else
|
return;
|
||||||
await ctx.Reply($"```\n{target.Pronouns}\n```");
|
}
|
||||||
|
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx.HasNext(false))
|
if (!ctx.HasNext(false))
|
||||||
{
|
{
|
||||||
if (target.Pronouns == null)
|
await ctx.Reply(
|
||||||
await ctx.Reply(noPronounsSetMessage);
|
$"**{target.NameFor(ctx)}**'s pronouns are **{target.Pronouns}**.\nTo print the pronouns with formatting, type `pk;member {target.Reference(ctx)} pronouns -raw`."
|
||||||
else
|
+ (ctx.System?.Id == target.System
|
||||||
await ctx.Reply(
|
? $" To clear them, type `pk;member {target.Reference(ctx)} pronouns -clear`."
|
||||||
$"**{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
|
+ $" Using {target.Pronouns.Length}/{Limits.MaxPronounsLength} characters.");
|
||||||
? $" To clear them, type `pk;member {target.Reference(ctx)} pronouns -clear`."
|
|
||||||
: "")
|
|
||||||
+ $" Using {target.Pronouns.Length}/{Limits.MaxPronounsLength} characters.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -232,7 +254,7 @@ public class MemberEdit
|
||||||
public async Task Color(Context ctx, PKMember target)
|
public async Task Color(Context ctx, PKMember target)
|
||||||
{
|
{
|
||||||
var isOwnSystem = ctx.System?.Id == target.System;
|
var isOwnSystem = ctx.System?.Id == target.System;
|
||||||
var matchedRaw = ctx.MatchRaw();
|
var matchedFormat = ctx.MatchFormat();
|
||||||
var matchedClear = ctx.MatchClear();
|
var matchedClear = ctx.MatchClear();
|
||||||
|
|
||||||
if (!isOwnSystem || !(ctx.HasNext() || matchedClear))
|
if (!isOwnSystem || !(ctx.HasNext() || matchedClear))
|
||||||
|
|
@ -240,8 +262,10 @@ public class MemberEdit
|
||||||
if (target.Color == null)
|
if (target.Color == null)
|
||||||
await ctx.Reply(
|
await ctx.Reply(
|
||||||
"This member does not have a color set." + (isOwnSystem ? $" To set one, type `pk;member {target.Reference(ctx)} color <color>`." : ""));
|
"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```");
|
await ctx.Reply("```\n#" + target.Color + "\n```");
|
||||||
|
else if (matchedFormat == ReplyFormat.Plaintext)
|
||||||
|
await ctx.Reply(target.Color);
|
||||||
else
|
else
|
||||||
await ctx.Reply(embed: new EmbedBuilder()
|
await ctx.Reply(embed: new EmbedBuilder()
|
||||||
.Title("Member color")
|
.Title("Member color")
|
||||||
|
|
@ -388,12 +412,26 @@ public class MemberEdit
|
||||||
|
|
||||||
// No perms check, display name isn't covered by member privacy
|
// 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)
|
if (target.DisplayName == null)
|
||||||
|
{
|
||||||
await ctx.Reply(noDisplayNameSetMessage);
|
await ctx.Reply(noDisplayNameSetMessage);
|
||||||
else
|
return;
|
||||||
await ctx.Reply($"```\n{target.DisplayName}\n```");
|
}
|
||||||
|
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -450,12 +488,26 @@ public class MemberEdit
|
||||||
// No perms check, display name isn't covered by member privacy
|
// No perms check, display name isn't covered by member privacy
|
||||||
var memberGuildConfig = await ctx.Repository.GetMemberGuild(ctx.Guild.Id, target.Id);
|
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)
|
if (memberGuildConfig.DisplayName == null)
|
||||||
|
{
|
||||||
await ctx.Reply(noServerNameSetMessage);
|
await ctx.Reply(noServerNameSetMessage);
|
||||||
else
|
return;
|
||||||
await ctx.Reply($"```\n{memberGuildConfig.DisplayName}\n```");
|
}
|
||||||
|
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -352,7 +352,9 @@ public class ProxiedMessage
|
||||||
else if (!await ctx.CheckPermissionsInGuildChannel(channel, PermissionSet.ViewChannel))
|
else if (!await ctx.CheckPermissionsInGuildChannel(channel, PermissionSet.ViewChannel))
|
||||||
showContent = false;
|
showContent = false;
|
||||||
|
|
||||||
if (ctx.MatchRaw())
|
var format = ctx.MatchFormat();
|
||||||
|
|
||||||
|
if (format != ReplyFormat.Standard)
|
||||||
{
|
{
|
||||||
var discordMessage = await _rest.GetMessageOrNull(message.Message.Channel, message.Message.Mid);
|
var discordMessage = await _rest.GetMessageOrNull(message.Message.Channel, message.Message.Mid);
|
||||||
if (discordMessage == null || !showContent)
|
if (discordMessage == null || !showContent)
|
||||||
|
|
@ -365,21 +367,32 @@ public class ProxiedMessage
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ctx.Reply($"```{content}```");
|
if (format == ReplyFormat.Raw)
|
||||||
|
|
||||||
if (Regex.IsMatch(content, "```.*```", RegexOptions.Singleline))
|
|
||||||
{
|
{
|
||||||
var stream = new MemoryStream(Encoding.UTF8.GetBytes(content));
|
await ctx.Reply($"```{content}```");
|
||||||
await ctx.Rest.CreateMessage(
|
|
||||||
ctx.Channel.Id,
|
if (Regex.IsMatch(content, "```.*```", RegexOptions.Singleline))
|
||||||
new MessageRequest
|
{
|
||||||
{
|
var stream = new MemoryStream(Encoding.UTF8.GetBytes(content));
|
||||||
Content = $"{Emojis.Warn} Message contains codeblocks, raw source sent as an attachment."
|
await ctx.Rest.CreateMessage(
|
||||||
},
|
ctx.Channel.Id,
|
||||||
new[] { new MultipartFile("message.txt", stream, null, null, null) });
|
new MessageRequest
|
||||||
|
{
|
||||||
|
Content = $"{Emojis.Warn} Message contains codeblocks, raw source sent as an attachment."
|
||||||
|
},
|
||||||
|
new[] { new MultipartFile("message.txt", stream, null, null, null) });
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (format == ReplyFormat.Plaintext)
|
||||||
|
{
|
||||||
|
var eb = new EmbedBuilder()
|
||||||
|
.Description($"Showing contents of message {message.Message.Mid}");
|
||||||
|
await ctx.Reply(content, embed: eb.Build());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDelete)
|
if (isDelete)
|
||||||
|
|
|
||||||
|
|
@ -37,24 +37,35 @@ public class SystemEdit
|
||||||
if (isOwnSystem)
|
if (isOwnSystem)
|
||||||
noNameSetMessage += " Type `pk;system name <name>` to set one.";
|
noNameSetMessage += " Type `pk;system name <name>` to set one.";
|
||||||
|
|
||||||
if (ctx.MatchRaw())
|
var format = ctx.MatchFormat();
|
||||||
{
|
|
||||||
if (target.Name != null)
|
// if there's nothing next or what's next is "raw"/"plaintext" we're doing a query, so check for null
|
||||||
await ctx.Reply($"```\n{target.Name}\n```");
|
if (!ctx.HasNext(false) || format != ReplyFormat.Standard)
|
||||||
else
|
if (target.Name == null)
|
||||||
|
{
|
||||||
await ctx.Reply(noNameSetMessage);
|
await ctx.Reply(noNameSetMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (format == ReplyFormat.Raw)
|
||||||
|
{
|
||||||
|
await ctx.Reply($"` ``\n{target.Name}\n` ``");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (format == ReplyFormat.Plaintext)
|
||||||
|
{
|
||||||
|
var eb = new EmbedBuilder()
|
||||||
|
.Description($"Showing name for system {target.DisplayHid()}");
|
||||||
|
await ctx.Reply(target.Name, embed: eb.Build());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx.HasNext(false))
|
if (!ctx.HasNext(false))
|
||||||
{
|
{
|
||||||
if (target.Name != null)
|
await ctx.Reply(
|
||||||
await ctx.Reply(
|
$"{(isOwnSystem ? "Your" : "This")} system's name is currently **{target.Name}**."
|
||||||
$"{(isOwnSystem ? "Your" : "This")} system's name is currently **{target.Name}**."
|
+ (isOwnSystem ? " Type `pk;system name -clear` to clear it." : "")
|
||||||
+ (isOwnSystem ? " Type `pk;system name -clear` to clear it." : "")
|
+ $" Using {target.Name.Length}/{Limits.MaxSystemNameLength} characters.");
|
||||||
+ $" Using {target.Name.Length}/{Limits.MaxSystemNameLength} characters.");
|
|
||||||
else
|
|
||||||
await ctx.Reply(noNameSetMessage);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,24 +102,35 @@ public class SystemEdit
|
||||||
|
|
||||||
var settings = await ctx.Repository.GetSystemGuild(ctx.Guild.Id, target.Id);
|
var settings = await ctx.Repository.GetSystemGuild(ctx.Guild.Id, target.Id);
|
||||||
|
|
||||||
if (ctx.MatchRaw())
|
var format = ctx.MatchFormat();
|
||||||
{
|
|
||||||
if (settings.DisplayName != null)
|
// if there's nothing next or what's next is "raw"/"plaintext" we're doing a query, so check for null
|
||||||
await ctx.Reply($"```\n{settings.DisplayName}\n```");
|
if (!ctx.HasNext(false) || format != ReplyFormat.Standard)
|
||||||
else
|
if (settings.DisplayName == null)
|
||||||
|
{
|
||||||
await ctx.Reply(noNameSetMessage);
|
await ctx.Reply(noNameSetMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (format == ReplyFormat.Raw)
|
||||||
|
{
|
||||||
|
await ctx.Reply($"` ``\n{settings.DisplayName}\n` ``");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (format == ReplyFormat.Plaintext)
|
||||||
|
{
|
||||||
|
var eb = new EmbedBuilder()
|
||||||
|
.Description($"Showing servername for system {target.DisplayHid()}");
|
||||||
|
await ctx.Reply(settings.DisplayName, embed: eb.Build());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx.HasNext(false))
|
if (!ctx.HasNext(false))
|
||||||
{
|
{
|
||||||
if (settings.DisplayName != null)
|
await ctx.Reply(
|
||||||
await ctx.Reply(
|
$"{(isOwnSystem ? "Your" : "This")} system's name for this server is currently **{settings.DisplayName}**."
|
||||||
$"{(isOwnSystem ? "Your" : "This")} system's name for this server is currently **{settings.DisplayName}**."
|
+ (isOwnSystem ? " Type `pk;system servername -clear` to clear it." : "")
|
||||||
+ (isOwnSystem ? " Type `pk;system servername -clear` to clear it." : "")
|
+ $" Using {settings.DisplayName.Length}/{Limits.MaxSystemNameLength} characters.");
|
||||||
+ $" Using {settings.DisplayName.Length}/{Limits.MaxSystemNameLength} characters.");
|
|
||||||
else
|
|
||||||
await ctx.Reply(noNameSetMessage);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,28 +165,39 @@ public class SystemEdit
|
||||||
if (isOwnSystem)
|
if (isOwnSystem)
|
||||||
noDescriptionSetMessage += " To set one, type `pk;s description <description>`.";
|
noDescriptionSetMessage += " To set one, type `pk;s 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)
|
if (target.Description == null)
|
||||||
|
{
|
||||||
await ctx.Reply(noDescriptionSetMessage);
|
await ctx.Reply(noDescriptionSetMessage);
|
||||||
else
|
return;
|
||||||
await ctx.Reply($"```\n{target.Description}\n```");
|
}
|
||||||
|
|
||||||
|
if (format == ReplyFormat.Raw)
|
||||||
|
{
|
||||||
|
await ctx.Reply($"` ``\n{target.Description}\n` ``");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (format == ReplyFormat.Plaintext)
|
||||||
|
{
|
||||||
|
var eb = new EmbedBuilder()
|
||||||
|
.Description($"Showing description for system {target.DisplayHid()}");
|
||||||
|
await ctx.Reply(target.Description, embed: eb.Build());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx.HasNext(false))
|
if (!ctx.HasNext(false))
|
||||||
{
|
{
|
||||||
if (target.Description == null)
|
await ctx.Reply(embed: new EmbedBuilder()
|
||||||
await ctx.Reply(noDescriptionSetMessage);
|
.Title("System description")
|
||||||
else
|
.Description(target.Description)
|
||||||
await ctx.Reply(embed: new EmbedBuilder()
|
.Footer(new Embed.EmbedFooter(
|
||||||
.Title("System description")
|
"To print the description with formatting, type `pk;s description -raw`."
|
||||||
.Description(target.Description)
|
+ (isOwnSystem ? " To clear it, type `pk;s description -clear`. To change it, type `pk;s description <new description>`." : "")
|
||||||
.Footer(new Embed.EmbedFooter(
|
+ $" Using {target.Description.Length}/{Limits.MaxDescriptionLength} characters."))
|
||||||
"To print the description with formatting, type `pk;s description -raw`."
|
.Build());
|
||||||
+ (isOwnSystem ? " To clear it, type `pk;s description -clear`. To change it, type `pk;s description <new description>`." : "")
|
|
||||||
+ $" Using {target.Description.Length}/{Limits.MaxDescriptionLength} characters."))
|
|
||||||
.Build());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,7 +224,7 @@ public class SystemEdit
|
||||||
public async Task Color(Context ctx, PKSystem target)
|
public async Task Color(Context ctx, PKSystem target)
|
||||||
{
|
{
|
||||||
var isOwnSystem = ctx.System?.Id == target.Id;
|
var isOwnSystem = ctx.System?.Id == target.Id;
|
||||||
var matchedRaw = ctx.MatchRaw();
|
var matchedFormat = ctx.MatchFormat();
|
||||||
var matchedClear = ctx.MatchClear();
|
var matchedClear = ctx.MatchClear();
|
||||||
|
|
||||||
if (!isOwnSystem || !(ctx.HasNext() || matchedClear))
|
if (!isOwnSystem || !(ctx.HasNext() || matchedClear))
|
||||||
|
|
@ -199,8 +232,10 @@ public class SystemEdit
|
||||||
if (target.Color == null)
|
if (target.Color == null)
|
||||||
await ctx.Reply(
|
await ctx.Reply(
|
||||||
"This system does not have a color set." + (isOwnSystem ? " To set one, type `pk;system color <color>`." : ""));
|
"This system does not have a color set." + (isOwnSystem ? " To set one, type `pk;system color <color>`." : ""));
|
||||||
else if (matchedRaw)
|
else if (matchedFormat == ReplyFormat.Raw)
|
||||||
await ctx.Reply("```\n#" + target.Color + "\n```");
|
await ctx.Reply("```\n#" + target.Color + "\n```");
|
||||||
|
else if (matchedFormat == ReplyFormat.Plaintext)
|
||||||
|
await ctx.Reply(target.Color);
|
||||||
else
|
else
|
||||||
await ctx.Reply(embed: new EmbedBuilder()
|
await ctx.Reply(embed: new EmbedBuilder()
|
||||||
.Title("System color")
|
.Title("System color")
|
||||||
|
|
@ -246,22 +281,33 @@ public class SystemEdit
|
||||||
? "You currently have no system tag set. To set one, type `pk;s tag <tag>`."
|
? "You currently have no system tag set. To set one, type `pk;s tag <tag>`."
|
||||||
: "This system currently has no system tag set.";
|
: "This system currently has no system tag set.";
|
||||||
|
|
||||||
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.Tag == null)
|
if (target.Tag == null)
|
||||||
|
{
|
||||||
await ctx.Reply(noTagSetMessage);
|
await ctx.Reply(noTagSetMessage);
|
||||||
else
|
return;
|
||||||
await ctx.Reply($"```\n{target.Tag}\n```");
|
}
|
||||||
|
|
||||||
|
if (format == ReplyFormat.Raw)
|
||||||
|
{
|
||||||
|
await ctx.Reply($"```\n{target.Tag}\n```");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (format == ReplyFormat.Plaintext)
|
||||||
|
{
|
||||||
|
var eb = new EmbedBuilder()
|
||||||
|
.Description($"Showing tag for system {target.DisplayHid()}");
|
||||||
|
await ctx.Reply(target.Tag, embed: eb.Build());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx.HasNext(false))
|
if (!ctx.HasNext(false))
|
||||||
{
|
{
|
||||||
if (target.Tag == null)
|
await ctx.Reply($"{(isOwnSystem ? "Your" : "This system's")} current system tag is {target.Tag.AsCode()}."
|
||||||
await ctx.Reply(noTagSetMessage);
|
+ (isOwnSystem ? "To change it, type `pk;s tag <tag>`. To clear it, type `pk;s tag -clear`." : ""));
|
||||||
else
|
|
||||||
await ctx.Reply($"{(isOwnSystem ? "Your" : "This system's")} current system tag is {target.Tag.AsCode()}."
|
|
||||||
+ (isOwnSystem ? "To change it, type `pk;s tag <tag>`. To clear it, type `pk;s tag -clear`." : ""));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -296,15 +342,22 @@ public class SystemEdit
|
||||||
|
|
||||||
var settings = await ctx.Repository.GetSystemGuild(ctx.Guild.Id, target.Id);
|
var settings = await ctx.Repository.GetSystemGuild(ctx.Guild.Id, target.Id);
|
||||||
|
|
||||||
async Task Show(bool raw = false)
|
async Task Show(ReplyFormat format = ReplyFormat.Standard)
|
||||||
{
|
{
|
||||||
if (settings.Tag != null)
|
if (settings.Tag != null)
|
||||||
{
|
{
|
||||||
if (raw)
|
if (format == ReplyFormat.Raw)
|
||||||
{
|
{
|
||||||
await ctx.Reply($"```{settings.Tag}```");
|
await ctx.Reply($"```{settings.Tag}```");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (format == ReplyFormat.Plaintext)
|
||||||
|
{
|
||||||
|
var eb = new EmbedBuilder()
|
||||||
|
.Description($"Showing servertag for system {target.DisplayHid()}");
|
||||||
|
await ctx.Reply(settings.Tag, embed: eb.Build());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var msg = $"Your current system tag in '{ctx.Guild.Name}' is {settings.Tag.AsCode()}";
|
var msg = $"Your current system tag in '{ctx.Guild.Name}' is {settings.Tag.AsCode()}";
|
||||||
if (!settings.TagEnabled)
|
if (!settings.TagEnabled)
|
||||||
|
|
@ -400,8 +453,8 @@ public class SystemEdit
|
||||||
await EnableDisable(false);
|
await EnableDisable(false);
|
||||||
else if (ctx.Match("enable") || ctx.MatchFlag("enable"))
|
else if (ctx.Match("enable") || ctx.MatchFlag("enable"))
|
||||||
await EnableDisable(true);
|
await EnableDisable(true);
|
||||||
else if (ctx.MatchRaw())
|
else if (ctx.MatchFormat() != ReplyFormat.Standard)
|
||||||
await Show(true);
|
await Show(ctx.MatchFormat());
|
||||||
else if (!ctx.HasNext(false))
|
else if (!ctx.HasNext(false))
|
||||||
await Show();
|
await Show();
|
||||||
else
|
else
|
||||||
|
|
@ -418,24 +471,35 @@ public class SystemEdit
|
||||||
if (isOwnSystem)
|
if (isOwnSystem)
|
||||||
noPronounsSetMessage += " To set some, type `pk;system pronouns <pronouns>`";
|
noPronounsSetMessage += " To set some, type `pk;system pronouns <pronouns>`";
|
||||||
|
|
||||||
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)
|
if (target.Pronouns == null)
|
||||||
|
{
|
||||||
await ctx.Reply(noPronounsSetMessage);
|
await ctx.Reply(noPronounsSetMessage);
|
||||||
else
|
return;
|
||||||
await ctx.Reply($"```\n{target.Pronouns}\n```");
|
}
|
||||||
|
|
||||||
|
if (format == ReplyFormat.Raw)
|
||||||
|
{
|
||||||
|
await ctx.Reply($"```\n{target.Pronouns}\n```");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (format == ReplyFormat.Plaintext)
|
||||||
|
{
|
||||||
|
var eb = new EmbedBuilder()
|
||||||
|
.Description($"Showing pronouns for system {target.DisplayHid()}");
|
||||||
|
await ctx.Reply(target.Pronouns, embed: eb.Build());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx.HasNext(false))
|
if (!ctx.HasNext(false))
|
||||||
{
|
{
|
||||||
if (target.Pronouns == null)
|
await ctx.Reply($"{(isOwnSystem ? "Your" : "This system's")} current pronouns are **{target.Pronouns}**.\nTo print the pronouns with formatting, type `pk;system pronouns -raw`."
|
||||||
await ctx.Reply(noPronounsSetMessage);
|
+ (isOwnSystem ? " To clear them, type `pk;system pronouns -clear`."
|
||||||
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`."
|
+ $" Using {target.Pronouns.Length}/{Limits.MaxPronounsLength} characters.");
|
||||||
+ (isOwnSystem ? " To clear them, type `pk;system pronouns -clear`."
|
|
||||||
: "")
|
|
||||||
+ $" Using {target.Pronouns.Length}/{Limits.MaxPronounsLength} characters.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue