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

72 lines
1.9 KiB
JavaScript

const { Command } = require('discord-akairo');
6 years ago
const fs = require('fs');
6 years ago
class TagCommand extends Command {
6 years ago
constructor() {
super('tag', {
aliases: ['tag'],
category: 'admin',
split: 'quoted',
userPermissions: ['MANAGE_MESSAGES'],
6 years ago
args: [
{
id: 'trigger',
5 years ago
type: 'string',
prompt: {
start: 'What word or sentence should trigger it?',
}
6 years ago
},
{
id: 'response',
type: 'string',
5 years ago
match: 'rest',
prompt: {
start: 'What word or sentence should the response be?',
}
6 years ago
}
],
channelRestriction: 'guild',
description: {
content: 'Create custom autoresponse [Click here to see the complete list of "tag"](https://cdn.discordapp.com/attachments/502198809355354133/561043193949585418/unknown.png) (Need "" if the trigger contains spaces)',
6 years ago
usage: '[trigger] [response]',
examples: ['"do you know da wea" Fuck off dead meme', 'hello Hello [author], how are you today?']
6 years ago
}
});
}
6 years ago
6 years ago
async exec(message, args) {
5 years ago
if (args.trigger == null || args.response == null) return;
6 years ago
let trigger = args.trigger;
let response = args.response;
6 years ago
6 years ago
trigger = trigger.toLowerCase();
6 years ago
6 years ago
let customresponse = {};
let json = JSON.stringify(customresponse);
6 years ago
6 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) {
6 years ago
if (err) {
6 years ago
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) {
return console.log(err);
}
});
}
});
6 years ago
return message.channel.send(`autoresponse have been set to ${trigger} : ${response}`);
}
}
module.exports = TagCommand;