From fff134bbb8a881c2b1b260a18ee0952c623cbdb8 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Fri, 19 Oct 2018 23:39:42 +0200 Subject: [PATCH] Auto response can be deactivated --- commands/admin/autoresponse.js | 47 ++++++++++++++++++++++++++++++++++ index.js | 11 ++++++++ 2 files changed, 58 insertions(+) create mode 100644 commands/admin/autoresponse.js diff --git a/commands/admin/autoresponse.js b/commands/admin/autoresponse.js new file mode 100644 index 0000000..fe79b8b --- /dev/null +++ b/commands/admin/autoresponse.js @@ -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); + } +}; \ No newline at end of file diff --git a/index.js b/index.js index 83e5211..a59345b 100644 --- a/index.js +++ b/index.js @@ -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") } }});