Haha-Yes/commands/utility/seetag.js

80 lines
2.6 KiB
JavaScript
Raw Normal View History

2018-12-30 01:20:24 +01:00
const { Command } = require('discord-akairo');
2019-07-08 22:45:41 +02:00
const Tag = require('../../models').Tag;
2018-12-30 02:14:43 +01:00
const fs = require('fs');
2019-07-12 05:43:32 +02:00
const { MessageEmbed } = require('discord.js');
2018-12-30 01:20:24 +01:00
2019-07-08 22:45:41 +02:00
2019-07-12 17:48:50 +02:00
class seetagCommand extends Command {
2019-01-02 08:09:45 +01:00
constructor() {
super('taglist', {
2019-07-12 17:48:50 +02:00
aliases: ['seetag', 'taglist', 'tags'],
2019-01-02 08:09:45 +01:00
category: 'utility',
channelRestriction: 'guild',
2019-02-10 14:57:39 +01:00
args: [
{
id: 'raw',
2019-07-08 22:45:41 +02:00
match: 'rest',
optional: true
2019-07-09 01:47:24 +02:00
},
{
2019-07-12 05:43:32 +02:00
id: 'all',
2019-07-09 01:47:24 +02:00
match: 'flag',
2019-07-12 05:43:32 +02:00
flag: '--all',
2019-02-10 14:57:39 +01:00
}
],
2019-01-02 08:09:45 +01:00
description: {
2019-07-17 01:17:10 +02:00
content: 'Show the list of tag for this server. --all to get a txt file with info about every tag on the server',
usage: '[name of tag]',
2019-01-02 08:09:45 +01:00
examples: ['']
}
});
}
2018-12-07 01:45:40 +01:00
2019-02-10 14:57:39 +01:00
async exec(message, args) {
2019-07-08 22:45:41 +02:00
if (args.raw) {
let tagList = await Tag.findOne({attributes: ['trigger','response','ownerID'], where: {trigger: args.raw, serverID: message.guild.id}});
2019-07-12 05:43:32 +02:00
this.client.users.fetch(tagList.dataValues.ownerID)
.then(user => {
const TagEmbed = new MessageEmbed()
.setColor('#ff9900')
.setTitle(message.guild.name)
.addField('Trigger:', tagList['dataValues']['trigger'])
.addField('Response:', tagList['dataValues']['response'])
2019-07-12 05:51:00 +02:00
.addField('Creator:', `${user.username}#${user.discriminator} (${user.id})`);
2019-07-12 05:43:32 +02:00
2019-07-17 01:17:10 +02:00
return message.channel.send(TagEmbed);
})
.catch(() => {
const TagEmbed = new MessageEmbed()
.setColor('#ff9900')
.setTitle(message.guild.name)
.addField('Trigger:', tagList['dataValues']['trigger'])
.addField('Response:', tagList['dataValues']['response'])
.addField('Creator:', 'No user info.');
2019-07-12 05:43:32 +02:00
return message.channel.send(TagEmbed);
});
} else if (args.all) {
2019-07-08 22:45:41 +02:00
let tagList = await Tag.findAll({attributes: ['trigger','response','ownerID'], where: {serverID: message.guild.id}});
2019-07-12 05:43:32 +02:00
var tagArray = [];
2019-07-08 22:45:41 +02:00
tagList.forEach(tag => {
2019-07-12 05:43:32 +02:00
tagArray.push(tag.dataValues);
});
2019-07-08 22:45:41 +02:00
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']});
});
2019-07-12 05:43:32 +02:00
} 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);
2019-07-08 22:45:41 +02:00
}
2019-01-02 08:09:45 +01:00
}
2018-12-30 01:20:24 +01:00
}
2019-07-12 17:48:50 +02:00
module.exports = seetagCommand;