forked from Supositware/Haha-Yes
custom response per server
This commit is contained in:
parent
20c83db125
commit
d0343d7b19
3 changed files with 55 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@ node_modules\
|
||||||
video.mp4
|
video.mp4
|
||||||
json/autoresponse.json
|
json/autoresponse.json
|
||||||
json/blacklist.json
|
json/blacklist.json
|
||||||
|
json/customresponse.json
|
||||||
|
|
52
commands/admin/customresponse.js
Normal file
52
commands/admin/customresponse.js
Normal file
|
@ -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`);
|
||||||
|
}
|
||||||
|
};
|
3
index.js
3
index.js
|
@ -92,10 +92,11 @@ client.registry
|
||||||
message.react(reactObject[message_content]);
|
message.react(reactObject[message_content]);
|
||||||
}
|
}
|
||||||
// auto respond to messages
|
// 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');
|
var autoresponse = new SelfReloadJSON('DiscordBot/json/autoresponse.json');
|
||||||
if(autoresponse[message.channel.id] == 'enable')
|
if(autoresponse[message.channel.id] == 'enable')
|
||||||
message.channel.send(responseObject[message_content]);
|
message.channel.send(responseObject[message_content]);
|
||||||
|
message.channel.send(customresponse[message.guild.id]['response'])
|
||||||
// If it contain "like if" react with 👍
|
// If it contain "like if" react with 👍
|
||||||
} else if (message_content.includes("like if")) {
|
} else if (message_content.includes("like if")) {
|
||||||
var autoresponse = new SelfReloadJSON('DiscordBot/json/autoresponse.json');
|
var autoresponse = new SelfReloadJSON('DiscordBot/json/autoresponse.json');
|
||||||
|
|
Loading…
Reference in a new issue