diff --git a/Izzy-Moonbot/EventListeners/MessageListener.cs b/Izzy-Moonbot/EventListeners/MessageListener.cs index 159c7bad..03049c24 100644 --- a/Izzy-Moonbot/EventListeners/MessageListener.cs +++ b/Izzy-Moonbot/EventListeners/MessageListener.cs @@ -36,22 +36,27 @@ private async Task ProcessMessageReceived( IIzzyMessage message, IIzzyClient client) { - // RecentMessages updating - var author = message.Author; - if (!_state.RecentMessages.ContainsKey(author.Id)) - _state.RecentMessages[author.Id] = new(); - var recentMessages = _state.RecentMessages[author.Id]; - recentMessages.Add((message.Timestamp, message.Content)); - if (recentMessages.Count > 5) + // RecentMessages updating + + if (message.Channel.Id != _config.ModChannel) { - var secondsUntilIrrelevant = _config.SpamPressureDecay * (_config.SpamMaxPressure / _config.SpamBasePressure); - while ( - (DateTimeOffset.UtcNow - recentMessages[0].Item1).TotalSeconds > secondsUntilIrrelevant && - recentMessages.Count > 5 - ) { - recentMessages.RemoveAt(0); + if (!_state.RecentMessages.ContainsKey(author.Id)) + _state.RecentMessages[author.Id] = new(); + var recentMessages = _state.RecentMessages[author.Id]; + recentMessages.Add((message.GetJumpUrl(), message.Timestamp, message.Content)); + + if (recentMessages.Count > 5) + { + var secondsUntilIrrelevant = _config.SpamPressureDecay * (_config.SpamMaxPressure / _config.SpamBasePressure); + while ( + (DateTimeOffset.UtcNow - recentMessages[0].Item2).TotalSeconds > secondsUntilIrrelevant && + recentMessages.Count > 5 + ) + { + recentMessages.RemoveAt(0); + } } } diff --git a/Izzy-Moonbot/Modules/ModMiscModule.cs b/Izzy-Moonbot/Modules/ModMiscModule.cs index aa85a241..b1b19e12 100644 --- a/Izzy-Moonbot/Modules/ModMiscModule.cs +++ b/Izzy-Moonbot/Modules/ModMiscModule.cs @@ -854,7 +854,14 @@ public async Task SetBannnerCommandAsync([Remainder] string url = "") [Command("recentmessages")] [Summary("Dump all of the recent messages Izzy has cached for a specific user.")] - [Remarks("Izzy caches at least 5 messages for each user, and will not throw away a message until it becomes irrelevant for spam pressure (see SpamPressureDecay, SpamMaxPressure and SpamBasePressure). Thus, this includes deleted messages that Izzy can't log in LogChannel because Discord doesn't produce a MessageDeleted event for them (e.g. deletions as part of a ban). Edits and deletes are ignored; only the original version of the message is cached. Restarting Izzy clears this cache.")] + [Remarks( + "This command is useful because some Discord message deletions (most importantly: banning with deletions) do not produce DeletedMessage events, and thus Izzy won't know to log them in LogChannel. This cache is also an implementation detail of some of Izzy's other systems.\n" + + "- Izzy will cache at least 5 messages for each user\n" + + "- Izzy will not throw away a message while it remains relevant for spam pressure calculations (see SpamPressureDecay, SpamMaxPressure and SpamBasePressure)\n" + + "- Edits and deletes are ignored; only the original version of the message is cached\n" + + "- Restarting Izzy clears this cache\n" + + "- Messages in `ModChannel` are ignored" + )] [RequireContext(ContextType.Guild)] [ModCommand(Group = "Permissions")] [DevCommand(Group = "Permissions")] @@ -873,13 +880,15 @@ public async Task RecentMessagesCommandAsync([Remainder] string user = "") !_state.RecentMessages.TryGetValue((ulong)userId, out var recentMessages) || recentMessages.Count == 0 ) { - await ReplyAsync($"I haven't seen any messages from <@{userId}> since my last restart. Sorry."); + await ReplyAsync($"I haven't seen any messages from <@{userId}> since my last restart. Sorry.", allowedMentions: AllowedMentions.None); return; } - await ReplyAsync($"These are all the recent messages (without edits or deletions) I have cached from <@{userId}>:\n" + + await ReplyAsync( + $"These are all the recent messages (without edits or deletions) I have cached from <@{userId}>:\n" + "\n" + - String.Join("\n", recentMessages.Select(rm => $"[] {rm.Item2}")) + String.Join("\n", recentMessages.Select(rm => $"[{rm.Item1} ] {rm.Item3}")), + allowedMentions: AllowedMentions.None ); } } diff --git a/Izzy-Moonbot/Settings/TransientState.cs b/Izzy-Moonbot/Settings/TransientState.cs index caa21833..584e1dd7 100644 --- a/Izzy-Moonbot/Settings/TransientState.cs +++ b/Izzy-Moonbot/Settings/TransientState.cs @@ -18,5 +18,6 @@ public class TransientState // RaidService public List RecentJoins = new(); - public Dictionary> RecentMessages = new(); + // (string, DateTimeOffset, string) = (jump URL, timestamp, content) + public Dictionary> RecentMessages = new(); }