Allow the blocking of command

This commit is contained in:
loicbersier 2020-03-18 02:28:29 +01:00
parent a811f8f749
commit f84b8e20d2
5 changed files with 110 additions and 0 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;
}
}
}

View file

@ -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');
}
};

11
models/commandblock.js Normal file
View file

@ -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;
};