diff --git a/.gitignore b/.gitignore index 2a07fac8..978b28a7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ node_modules\ video.mp4 json/autoresponse.json json/blacklist.json +json/customresponse.json diff --git a/commands/admin/customresponse.js b/commands/admin/customresponse.js new file mode 100644 index 00000000..b06e11f6 --- /dev/null +++ b/commands/admin/customresponse.js @@ -0,0 +1,52 @@ +const { Command } = require('discord.js-commando'); +const blacklist = require('../../json/blacklist.json'); +const fs = require('fs'); +module.exports = class CustomResponseCommand extends Command { + constructor(client) { + super(client, { + name: 'customresponse', + group: 'admin', + memberName: 'customresponse', + userPermissions: ['ADMINISTRATOR'], + description: `Can disable autoresponse in the channel (you can add "ALL" like this "haha enable/disable all" to enable/disable in every channel (EXPERIMENTAL))`, + args: [ + { + key: 'trigger', + prompt: 'Disable or enable?', + type: 'string', + }, + { + key: 'response', + prompt: 'Disable or enable?', + type: 'string', + } + ] + }); + } + + async run(message, { trigger, response }) { + if(blacklist[message.author.id]) + return message.channel.send("You are blacklisted") + + trigger = trigger.toLowerCase(); + response = response.toLowerCase() + trigger = trigger.replace('--', ' ') + let customresponse = {} + let json = JSON.stringify(customresponse) + + fs.readFile('DiscordBot/json/customresponse.json', 'utf8', function readFileCallback(err, data){ + if (err){ + console.log(err); + } else { + customresponse = JSON.parse(data); //now it an object + customresponse [message.guild.id] = { 'text': trigger, 'response': response } + json = JSON.stringify(customresponse); //convert it back to json + fs.writeFile('DiscordBot/json/customresponse.json', json, 'utf8', function(err) { + if(err) { + return console.log(err); + } + })}}); + + return message.say(`autoresponse have been set`); + } +}; \ No newline at end of file diff --git a/index.js b/index.js index 4a51efad..97bf1b8c 100644 --- a/index.js +++ b/index.js @@ -92,10 +92,11 @@ client.registry message.react(reactObject[message_content]); } // auto respond to messages - else if(responseObject[message_content] || customresponse[message_content]) { + else if(responseObject[message_content] || customresponse[message.guild.id]['text'] == message_content) { var autoresponse = new SelfReloadJSON('DiscordBot/json/autoresponse.json'); if(autoresponse[message.channel.id] == 'enable') message.channel.send(responseObject[message_content]); + message.channel.send(customresponse[message.guild.id]['response']) // If it contain "like if" react with 👍 } else if (message_content.includes("like if")) { var autoresponse = new SelfReloadJSON('DiscordBot/json/autoresponse.json');