-
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
Add ignore #225
Add ignore #225
Conversation
I don't suppose you can add tests for this? (It doesn't seem to have any at present, and while it seems very straightforward, it would be useful to have tests to make sure this functionality works as expected and doesn't break in the future.) Edit: Also it doesn't look like it'll ignore these nicks for the |
I'm not much of a js person nor can I see any tests to add. I'll gladly add them if you give me a hand :P |
Sinon chai seems to be the test library in use (which I hadn't touched before I submitted PRs to here, like 4 weeks ago?). Suggested tests would be to add example configs into the bot, trigger the event (or the method) with an author who should be ignored (and maybe an author who should not be ignored), and ensure that only the one who shouldn't be ignored gets through. In
and for the IRC → Discord side of things:
(I pulled your branch and tried these on it, and they pass and I think should work as expected.) Your code won't, I don't think, ignore Discord messages from ignored nicks, which may be confusing from the name of the config – I'd suggest either adding that (and adding a test for it, and in that case the Once you've added the feature for ignoring join/parts, tests could be added for that in |
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.
Bump about tests.
Not sure on the protocol here but I'd like to see this feature make it in. Does anyone mind if i make the requested changes and resubmit this? Don't know what the protocol is here. |
Sorry, completely forgot about this, way too much work... I'll try to get it done tomorrow. It is a relatively basic feature so tests do seem unnecessary IMHO but I'll get them in :) |
Or I'll get them in before I go to sleep :P |
The tests are mostly so that if the whole thing gets restructured later in some other pull request we don't somehow accidentally remove this functionality. Instead of just ensuring the basic code works as it's intended to at the time of implementation (which it seems it should, on inspection, which is why I otherwise accept the PR), it's ensuring future code doesn't screw anything up. I did suggest doing messages from non-bot users and ensuring those come through properly despite ignoring bots (that is, ensuring at least cursorily that non-bot users aren't filtered out when ignoring bots), but it doesn't seem all that necessary. Thanks for the pull request! @ekmartin if this looks okay with you I think it's good to go. |
hey no worries guys, was just offering my help. glad to see it it got worked out. |
Added tests for the other case but maybe should check the exact message getting through too :/ Feel free to merge with or without the last commit. |
Could you rebase this onto master? There are some conflicts which need to be resolved and I also expect it'll fix the problem with the coverage (presumably it's complaining because this is a slightly outdated branch). |
anyone still working on this? I could fork and apply the required changes on top, if any is needed |
Well this is done, I even rebased it :P |
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.
Thanks for adding tests - just a few small comments.
@@ -36,6 +36,8 @@ class Bot { | |||
this.channels = _.values(options.channelMapping); | |||
this.ircStatusNotices = options.ircStatusNotices; | |||
this.announceSelfJoin = options.announceSelfJoin; | |||
this.ignoreBots = options.ignoreBots; | |||
this.ignoreIrcNicks = options.ignoreIrcNicks || []; |
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.
Should this support both IRC and Discord? I.e. ignore: { discord: [], irc: [] }
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.
Well I needed it for one way. Thought about adding it to Discord->IRC as well but Discord has many ways of identifying a user, I just couldn't choose which one to use.
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.
For the Discord ignore I'd expect to use something that's unlikely to change – either username#discriminator
or username
. Maybe match on those?
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.
Userid would be the most watertight ignore method, no?
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.
Oh, yeah, it could be a better idea since it doesn't change. It's less readily accessible, though, which might make username#discriminator
better, especially since usernames and discriminators don't, I think, change much? (I'd go about getting the ID by either putting Discord in dev mode or using \@Username
to grab the ID from the escaped mention, both of which seem more awkward than username#discriminator
.)
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.
Well it depends for what the ignore would be used the most, if it's used to prevent some bots to go through username#separator would be fine. But if it's to prevent some user to flood and kicking/banning/mute isn't option for some reason, he can just switch discord username to circumvent the ignore.
In both cases I don't think the getting userid part would be too complicated, most people running servers and bots already have dev mode on all the time.
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'm unclear where such a circumstance would arise? I agree that if such a situation did occur then user ID would be better, but don't expect it'd occur enough that it'd outweigh the added (minor) ease from using username#discriminator
.
I mean, not that there's much difference between the two, so I'm mostly of the opinion "pick at least one of these" here.
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 think a plain snowflake id would be best. The bot owner can right click a user and choose "copy ID" to get the ID (if they can spend the time to set this up and have a Discord app, then they can enable dev mode in the client)
lib/bot.js
Outdated
@@ -131,6 +133,7 @@ class Bot { | |||
|
|||
this.ircClient.on('nick', (oldNick, newNick, channels) => { | |||
if (!this.ircStatusNotices) return; | |||
if (this.ignoreIrcNicks.indexOf(oldNick) !== -1) return; |
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.ignoreIrcNicks.includes(oldNick)
lib/bot.js
Outdated
@@ -148,6 +151,7 @@ class Bot { | |||
this.ircClient.on('join', (channelName, nick) => { | |||
logger.debug('Received join:', channelName, nick); | |||
if (!this.ircStatusNotices) return; | |||
if (this.ignoreIrcNicks.indexOf(nick) !== -1) return; |
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.
includes
lib/bot.js
Outdated
@@ -159,6 +163,7 @@ class Bot { | |||
this.ircClient.on('part', (channelName, nick, reason) => { | |||
logger.debug('Received part:', channelName, nick, reason); | |||
if (!this.ircStatusNotices) return; | |||
if (this.ignoreIrcNicks.indexOf(nick) !== -1) return; |
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.
includes
lib/bot.js
Outdated
@@ -177,6 +182,7 @@ class Bot { | |||
this.ircClient.on('quit', (nick, reason, channels) => { | |||
logger.debug('Received quit:', nick, channels); | |||
if (!this.ircStatusNotices || nick === this.ircClient.nick) return; | |||
if (this.ignoreIrcNicks.indexOf(nick) !== -1) return; |
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.
includes
test/bot-events.test.js
Outdated
bot.ircClient.emit('names', channel, { [bot.nickname]: '' }); | ||
|
||
const nick = 'ignored'; | ||
const altnick = 'notignored'; |
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.
altNick
test/bot.test.js
Outdated
this.bot.connect(); | ||
|
||
const guild = createGuildStub(); | ||
const botmsg = { |
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.
botMessage
test/bot.test.js
Outdated
guild | ||
}; | ||
|
||
const normalmsg = { |
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.
normalMessage
Sorry about the slow answer here - was skeptical of adding yet another couple config options, but sounds like people find it helpful so let's get it in. |
Any chance of this making it into master any time soon? I've applied the changes here locally to get this functionality but i'd like to see it make it into a release |
I'm happy to help but i'm not sure where things are at with this PR |
Just needs a config option to do filtering for Discord->IRC as well. I don't have time to do this right now. |
Small feature I added to use with our development channel. We have github hooks on both sides.