diff --git a/PluralKit.Bot/Commands/ModCommands.cs b/PluralKit.Bot/Commands/ModCommands.cs index 8753bc9e..9d1071fa 100644 --- a/PluralKit.Bot/Commands/ModCommands.cs +++ b/PluralKit.Bot/Commands/ModCommands.cs @@ -32,7 +32,7 @@ namespace PluralKit.Bot.Commands var message = await Messages.Get(messageId); if (message == null) throw Errors.MessageNotFound(messageId); - await Context.Channel.SendMessageAsync(embed: await Embeds.CreateMessageInfoEmbed(messageId)); + await Context.Channel.SendMessageAsync(embed: await Embeds.CreateMessageInfoEmbed(message)); } [Command("message")] diff --git a/PluralKit.Bot/Services/EmbedService.cs b/PluralKit.Bot/Services/EmbedService.cs index bccfc4bc..e960bc08 100644 --- a/PluralKit.Bot/Services/EmbedService.cs +++ b/PluralKit.Bot/Services/EmbedService.cs @@ -120,9 +120,8 @@ namespace PluralKit.Bot { .Build(); } - public async Task CreateMessageInfoEmbed(ulong messageId) + public async Task CreateMessageInfoEmbed(MessageStore.StoredMessage msg) { - var msg = await _messages.Get(messageId); var channel = (ITextChannel) await _client.GetChannelAsync(msg.Message.Channel); var serverMsg = await channel.GetMessageAsync(msg.Message.Mid); @@ -131,7 +130,7 @@ namespace PluralKit.Bot { return new EmbedBuilder() .WithAuthor(msg.Member.Name, msg.Member.AvatarUrl) - .WithDescription(serverMsg.Content) + .WithDescription(serverMsg?.Content ?? "*(message contents deleted or inaccessible)*") .AddField("System", msg.System.Name != null ? $"{msg.System.Name} (`{msg.System.Hid}`)" : $"`{msg.System.Hid}`", true) .AddField("Member", memberStr, true) .WithTimestamp(SnowflakeUtils.FromSnowflake(msg.Message.Mid)) diff --git a/PluralKit.Bot/Services/ProxyService.cs b/PluralKit.Bot/Services/ProxyService.cs index 01af085a..3b117d8b 100644 --- a/PluralKit.Bot/Services/ProxyService.cs +++ b/PluralKit.Bot/Services/ProxyService.cs @@ -33,15 +33,16 @@ namespace PluralKit.Bot private LogChannelService _logger; private WebhookCacheService _webhookCache; private MessageStore _messageStorage; - + private EmbedService _embeds; - public ProxyService(IDiscordClient client, WebhookCacheService webhookCache, IDbConnection connection, LogChannelService logger, MessageStore messageStorage) + public ProxyService(IDiscordClient client, WebhookCacheService webhookCache, IDbConnection connection, LogChannelService logger, MessageStore messageStorage, EmbedService embeds) { - this._client = client; - this._webhookCache = webhookCache; - this._connection = connection; - this._logger = logger; - this._messageStorage = messageStorage; + _client = client; + _webhookCache = webhookCache; + _connection = connection; + _logger = logger; + _messageStorage = messageStorage; + _embeds = embeds; } private ProxyMatch GetProxyTagMatch(string message, IEnumerable potentials) { @@ -98,17 +99,40 @@ namespace PluralKit.Bot return await webhook.Channel.GetMessageAsync(messageId); } - public async Task HandleReactionAddedAsync(Cacheable message, ISocketMessageChannel channel, SocketReaction reaction) + public Task HandleReactionAddedAsync(Cacheable message, ISocketMessageChannel channel, SocketReaction reaction) { - // Make sure it's the right emoji (red X) - if (reaction.Emote.Name != "\u274C") return; + // Dispatch on emoji + switch (reaction.Emote.Name) + { + case "\u274C": // Red X + return HandleMessageDeletionByReaction(message, reaction.UserId); + case "\u2753": // Red question mark + case "\u2754": // White question mark + return HandleMessageQueryByReaction(message, reaction.UserId); + default: + return Task.CompletedTask; + } + } + private async Task HandleMessageQueryByReaction(Cacheable message, ulong userWhoReacted) + { + var user = await _client.GetUserAsync(userWhoReacted); + if (user == null) return; + + var msg = await _messageStorage.Get(message.Id); + if (msg == null) return; + + await user.SendMessageAsync(embed: await _embeds.CreateMessageInfoEmbed(msg)); + } + + public async Task HandleMessageDeletionByReaction(Cacheable message, ulong userWhoReacted) + { // Find the message in the database var storedMessage = await _messageStorage.Get(message.Id); if (storedMessage == null) return; // (if we can't, that's ok, no worries) // Make sure it's the actual sender of that message deleting the message - if (storedMessage.Message.Sender != reaction.UserId) return; + if (storedMessage.Message.Sender != userWhoReacted) return; try { // Then, fetch the Discord message and delete that