Auto response can be deactivated

This commit is contained in:
loicbersier 2018-10-19 23:39:42 +02:00
parent 05d036d6c5
commit fff134bbb8
2 changed files with 58 additions and 0 deletions

View file

@ -0,0 +1,47 @@
const { Command } = require('discord.js-commando');
const blacklist = require('../../json/blacklist.json');
const fs = require('fs');
const autoresponse = require('../../json/autoresponse.json')
module.exports = class sayCommand extends Command {
constructor(client) {
super(client, {
name: 'autoresponse',
group: 'admin',
memberName: 'autoresponse',
userPermissions: ['MANAGE_MESSAGES'],
description: `Repeat the text you send`,
args: [
{
key: 'text',
prompt: 'What do you want me to say',
type: 'string',
oneOf: ['disable', 'enable'],
}
]
});
}
async run(message, { text }) {
if(blacklist[message.author.id])
return message.channel.send("You are blacklisted")
let test = {}
let json = JSON.stringify(test)
fs.readFile('json/autoresponse.json', 'utf8', function readFileCallback(err, data){
if (err){
console.log(err);
} else {
test = JSON.parse(data); //now it an object
test [message.channel.id] = text
json = JSON.stringify(test); //convert it back to json
fs.writeFile('json/autoresponse.json', json, 'utf8', function(err) {
if(err) {
return console.log(err);
}
})}});
message.say(text);
}
};

View file

@ -5,6 +5,7 @@ const { token, prefix, statsChannel, ownerID, supportServer } = require('./confi
const responseObject = require("./json/reply.json");
const reactObject = require("./json/react.json");
const imgResponseObject = require("./json/imgreply.json");
const autoresponse = require("./json/autoresponse.json");
// Prefix and ownerID and invite to support server
const client = new CommandoClient({
@ -81,18 +82,28 @@ client.registry
if (message.author.bot) return; {
// Reply with images as attachement
if(imgResponseObject[message_content]) {
if(autoresponse[message.channel.id] == 'disable')
return message.channel.send('test')
message.channel.send({files: [imgResponseObject[message_content]]});
}
// React only to the messages
else if(reactObject[message_content]) {
if(autoresponse[message.channel.id] == 'disable')
return message.channel.send('test')
message.react(reactObject[message_content]);
}
// auto respond to messages
else if(responseObject[message_content]) {
if(autoresponse[message.channel.id] == 'disable')
return message.channel.send('test')
message.channel.send(responseObject[message_content]);
} else if (message_content.includes("like if")) {
if(autoresponse[message.channel.id] == 'disable')
return message.channel.send('test')
message.react("\u{1F44D}")
} else if (message_content.includes("jeff")) {
if(autoresponse[message.channel.id] == 'disable')
return message.channel.send('test')
message.react("496028845967802378")
}
}});