feat: add prepend and append switches to Pk;edit (#436)
This commit is contained in:
parent
576b23bca5
commit
8d50ae55e7
@ -51,15 +51,28 @@ public class ProxiedMessage
|
|||||||
if (!ctx.HasNext())
|
if (!ctx.HasNext())
|
||||||
throw new PKSyntaxError("You need to include the message to edit in.");
|
throw new PKSyntaxError("You need to include the message to edit in.");
|
||||||
|
|
||||||
var newContent = ctx.RemainderOrNull().NormalizeLineEndSpacing();
|
|
||||||
|
|
||||||
if (newContent.Length > 2000)
|
|
||||||
throw new PKError("PluralKit cannot proxy messages over 2000 characters in length.");
|
|
||||||
|
|
||||||
var originalMsg = await _rest.GetMessageOrNull(msg.Message.Channel, msg.Message.Mid);
|
var originalMsg = await _rest.GetMessageOrNull(msg.Message.Channel, msg.Message.Mid);
|
||||||
if (originalMsg == null)
|
if (originalMsg == null)
|
||||||
throw new PKError("Could not edit message.");
|
throw new PKError("Could not edit message.");
|
||||||
|
|
||||||
|
// Check if we should append or prepend
|
||||||
|
var append = ctx.MatchFlag("append");
|
||||||
|
var prepend = ctx.MatchFlag("prepend");
|
||||||
|
|
||||||
|
// Grab the original message content and new message content
|
||||||
|
var originalContent = originalMsg.Content;
|
||||||
|
var newContent = ctx.RemainderOrNull().NormalizeLineEndSpacing();
|
||||||
|
|
||||||
|
// Append or prepend the new content to the original message content if needed.
|
||||||
|
// If no flag is supplied, the new contents will completly overwrite the old contents
|
||||||
|
// If both flags are specified. the message will be prepended AND appended
|
||||||
|
if (append && prepend) newContent = $"{newContent} {originalContent} {newContent}";
|
||||||
|
else if (append) newContent = originalContent +" "+ newContent;
|
||||||
|
else if (prepend) newContent = newContent +" "+ originalContent;
|
||||||
|
|
||||||
|
if (newContent.Length > 2000)
|
||||||
|
throw new PKError("PluralKit cannot proxy messages over 2000 characters in length.");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var editedMsg =
|
var editedMsg =
|
||||||
|
@ -74,6 +74,8 @@ You cannot look up private members or groups of another system.
|
|||||||
|pk;system frontpercent|-flat||Show "flat" frontpercent - percentages add up to 100%|
|
|pk;system frontpercent|-flat||Show "flat" frontpercent - percentages add up to 100%|
|
||||||
|pk;group \<group> frontpercent|-fronters-only|-fo|Show a group's frontpercent without the "no fronter" entry|
|
|pk;group \<group> frontpercent|-fronters-only|-fo|Show a group's frontpercent without the "no fronter" entry|
|
||||||
|pk;group \<group> frontpercent|-flat||Show "flat" frontpercent - percentages add up to 100%|
|
|pk;group \<group> frontpercent|-flat||Show "flat" frontpercent - percentages add up to 100%|
|
||||||
|
|pk;edit|-append||Append the new content to the old message instead of overwriting it|
|
||||||
|
|pk;edit|-prepend||Prepend the new content to the old message instead of overwriting it|
|
||||||
|Most commands|-all|-a|Show hidden/private information|
|
|Most commands|-all|-a|Show hidden/private information|
|
||||||
|Most commands|-raw|-r|Show text with formatting, for easier copy-pasting|
|
|Most commands|-raw|-r|Show text with formatting, for easier copy-pasting|
|
||||||
|All commands|-private|-priv|Show private information|
|
|All commands|-private|-priv|Show private information|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user