feat: add prepend and append switches to Pk;edit (#436)

This commit is contained in:
UsernameNotAvalible
2022-04-07 03:43:46 -04:00
committed by GitHub
parent 576b23bca5
commit 8d50ae55e7
2 changed files with 20 additions and 5 deletions

View File

@@ -51,15 +51,28 @@ public class ProxiedMessage
if (!ctx.HasNext())
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);
if (originalMsg == null)
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
{
var editedMsg =