-
Notifications
You must be signed in to change notification settings - Fork 293
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
Mentioning by guild nickname #147
Conversation
Use per server nickname instead of username.
Not tested yet since I'm not on my development machine
I should consider using a regex at this point... but hotfix
# Conflicts: # lib/bot.js # test/bot.test.js # test/stubs/discord-stub.js
Test to make sure you can't mention someone by username if their nickname differs
if (userDetails) { | ||
return userDetails.nickname || user.username; | ||
} | ||
return user.username; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check if the last line is actually ever reachable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is reached when sent by a webhook. Looks like it resolves #146
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, looks great! Had one small comment, looks good to go other than that.
if (user) { | ||
const serverUser = guild.members.find('id', user.id); | ||
if (serverUser.nickname && serverUser.nickname !== search) { | ||
// User has a guild nickname which is different from the search query |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but maybe it wouldn't be a terrible idea to just let people be highlighted by usernames as well?
Nonetheless, I think this could be refactored slightly by returning early instead. Example:
const nickUser = guild.members.find('nickname', search);
if (nickUser) {
return nickUser;
}
const user = this.discord.users.find('username', search);
if (user && guild.members.find('id').nickname === search) {
return user;
}
return match;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ekmartin I'm not sure that's a good idea. The people on IRC would be unable to see what the usernames of users on Discord are, and could possibly even inadvertently mention someone they weren't trying to mention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to change this refactor around a bit so it still works for people without nicknames.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't guild.members.find('id').nickname
just be null/undefined for users without nicknames? If so you'd just be comparing search
to that anyway, which would never be true since search is the match from your regex - right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ekmartin If user found by username and nickname = null it means the "visible nickname" is a match and should return true.
|
||
it('should not convert username mentions from IRC if nickname differs', function () { | ||
const testUser = new discord.User(this.bot.discord, { username: 'testuser', id: '123', nickname: 'somenickname' }); | ||
this.findUserStub.withArgs('username', testUser.username).returns(testUser); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice sinon usage!
if (userDetails) { | ||
return userDetails.nickname || user.username; | ||
} | ||
return user.username; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
I've added you as a collaborator @DarkSpyro003 - thanks for the help :) |
resolves issue #137