-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve IRC → Discord mentions for non-word characters and partial word matches #273
Conversation
7666431
to
9faa90b
Compare
(rebased onto #272) |
9faa90b
to
84ea646
Compare
I'm running this on my server. "Partial matching" is not the right description for "match by prefix". For example, I'm "qaisjp".
In general though this is a great commit. |
I phrased it that way because Thanks. |
Hmm that's true. In my mind I was thinking that "user input" partially matches "real nickname". I guess you're saying "real nickname" partially matches "user input"? |
Yeah. There's a partial match, in the "haystack" of the user input, of the "needle" of the actual username/nickname. |
84ea646
to
ef04c4e
Compare
(Rebased onto master and fixed a merge conflict.) |
6d2f99b
to
8cf07ab
Compare
@ekmartin Do you have time to review this? I was just thinking it would be nice to cut a new release with the few recent updates, and was going to ask you about it, but since there have been some new features (well, the ignore feature, plus some changes in the upstream I mostly wonder this because, as far as I know, the current release uses an old version of It might also be worth regenerating the Edit: It looks like Travis is taking a while, and it might be due to something around |
Yeah - sorry about the delay. I'll set a reminder to get it done sometime this week. |
8cf07ab
to
cff6eee
Compare
Good work :) I think it'd be nice to pull out some of the functionality from |
Things seem to work fine in master! I'll get to making a changelog entry and minor version release. |
Okay, new version released! |
Previously, attempting to mention someone with non-
\w
characters in their name would fail. So if you're on a server with a lot of non-latin names, or one where users have mysterious symbols in their names to indicate something (an example could be 'Throne✶', with the '✶' representing that one is an admin) then IRC users would not properly be able to ping them, as it wasn't recognized as being a wordy character. (Fortunately, if the user in question has 'Throne3d' as their Discord username, that worked as a fallback, but it was non-obvious. Typing the symbol would also be hard but plausibly could be copied and pasted.)This builds on #272 (which standardizes the testing suite in ways that make this easier to test), adds case-insensitive username and nickname matching, matches all strings of characters that don't involve spaces or hash symbols instead of just
\w
ones, adds matching for mentions of the format@username#discriminator
, and will match partially – e.g., if there's a user "Throne" in the channel,@Thronetest
,@Throne's
and@Throne-won't-see-this
will all have the starting@Throne
matched and turned into a mention, as Discord does with usernames.The partial matching prefers longer matches first and foremost, case insensitively, and then prefers matches which have exact case. I couldn't find an easy method to compare case-insensitively across locales (it seems to require you list the locales you want to compare across), and I'm not sure what Discord does internally, so I uppercased them then compared (and have this in a separate function to make it easier to change later, if necessary).
There is, I think, duplicated logic, in that it checks for perfect non-partial matches first, but if that special casing were removed it should produce the same result (except with a bias towards exact case match, instead of what order the Collection uses behind the scenes), but I wasn't sure if there might be some sort of performance problem with large Discord servers so I thought it best to leave that there, at least for now.