hopefully a fix for #384

This commit is contained in:
spiral 2021-08-15 00:50:31 -04:00
parent 4761804082
commit 4c97a9daf6
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31
2 changed files with 11 additions and 8 deletions

View File

@ -7,6 +7,7 @@
public record GuildMemberPartial
{
public string? Avatar { get; init; }
public string? Nick { get; init; }
public ulong[] Roles { get; init; }
public string JoinedAt { get; init; }

View File

@ -132,8 +132,8 @@ namespace PluralKit.Bot
var repliedTo = trigger.ReferencedMessage.Value;
if (repliedTo != null)
{
var nickname = await FetchReferencedMessageAuthorNickname(trigger, repliedTo);
var embed = CreateReplyEmbed(match, trigger, repliedTo, nickname);
var (nickname, avatar) = await FetchReferencedMessageAuthorInfo(trigger, repliedTo);
var embed = CreateReplyEmbed(match, trigger, repliedTo, nickname, avatar);
if (embed != null)
embeds.Add(embed);
}
@ -164,25 +164,25 @@ namespace PluralKit.Bot
await HandleProxyExecutedActions(shard, conn, ctx, trigger, proxyMessage, match);
}
private async Task<string?> FetchReferencedMessageAuthorNickname(Message trigger, Message referenced)
private async Task<(string?, string?)> FetchReferencedMessageAuthorInfo(Message trigger, Message referenced)
{
if (referenced.WebhookId != null)
return null;
return (null, null);
try
{
var member = await _rest.GetGuildMember(trigger.GuildId!.Value, referenced.Author.Id);
return member?.Nick;
return (member?.Nick, member?.Avatar);
}
catch (ForbiddenException)
{
_logger.Warning("Failed to fetch member {UserId} in guild {GuildId} when getting reply nickname, falling back to username",
referenced.Author.Id, trigger.GuildId!.Value);
return null;
return (null, null);
}
}
private Embed CreateReplyEmbed(ProxyMatch match, Message trigger, Message repliedTo, string? nickname)
private Embed CreateReplyEmbed(ProxyMatch match, Message trigger, Message repliedTo, string? nickname, string? avatar)
{
// repliedTo doesn't have a GuildId field :/
var jumpLink = $"https://discord.com/channels/{trigger.GuildId}/{repliedTo.ChannelId}/{repliedTo.Id}";
@ -231,7 +231,9 @@ namespace PluralKit.Bot
}
var username = nickname ?? repliedTo.Author.Username;
var avatarUrl = $"https://cdn.discordapp.com/avatars/{repliedTo.Author.Id}/{repliedTo.Author.Avatar}.png";
var avatarUrl = avatar != null
? $"https://cdn.discordapp.com/guilds/{trigger.GuildId}/users/{repliedTo.Author.Id}/{avatar}.png"
: $"https://cdn.discordapp.com/avatars/{repliedTo.Author.Id}/{repliedTo.Author.Avatar}.png";
return new Embed
{