1
0
Fork 0
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/utility/taglist.js

57 lines
1.6 KiB
JavaScript

const { Command } = require('discord-akairo');
const Tag = require('../../models').Tag;
const fs = require('fs');
class taglistCommand extends Command {
constructor() {
super('taglist', {
aliases: ['taglist', 'tags'],
category: 'utility',
channelRestriction: 'guild',
args: [
{
id: 'raw',
match: 'rest',
optional: true
},
{
id: 'list',
match: 'flag',
flag: '--list',
}
],
description: {
content: 'Show the list of tag for this server.',
usage: '',
examples: ['']
}
});
}
async exec(message, args) {
if (args.list) {
let tagList = await Tag.findAll({attributes: ['trigger'], where: {serverID: message.guild.id}});
const tagString = tagList.map(t => t.trigger).join(', ') || 'No tags set.';
return message.channel.send(`List of tags:\n${tagString}`, {code: true});
}
if (args.raw) {
let tagList = await Tag.findOne({attributes: ['trigger','response','ownerID'], where: {trigger: args.raw, serverID: message.guild.id}});
return message.channel.send(JSON.stringify(tagList, null, 2), {code: true});
} else {
let tagList = await Tag.findAll({attributes: ['trigger','response','ownerID'], where: {serverID: message.guild.id}});
let tagArray = [];
tagList.forEach(tag => {
tagArray.push(tag['dataValues']);
});
fs.writeFile('/tmp/tagslist.txt',JSON.stringify(tagArray, null, 2), function(err) {
if (err) return console.error(err);
return message.channel.send('Here are your tags', {files: ['/tmp/tagslist.txt']});
});
}
}
}
module.exports = taglistCommand;