Skip to content
This repository has been archived by the owner on Aug 28, 2020. It is now read-only.

Commit

Permalink
Monitor.ignoreOthers (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdistin authored Nov 17, 2017
1 parent de560a1 commit 12616ee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/lib/structures/Monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Monitor {
* @property {boolean} [enabled=true] Whether the monitor is enabled
* @property {boolean} [ignoreBots=true] Whether the monitor ignores bots or not
* @property {boolean} [ignoreSelf=true] Whether the monitor ignores itself or not
* @property {boolean} [ignoreOthers=true] Whether the monitor ignores others or not
*/

/**
Expand Down Expand Up @@ -79,6 +80,13 @@ class Monitor {
* @type {boolean}
*/
this.ignoreSelf = 'ignoreSelf' in options ? options.ignoreSelf : true;

/**
* Whether the monitor ignores others or not
* @since 0.4.0
* @type {boolean}
*/
this.ignoreOthers = 'ignoreOthers' in options ? options.ignoreOthers : true;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/lib/structures/MonitorStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ class MonitorStore extends Collection {
* @param {external:Message} msg The message object from Discord.js
*/
run(msg) {
for (const monit of this.values()) if (monit.enabled && !(monit.ignoreBots && msg.author.bot) && !(monit.ignoreSelf && this.client.user === msg.author)) monit.run(msg);
for (const monit of this.values()) {
if (monit.enabled && !(monit.ignoreBots && msg.author.bot) && !(monit.ignoreSelf && this.client.user === msg.author) && !(monit.ignoreOthers && this.client.user !== msg.author)) monit.run(msg);
}
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/monitors/commandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ module.exports = class extends Monitor {
}

async run(msg) {
// Ignore other users if selfbot
if (!this.client.user.bot && msg.author.id !== this.client.user.id) return;
if (this.client.user.bot && msg.guild && !msg.guild.me) await msg.guild.members.fetch(this.client.user);
if (msg.guild && !msg.channel.permissionsFor(msg.guild.me).has('SEND_MESSAGES')) return;
const { command, prefix, prefixLength } = this.parseCommand(msg);
Expand Down Expand Up @@ -115,6 +113,7 @@ module.exports = class extends Monitor {

init() {
this.ignoreSelf = this.client.user.bot;
this.ignoreOthers = !this.client.user.bot;
this.prefixMention = new RegExp(`^<@!?${this.client.user.id}>`);
this.prefixMentionLength = this.client.user.id.length + 3;
}
Expand Down

0 comments on commit 12616ee

Please # to comment.