Changed how this command work
This commit is contained in:
parent
0fc2db5074
commit
ae15265af6
1 changed files with 27 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
||||||
const { Command } = require('discord-akairo');
|
const { Command } = require('discord-akairo');
|
||||||
const Tag = require('../../models').Tag;
|
const Tag = require('../../models').Tag;
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const { MessageEmbed } = require('discord.js');
|
||||||
|
|
||||||
|
|
||||||
class taglistCommand extends Command {
|
class taglistCommand extends Command {
|
||||||
|
@ -16,9 +17,9 @@ class taglistCommand extends Command {
|
||||||
optional: true
|
optional: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'list',
|
id: 'all',
|
||||||
match: 'flag',
|
match: 'flag',
|
||||||
flag: '--list',
|
flag: '--all',
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
description: {
|
description: {
|
||||||
|
@ -30,28 +31,40 @@ class taglistCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
async exec(message, args) {
|
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) {
|
if (args.raw) {
|
||||||
let tagList = await Tag.findOne({attributes: ['trigger','response','ownerID'], where: {trigger: args.raw, serverID: message.guild.id}});
|
let tagList = await Tag.findOne({attributes: ['trigger','response','ownerID'], where: {trigger: args.raw, serverID: message.guild.id}});
|
||||||
|
this.client.users.fetch(tagList.dataValues.ownerID)
|
||||||
return message.channel.send(JSON.stringify(tagList, null, 2), {code: true});
|
.then(user => {
|
||||||
} else {
|
const TagEmbed = new MessageEmbed()
|
||||||
|
.setColor('#ff9900')
|
||||||
|
.setTitle(message.guild.name)
|
||||||
|
.addField('Trigger:', tagList['dataValues']['trigger'])
|
||||||
|
.addField('Response:', tagList['dataValues']['response'])
|
||||||
|
.addField('Owner:', `${user.username}#${user.discriminator} (${user.id})`);
|
||||||
|
|
||||||
|
return message.channel.send(TagEmbed);
|
||||||
|
});
|
||||||
|
} else if (args.all) {
|
||||||
let tagList = await Tag.findAll({attributes: ['trigger','response','ownerID'], where: {serverID: message.guild.id}});
|
let tagList = await Tag.findAll({attributes: ['trigger','response','ownerID'], where: {serverID: message.guild.id}});
|
||||||
let tagArray = [];
|
var tagArray = [];
|
||||||
tagList.forEach(tag => {
|
tagList.forEach(tag => {
|
||||||
tagArray.push(tag['dataValues']);
|
tagArray.push(tag.dataValues);
|
||||||
});
|
});
|
||||||
fs.writeFile('/tmp/tagslist.txt',JSON.stringify(tagArray, null, 2), function(err) {
|
fs.writeFile('/tmp/tagslist.txt',JSON.stringify(tagArray, null, 2), function(err) {
|
||||||
if (err) return console.error(err);
|
if (err) return console.error(err);
|
||||||
return message.channel.send('Here are your tags', {files: ['/tmp/tagslist.txt']});
|
return message.channel.send('Here are your tags', {files: ['/tmp/tagslist.txt']});
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
let tagList = await Tag.findAll({attributes: ['trigger'], where: {serverID: message.guild.id}});
|
||||||
|
const tagString = tagList.map(t => t.trigger).join(', ') || 'No tags set.';
|
||||||
|
const TagEmbed = new MessageEmbed()
|
||||||
|
.setColor('#ff9900')
|
||||||
|
.setTitle('List of tags')
|
||||||
|
.setDescription(tagString)
|
||||||
|
.setFooter('Use this command with the name of the tag to see more info about it!');
|
||||||
|
|
||||||
|
return message.channel.send(TagEmbed);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = taglistCommand;
|
module.exports = taglistCommand;
|
Loading…
Reference in a new issue