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

64 lines
1.5 KiB
JavaScript

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