forked from Supositware/Haha-Yes
new tag system
This commit is contained in:
parent
54ed1d2e0e
commit
e4a5550885
4 changed files with 17 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,3 +8,4 @@ video.mp4
|
|||
json/autoresponse.json
|
||||
json/blacklist.json
|
||||
json/customresponse.json
|
||||
tag/*
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
6
index.js
6
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")) {
|
||||
|
|
Loading…
Reference in a new issue