Skip to content

Commit

Permalink
Add blacklistAdd, blacklistRemove events
Browse files Browse the repository at this point in the history
  • Loading branch information
zajrik committed Mar 10, 2017
1 parent 12042f3 commit c697929
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
49 changes: 35 additions & 14 deletions src/lib/bot/Bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,6 @@ export class Bot extends Client
this._guildStorageLoader.cleanGuilds(this._guildDataStorage, this._guildSettingStorage);
}

/**
* Emitted whenever a command is successfully called
* @memberof Bot
* @instance
* @event event:command
* @param {string} name Name of the called command
* @param {any[]} args Args passed to the called command
* @param {number} execTime Time command took to execute
* @param {external:Message} message Message that triggered the command
*/
public on(event: 'command', listener: (name: string, args: any[], execTime: number, message: Message) => void): this;

//#region Discord.js events

public on(event: 'channelCreate', listener: (channel: Channel) => void): this;
Expand Down Expand Up @@ -383,10 +371,43 @@ export class Bot extends Client
public on(event: 'userUpdate', listener: (oldUser: User, newUser: User) => void): this;
public on(event: 'voiceStateUpdate', listener: (oldMember: GuildMember, newMember: GuildMember) => void): this;
public on(event: 'warn', listener: (info: string) => void): this;

//#endregion

public on(event: 'command', listener: (name: string, args: any[], execTime: number, message: Message) => void): this;
public on(event: 'blacklistAdd', listener: (user: User, global: boolean) => void): this;
public on(event: 'blacklistRemove', listener: (user: User, global: boolean) => void): this;

/**
* Emitted whenever a command is successfully called
* @memberof Bot
* @instance
* @event event:command
* @param {string} name Name of the called command
* @param {any[]} args Args passed to the called command
* @param {number} execTime Time command took to execute
* @param {external:Message} message Message that triggered the command
*/

/**
* Emitted whenever a user is blacklisted
* @memberof Bot
* @instance
* @event event:blacklistAdd
* @param {User} user User who was blacklisted
* @param {boolean} global Whether or not blacklisting is global
*/

/**
* Emitted whenever a user is removed from the blacklist
* @memberof Bot
* @instance
* @event event:blacklistRemove
* @param {User} user User who was removed
* @param {boolean} global Whether or not removal is global
*/
public on(event: string, listener: Function): this
{
return super.on(event, listener);
}

//#endregion
}
2 changes: 2 additions & 0 deletions src/lib/command/base/blacklist/Blacklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default class Blacklist extends Command<Bot>
return message.channel.send('That user is already globally blacklisted.');

this.bot.storage.setItem(`blacklist/${user.id}`, true);
this.bot.emit('blacklistAdd', user, true);
return message.channel.send(`Added ${user.username}#${user.discriminator} to the global blacklist.`);
}

Expand All @@ -49,6 +50,7 @@ export default class Blacklist extends Command<Bot>
return message.channel.send('That user is already blacklisted in this server.');

message.guild.storage.setSetting(`blacklist/${user.id}`, true);
this.bot.emit('blacklistAdd', user, false);
return message.channel.send(`Added ${user.username}#${user.discriminator} to this server's blacklist.`);
}
}
2 changes: 2 additions & 0 deletions src/lib/command/base/blacklist/Whitelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ export default class Whitelist extends Command<Bot>
return message.channel.send('That user is not currently globally blacklisted.');

this.bot.storage.removeItem(`blacklist/${user.id}`);
this.bot.emit('blacklistRemove', user, true);
return message.channel.send(`Removed ${user.username}#${user.discriminator} from the global blacklist.`);
}

if (!message.guild.storage.settingExists(`blacklist/${user.id}`))
return message.channel.send('That user is not currently blacklisted in this server.');

message.guild.storage.removeSetting(`blacklist/${user.id}`);
this.bot.emit('blacklistRemove', user, false);
return message.channel.send(`Removed ${user.username}#${user.discriminator} from this server's blacklist.`);
}
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"es7"
],
"declaration": true,
"sourceMap": true
"sourceMap": true,
"removeComments": false
},
"exclude": [
"node_modules",
Expand Down

0 comments on commit c697929

Please sign in to comment.