Raku / whateverable

🤖 Different IRC bots that operate on a bunch of prebuilt Rakudo versions
https://gist.github.com/Whateverable
GNU Affero General Public License v3.0
18 stars 14 forks source link

Improve Tellable's .seen normalization on startup #384

Closed AlexDaniel closed 2 years ago

AlexDaniel commented 2 years ago

Tellable stores a dict of all latest messages by all users that it has seen. However, the keys in that dict are not exact nicknames. Instead, they are intentionally mangled simplified versions of nicknames. The goal of the normalization is to allow users to change their nicknames slightly and still receive messages, and have .seen that DWIMs. AlexDaniel, AlexDaniel11, alexdaniel_, etc. are all treated the same by Tellable, that's what makes this bot so nice. 😌

Now, when the bot starts up, it could be that the file was created with old rules, or the file was recovered from something that didn't follow the same rules. For that reason the code renormalizes the entire seen and tell files and saves them back. However, now that I looked at the code again, I realized that there is a flaw. If two nicknames get normalized to the same value, it should pick the latest message and discard the old one. However, the code was just keeping one random message instead of taking the timestamp into account. This commit fixes that.

AlexDaniel commented 2 years ago

To be clear, .tell was not broken the same way .seen was. The renormalization for .tell merges lists of all messages, so the user will receive all messages (and not just messages for the latest nick), which is correct and good. There's perhaps a question of order in which the messages should be stored (and sent), but actually this renormalization only runs once in a while – if normalizations rules change, or if the file is created by parsing irc logs, etc. – this happens once in a few years, so the order is hardly a problem in my opinion :)