From e4a5550885fab922db24cea3b545ac75c7a1b961 Mon Sep 17 00:00:00 2001 From: Loic Bersier Date: Thu, 6 Dec 2018 18:50:18 +0100 Subject: [PATCH] new tag system --- .gitignore | 1 + commands/utility/tag.js | 12 +++++++++--- commands/utility/{unstag.js => untag.js} | 8 ++++---- index.js | 6 +++--- 4 files changed, 17 insertions(+), 10 deletions(-) rename commands/utility/{unstag.js => untag.js} (80%) diff --git a/.gitignore b/.gitignore index 978b28a7..d0b56d42 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ video.mp4 json/autoresponse.json json/blacklist.json json/customresponse.json +tag/* diff --git a/commands/utility/tag.js b/commands/utility/tag.js index c413abbd..a001ead9 100644 --- a/commands/utility/tag.js +++ b/commands/utility/tag.js @@ -38,14 +38,20 @@ module.exports = class CustomResponseCommand extends Command { let json = JSON.stringify(customresponse) - fs.readFile('DiscordBot/json/customresponse.json', 'utf8', function readFileCallback(err, data){ + fs.writeFile(`DiscordBot/tag/${message.guild.id}.json`, '{}', function (err) { + if (err){ + console.log(err); + } + }) + + fs.readFile(`DiscordBot/tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data){ if (err){ console.log(err); } else { customresponse = JSON.parse(data); //now it an object - customresponse [trigger] = { 'response': response, 'server': message.guild.id } + customresponse [trigger] = response json = JSON.stringify(customresponse); //convert it back to json - fs.writeFile('DiscordBot/json/customresponse.json', json, 'utf8', function(err) { + fs.writeFile(`DiscordBot/tag/${message.guild.id}.json`, json, 'utf8', function(err) { if(err) { return console.log(err); } diff --git a/commands/utility/unstag.js b/commands/utility/untag.js similarity index 80% rename from commands/utility/unstag.js rename to commands/utility/untag.js index d9b964a0..876cba51 100644 --- a/commands/utility/unstag.js +++ b/commands/utility/untag.js @@ -19,7 +19,7 @@ module.exports = class CustomResponseCommand extends Command { }); } - async run(message, { trigger, response }) { + async run(message, { trigger }) { if(blacklist[message.author.id]) return message.channel.send("You are blacklisted") @@ -29,14 +29,14 @@ module.exports = class CustomResponseCommand extends Command { let json = JSON.stringify(customresponse) - fs.readFile('DiscordBot/json/customresponse.json', 'utf8', function readFileCallback(err, data){ + fs.readFile(`DiscordBot/tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data){ if (err){ console.log(err); } else { customresponse = JSON.parse(data); //now it an object - customresponse [trigger] = { 'response': '', 'server': message.guild.id } + customresponse [trigger] = '' json = JSON.stringify(customresponse); //convert it back to json - fs.writeFile('DiscordBot/json/customresponse.json', json, 'utf8', function(err) { + fs.writeFile(`DiscordBot/tag/${message.guild.id}.json`, json, 'utf8', function(err) { if(err) { return console.log(err); } diff --git a/index.js b/index.js index 3a780d3b..b525ee26 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,6 @@ const responseObject = require("./json/reply.json"); const reactObject = require("./json/react.json"); const imgResponseObject = require("./json/imgreply.json"); const SelfReloadJSON = require('self-reload-json'); -var customresponse = new SelfReloadJSON('DiscordBot/json/customresponse.json'); // Prefix and ownerID and invite to support server const client = new CommandoClient({ commandPrefix: prefix, @@ -76,6 +75,8 @@ client.registry }); client.on("message", async (message) => { + var customresponse = new SelfReloadJSON(`DiscordBot/tag/${message.guild.id}.json`); + let message_content = message.content.toLowerCase(); // React to the message and send an auto response with it if (message.author.bot) return; { @@ -100,8 +101,7 @@ client.registry } else if(customresponse[message_content]) { var autoresponse = new SelfReloadJSON('DiscordBot/json/autoresponse.json'); if(autoresponse[message.channel.id] == 'enable') { - if(customresponse[message_content].server == message.guild.id) - message.channel.send(customresponse[message_content].response) + message.channel.send(customresponse[message_content]) } // If it contain "like if" react with 👍 } else if (message_content.includes("like if")) {