feat: more log context

This commit is contained in:
sam 2024-11-27 15:48:30 +01:00
parent 4047df8610
commit 7749c9d9e2
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
21 changed files with 159 additions and 15 deletions

View file

@ -13,6 +13,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
using Catalogger.Backend.Extensions;
using Microsoft.Extensions.Options;
using Remora.Commands.Services;
using Remora.Commands.Tokenization;
@ -23,6 +24,7 @@ using Remora.Discord.Commands.Responders;
using Remora.Discord.Commands.Services;
using Remora.Discord.Gateway.Responders;
using Remora.Results;
using Serilog.Context;
namespace Catalogger.Backend.Bot.Responders;
@ -57,21 +59,34 @@ public class CustomInteractionResponder(
treeNameResolver
);
public async Task<Result> RespondAsync(
IInteractionCreate gatewayEvent,
CancellationToken ct = default
)
public async Task<Result> RespondAsync(IInteractionCreate evt, CancellationToken ct = default)
{
if (config.Discord.TestMode)
{
_logger.Information(
"Not responding to interaction create event {InteractionId} in {ChannelId} as test mode is enabled",
gatewayEvent.ID,
gatewayEvent.Channel.Map(c => c.ID).OrDefault()
evt.ID,
evt.Channel.Map(c => c.ID).OrDefault()
);
return Result.Success;
}
return await _inner.RespondAsync(gatewayEvent, ct);
using var _ = LogUtils.PushProperties(
("Event", nameof(IInteractionCreate)),
("InteractionId", evt.ID),
("GuildId", evt.GuildID),
("UserId", evt.User.Map(u => u.ID)),
("MemberId", evt.Member.Map(m => m.User.Map(u => u.ID).OrDefault())),
("ChannelId", evt.Channel.Map(c => c.ID)),
("InteractionType", evt.Type)
);
using var __ = LogContext.PushProperty(
"InteractionData",
evt.Data.HasValue ? (object?)evt.Data.Value : null,
true
);
return await _inner.RespondAsync(evt, ct);
}
}