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

@ -352,7 +352,9 @@ public class ProxiedMessage
else if (!await ctx.CheckPermissionsInGuildChannel(channel, PermissionSet.ViewChannel))
showContent = false;
if (ctx.MatchRaw())
var format = ctx.MatchFormat();
if (format != ReplyFormat.Standard)
{
var discordMessage = await _rest.GetMessageOrNull(message.Message.Channel, message.Message.Mid);
if (discordMessage == null || !showContent)
@ -365,21 +367,32 @@ public class ProxiedMessage
return;
}
await ctx.Reply($"```{content}```");
if (Regex.IsMatch(content, "```.*```", RegexOptions.Singleline))
if (format == ReplyFormat.Raw)
{
var stream = new MemoryStream(Encoding.UTF8.GetBytes(content));
await ctx.Rest.CreateMessage(
ctx.Channel.Id,
new MessageRequest
{
Content = $"{Emojis.Warn} Message contains codeblocks, raw source sent as an attachment."
},
new[] { new MultipartFile("message.txt", stream, null, null, null) });
await ctx.Reply($"```{content}```");
if (Regex.IsMatch(content, "```.*```", RegexOptions.Singleline))
{
var stream = new MemoryStream(Encoding.UTF8.GetBytes(content));
await ctx.Rest.CreateMessage(
ctx.Channel.Id,
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)