feat: add prepend and append switches to Pk;edit (#436)
This commit is contained in:
committed by
GitHub
parent
576b23bca5
commit
8d50ae55e7
@@ -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 =
|
||||
|
Reference in New Issue
Block a user