Reformat replies
This commit is contained in:
parent
97f5ab94c1
commit
4e5d02e1a4
@ -102,7 +102,8 @@ namespace PluralKit.Bot
|
|||||||
var embeds = new List<DiscordEmbed>();
|
var embeds = new List<DiscordEmbed>();
|
||||||
if (trigger.Reference?.Channel?.Id == trigger.ChannelId)
|
if (trigger.Reference?.Channel?.Id == trigger.ChannelId)
|
||||||
{
|
{
|
||||||
var embed = await CreateReplyEmbed(trigger);
|
var repliedTo = await FetchReplyOriginalMessage(trigger.Reference);
|
||||||
|
var embed = await CreateReplyEmbed(repliedTo);
|
||||||
if (embed != null)
|
if (embed != null)
|
||||||
embeds.Add(embed);
|
embeds.Add(embed);
|
||||||
}
|
}
|
||||||
@ -117,43 +118,48 @@ namespace PluralKit.Bot
|
|||||||
await HandleProxyExecutedActions(shard, conn, ctx, trigger, proxyMessage, match);
|
await HandleProxyExecutedActions(shard, conn, ctx, trigger, proxyMessage, match);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<DiscordEmbed> CreateReplyEmbed(DiscordMessage trigger)
|
private async Task<DiscordMessage> FetchReplyOriginalMessage(DiscordMessageReference reference)
|
||||||
{
|
{
|
||||||
DiscordMessage message;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
message = await trigger.Channel.GetMessageAsync(trigger.Reference.Message.Id);
|
return await reference.Channel.GetMessageAsync(reference.Message.Id);
|
||||||
}
|
}
|
||||||
catch (NotFoundException)
|
catch (NotFoundException)
|
||||||
{
|
{
|
||||||
_logger.Warning("Attempted to fetch reply message {ChannelId}/{MessageId} but it was not found",
|
_logger.Warning("Attempted to fetch reply message {ChannelId}/{MessageId} but it was not found",
|
||||||
trigger.Reference.Channel.Id, trigger.Reference.Message.Id);
|
reference.Channel.Id, reference.Message.Id);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
catch (UnauthorizedException)
|
catch (UnauthorizedException)
|
||||||
{
|
{
|
||||||
_logger.Warning("Attempted to fetch reply message {ChannelId}/{MessageId} but bot was not allowed to",
|
_logger.Warning("Attempted to fetch reply message {ChannelId}/{MessageId} but bot was not allowed to",
|
||||||
trigger.Reference.Channel.Id, trigger.Reference.Message.Id);
|
reference.Channel.Id, reference.Message.Id);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<DiscordEmbed> CreateReplyEmbed(DiscordMessage original)
|
||||||
|
{
|
||||||
var content = new StringBuilder();
|
var content = new StringBuilder();
|
||||||
content.Append($"[Reply to]({message.JumpLink}) ");
|
|
||||||
|
var hasContent = !string.IsNullOrWhiteSpace(original.Content);
|
||||||
if (message.WebhookMessage)
|
if (hasContent)
|
||||||
content.Append($"**[{message.Author.Username.EscapeMarkdown()}]({message.JumpLink})**");
|
{
|
||||||
|
content.Append($"**[Reply to:]({original.JumpLink})** ");
|
||||||
|
content.Append($"{original.Content.Truncate(100)}");
|
||||||
|
if (original.Attachments.Count > 0)
|
||||||
|
content.Append($" {Emojis.Paperclip}");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
content.Append(message.Author.Mention);
|
{
|
||||||
|
content.Append($"*[(click to see attachment)]({original.JumpLink})*");
|
||||||
content.Append(": ");
|
}
|
||||||
|
|
||||||
if (message.Attachments.Count > 0)
|
var username = (original.Author as DiscordMember)?.Nickname ?? original.Author.Username;
|
||||||
content.Append($"{Emojis.Image} ");
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(message.Content))
|
|
||||||
content.Append($"{message.Content.Truncate(100)}");
|
|
||||||
|
|
||||||
return new DiscordEmbedBuilder()
|
return new DiscordEmbedBuilder()
|
||||||
|
// unicodes: [three-per-em space] [left arrow emoji] [force emoji presentation]
|
||||||
|
.WithAuthor($"{username}\u2004\u21a9\ufe0f", iconUrl: original.Author.AvatarUrl)
|
||||||
.WithDescription(content.ToString())
|
.WithDescription(content.ToString())
|
||||||
.Build();
|
.Build();
|
||||||
}
|
}
|
||||||
|
@ -8,5 +8,6 @@
|
|||||||
public static readonly string RedQuestion = "\u2753";
|
public static readonly string RedQuestion = "\u2753";
|
||||||
public static readonly string Bell = "\U0001F514";
|
public static readonly string Bell = "\U0001F514";
|
||||||
public static readonly string Image = "\U0001F5BC";
|
public static readonly string Image = "\U0001F5BC";
|
||||||
|
public static readonly string Paperclip = "\U0001F4CE";
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user