using System.Collections.Generic; using System.Linq; using Discord; using Discord.WebSocket; using Sentry; namespace PluralKit.Bot { public static class BreadcrumbExtensions { public static void AddMessageBreadcrumb(this Scope scope, SocketMessage msg) { scope.AddBreadcrumb(msg.Content, "event.message", data: new Dictionary() { {"user", msg.Author.Id.ToString()}, {"channel", msg.Channel.Id.ToString()}, {"guild", ((msg.Channel as IGuildChannel)?.GuildId ?? 0).ToString()}, {"message", msg.Id.ToString()}, }); } public static void AddReactionAddedBreadcrumb(this Scope scope, Cacheable message, ISocketMessageChannel channel, SocketReaction reaction) { scope.AddBreadcrumb("", "event.reaction", data: new Dictionary() { {"user", reaction.UserId.ToString()}, {"channel", channel.Id.ToString()}, {"guild", ((channel as IGuildChannel)?.GuildId ?? 0).ToString()}, {"message", message.Id.ToString()}, {"reaction", reaction.Emote.Name} }); } public static void AddMessageDeleteBreadcrumb(this Scope scope, Cacheable message, ISocketMessageChannel channel) { scope.AddBreadcrumb("", "event.messageDelete", data: new Dictionary() { {"channel", channel.Id.ToString()}, {"guild", ((channel as IGuildChannel)?.GuildId ?? 0).ToString()}, {"message", message.Id.ToString()}, }); } public static void AddMessageBulkDeleteBreadcrumb(this Scope scope, IReadOnlyCollection> messages, ISocketMessageChannel channel) { scope.AddBreadcrumb("", "event.messageDelete", data: new Dictionary() { {"channel", channel.Id.ToString()}, {"guild", ((channel as IGuildChannel)?.GuildId ?? 0).ToString()}, {"messages", string.Join(",", messages.Select(m => m.Id))}, }); } public static void AddPeriodicBreadcrumb(this Scope scope) => scope.AddBreadcrumb("", "periodic"); } }