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

65 lines
2.3 KiB
JavaScript

const { Command } = require('discord-akairo');
5 years ago
const Tag = require('../../models').Tag;
6 years ago
class TagCommand extends Command {
6 years ago
constructor() {
super('tag', {
aliases: ['tag'],
category: 'admin',
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
const tag = await Tag.findOne({where: {trigger: args.trigger, serverID: message.guild.id}});
6 years ago
5 years ago
if (!tag) {
5 years ago
const body = {trigger: args.trigger, response: args.response, ownerID: message.author.id, serverID: message.guild.id};
5 years ago
await Tag.create(body);
return message.channel.send(`tag have been set to ${args.trigger} : ${args.response}`);
5 years ago
} else {
message.channel.send('This tag already exist, do you want to update it? y/n');
const filter = m => m.content && m.author.id == message.author.id;
message.channel.awaitMessages(filter, {time: 5000, max: 1, errors: ['time'] })
5 years ago
.then(async messages => {
let messageContent = messages.map(messages => messages.content.tolowerCase());
if (messageContent == 'y' || messageContent == 'yes') {
const body = {trigger: args.trigger, response: args.response, ownerID: message.author.id, serverID: message.guild.id};
5 years ago
await Tag.update(body, {where: {trigger: args.trigger, serverID: message.guild.id}});
return message.channel.send(`tag have been set to ${args.trigger} : ${args.response}`);
} else {
return message.channel.send('Not updating.');
}
})
5 years ago
.catch(err => {
console.error(err);
return message.channel.send('Took too long to answer. didin\'t update anything.');
});
5 years ago
}
6 years ago
}
}
module.exports = TagCommand;