This commit is contained in:
Ske 2020-05-05 19:09:18 +02:00
parent c1d17c2944
commit 892601110f
4 changed files with 21 additions and 4 deletions

View File

@ -11,6 +11,7 @@ using Autofac;
using DSharpPlus; using DSharpPlus;
using DSharpPlus.Entities; using DSharpPlus.Entities;
using DSharpPlus.EventArgs; using DSharpPlus.EventArgs;
using DSharpPlus.Exceptions;
using NodaTime; using NodaTime;
@ -122,6 +123,8 @@ namespace PluralKit.Bot
{ {
// Make this beforehand so we can access the event ID for logging // Make this beforehand so we can access the event ID for logging
var sentryEvent = new SentryEvent(exc); var sentryEvent = new SentryEvent(exc);
if (exc is BadRequestException bre)
sentryEvent.SetExtra("errors", MiscUtils.ExtractError(bre));
_logger.Error(exc, "Exception in bot event handler (Sentry ID: {SentryEventId})", sentryEvent.EventId); _logger.Error(exc, "Exception in bot event handler (Sentry ID: {SentryEventId})", sentryEvent.EventId);

View File

@ -33,7 +33,7 @@ namespace PluralKit.Bot {
var eb = new DiscordEmbedBuilder() var eb = new DiscordEmbedBuilder()
.WithColor(DiscordUtils.Gray) .WithColor(DiscordUtils.Gray)
.WithTitle(system.Name ?? null) .WithTitle(system.Name ?? null)
.WithThumbnailUrl(system.AvatarUrl ?? null) .WithThumbnailUrl(system.AvatarUrl)
.WithFooter($"System ID: {system.Hid} | Created on {DateTimeFormats.ZonedDateTimeFormat.Format(system.Created.InZone(system.Zone))}"); .WithFooter($"System ID: {system.Hid} | Created on {DateTimeFormats.ZonedDateTimeFormat.Format(system.Created.InZone(system.Zone))}");
var latestSwitch = await _data.GetLatestSwitch(system); var latestSwitch = await _data.GetLatestSwitch(system);
@ -66,7 +66,8 @@ namespace PluralKit.Bot {
// TODO: pronouns in ?-reacted response using this card // TODO: pronouns in ?-reacted response using this card
var timestamp = DiscordUtils.SnowflakeToInstant(messageId); var timestamp = DiscordUtils.SnowflakeToInstant(messageId);
return new DiscordEmbedBuilder() return new DiscordEmbedBuilder()
.WithAuthor($"#{channel.Name}: {member.Name}", iconUrl: member.AvatarUrl) .WithAuthor($"#{channel.Name}: {member.Name}", iconUrl: DiscordUtils.WorkaroundForUrlBug(member.AvatarUrl))
.WithThumbnailUrl(member.AvatarUrl)
.WithDescription(content?.NormalizeLineEndSpacing()) .WithDescription(content?.NormalizeLineEndSpacing())
.WithFooter($"System ID: {system.Hid} | Member ID: {member.Hid} | Sender: {sender.Username}#{sender.Discriminator} ({sender.Id}) | Message ID: {messageId} | Original Message ID: {originalMsgId}") .WithFooter($"System ID: {system.Hid} | Member ID: {member.Hid} | Sender: {sender.Username}#{sender.Discriminator} ({sender.Id}) | Message ID: {messageId} | Original Message ID: {originalMsgId}")
.WithTimestamp(timestamp.ToDateTimeOffset()) .WithTimestamp(timestamp.ToDateTimeOffset())
@ -101,7 +102,7 @@ namespace PluralKit.Bot {
var eb = new DiscordEmbedBuilder() var eb = new DiscordEmbedBuilder()
// TODO: add URL of website when that's up // TODO: add URL of website when that's up
.WithAuthor(name, avatar) .WithAuthor(name, iconUrl: DiscordUtils.WorkaroundForUrlBug(avatar))
.WithColor(member.MemberPrivacy.CanAccess(ctx) ? color : DiscordUtils.Gray) .WithColor(member.MemberPrivacy.CanAccess(ctx) ? color : DiscordUtils.Gray)
.WithFooter($"System ID: {system.Hid} | Member ID: {member.Hid} | Created on {DateTimeFormats.ZonedDateTimeFormat.Format(member.Created.InZone(system.Zone))}"); .WithFooter($"System ID: {system.Hid} | Member ID: {member.Hid} | Created on {DateTimeFormats.ZonedDateTimeFormat.Format(member.Created.InZone(system.Zone))}");
@ -167,7 +168,7 @@ namespace PluralKit.Bot {
} }
var eb = new DiscordEmbedBuilder() var eb = new DiscordEmbedBuilder()
.WithAuthor(msg.Member.Name, msg.Member.AvatarUrl) .WithAuthor(msg.Member.Name, iconUrl: DiscordUtils.WorkaroundForUrlBug(msg.Member.AvatarUrl))
.WithDescription(serverMsg?.Content?.NormalizeLineEndSpacing() ?? "*(message contents deleted or inaccessible)*") .WithDescription(serverMsg?.Content?.NormalizeLineEndSpacing() ?? "*(message contents deleted or inaccessible)*")
.WithImageUrl(serverMsg?.Attachments?.FirstOrDefault()?.Url) .WithImageUrl(serverMsg?.Attachments?.FirstOrDefault()?.Url)
.AddField("System", .AddField("System",

View File

@ -84,5 +84,11 @@ namespace PluralKit.Bot
await msg.CreateReactionAsync(DiscordEmoji.FromUnicode(reaction)); await msg.CreateReactionAsync(DiscordEmoji.FromUnicode(reaction));
} }
} }
public static string WorkaroundForUrlBug(string input)
{
// Workaround for https://github.com/DSharpPlus/DSharpPlus/issues/565
return input.Replace("%20", "+");
}
} }
} }

View File

@ -3,6 +3,8 @@ using System.Linq;
using System.Net.Sockets; using System.Net.Sockets;
using System.Threading.Tasks; using System.Threading.Tasks;
using DSharpPlus.Exceptions;
using Npgsql; using Npgsql;
using PluralKit.Core; using PluralKit.Core;
@ -40,5 +42,10 @@ namespace PluralKit.Bot
// This may expanded at some point. // This may expanded at some point.
return true; return true;
} }
public static string ExtractError(BadRequestException e)
{
return e.WebResponse.Response;
}
} }
} }