You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Haha-Yes/commands/admin/tag.js

67 lines
2.1 KiB
JavaScript

const { Command } = require('discord-akairo');
5 years ago
const fs = require('fs');
5 years ago
class TagCommand extends Command {
constructor() {
super('tag', {
aliases: ['tag'],
category: 'admin',
split: 'quoted',
5 years ago
args: [
{
id: "trigger",
type: "string"
5 years ago
},
{
id: "response",
type: "string"
5 years ago
}
],
channelRestriction: 'guild',
description: {
content: 'Create custom autoresponse',
usage: '[trigger] [response]',
examples: ['"do you know da wea" "Fuck off dead meme"']
}
5 years ago
});
}
async exec(message, args) {
let trigger = args.trigger;
let response = args.response;
5 years ago
trigger = trigger.toLowerCase();
do {
trigger = trigger.replace('--', ' ');
} while (trigger.includes('--'))
5 years ago
let customresponse = {};
let json = JSON.stringify(customresponse);
5 years ago
fs.readFile(`./tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data) {
if (err) {
fs.writeFile(`./tag/${message.guild.id}.json`, `{"${trigger}":"${response}"}`, function (err) {
if (err) {
fs.close();
console.log(err);
}
})
} else {
5 years ago
customresponse = JSON.parse(data); //now it an object
customresponse[trigger] = response
5 years ago
json = JSON.stringify(customresponse); //convert it back to json
fs.writeFile(`./tag/${message.guild.id}.json`, json, 'utf8', function (err) {
if (err) {
fs.close();
5 years ago
return console.log(err);
}
})
}
});
fs.close();
return message.channel.send(`autoresponse have been set to ${trigger} : ${response}`);
}
}
module.exports = TagCommand;