diff --git a/commands/admin/commandblock.js b/commands/admin/commandblock.js new file mode 100644 index 00000000..fe829696 --- /dev/null +++ b/commands/admin/commandblock.js @@ -0,0 +1,45 @@ +const { Command } = require('discord-akairo'); +const commandblock = require('../../models').commandBlock; + +class commandblockCommand extends Command { + constructor() { + super('commandblock', { + aliases: ['commandblock', 'blockcommand'], + category: 'admin', + args: [ + { + id: 'command', + type: 'command', + prompt: { + start: 'What command do you want to block?', + retry: 'Not a valid command, please try again' + } + } + ], + clientPermissions: ['SEND_MESSAGES'], + userPermissions: ['ADMINISTRATOR'], + channelRestriction: 'guild', + description: { + content: 'Block a command', + usage: '[command name]', + examples: ['owned'] + } + }); + } + + async exec(message, args) { + if (args.command.id == 'commandblock') return message.channel.send('Whoa there, i can\'t let you block this command or else how would you unblock it?'); + + const blocked = await commandblock.findOne({where: {serverID: message.guild.id}}); + + if (!blocked) { + const body = {serverID: message.guild.id, command: args.command.id}; + commandblock.create(body); + return message.channel.send(`Blocked command ${args.command.id}`); + } else { + commandblock.destroy({where: {serverID: message.guild.id, command: args.command.id}}); + return message.channel.send(`The command ${args.command.id} has been unblocked`); + } + } +} +module.exports = commandblockCommand; \ No newline at end of file diff --git a/event/inhibitors/commandBlock.js b/event/inhibitors/commandBlock.js new file mode 100644 index 00000000..16086523 --- /dev/null +++ b/event/inhibitors/commandBlock.js @@ -0,0 +1,19 @@ +const { Inhibitor } = require('discord-akairo'); +const commandblock = require('../../models').commandBlock; + +class commandblockInhibitor extends Inhibitor { + constructor() { + super('commandblock', { + reason: 'commandblock' + }); + } + + async exec(message, command) { + if (message.channel.type == 'dm') return false; + const blacklist = await commandblock.findOne({where: {serverID:message.guild.id, command: command.id}}); + + if (blacklist) return true; + } +} + +module.exports = commandblockInhibitor; \ No newline at end of file diff --git a/event/listeners/commandblocked.js b/event/listeners/commandblocked.js index e547d125..5da00fef 100644 --- a/event/listeners/commandblocked.js +++ b/event/listeners/commandblocked.js @@ -42,6 +42,11 @@ class CommandBlockedListener extends Listener { message.channel.send(Embed); message.guild.leave(); break; + case 'commandblock': + Embed.setTitle('Command blocked.'); + Embed.setDescription('The admins of this server blocked this command.'); + message.channel.send(Embed); + break; } } } diff --git a/migrations/20200318011556-create-command-block.js b/migrations/20200318011556-create-command-block.js new file mode 100644 index 00000000..dc94588f --- /dev/null +++ b/migrations/20200318011556-create-command-block.js @@ -0,0 +1,30 @@ +'use strict'; +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.createTable('commandBlocks', { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: Sequelize.INTEGER + }, + serverID: { + type: Sequelize.BIGINT + }, + command: { + type: Sequelize.STRING + }, + createdAt: { + allowNull: false, + type: Sequelize.DATE + }, + updatedAt: { + allowNull: false, + type: Sequelize.DATE + } + }); + }, + down: (queryInterface, Sequelize) => { + return queryInterface.dropTable('commandBlocks'); + } +}; \ No newline at end of file diff --git a/models/commandblock.js b/models/commandblock.js new file mode 100644 index 00000000..25409ed4 --- /dev/null +++ b/models/commandblock.js @@ -0,0 +1,11 @@ +'use strict'; +module.exports = (sequelize, DataTypes) => { + const commandBlock = sequelize.define('commandBlock', { + serverID: DataTypes.BIGINT, + command: DataTypes.STRING + }, {}); + commandBlock.associate = function(models) { + // associations can be defined here + }; + return commandBlock; +}; \ No newline at end of file