Haha-Yes/commands/utility/seetag.js

84 lines
2.9 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');
const os = require('os');
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',
2019-11-09 12:04:01 +01:00
clientPermissions: ['SEND_MESSAGES', 'EMBED_LINKS'],
2019-01-02 08:09:45 +01:00
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-11-19 17:27:46 +01:00
if (!tagList) return message.channel.send('Tag not found.');
2019-07-12 05:43:32 +02:00
this.client.users.fetch(tagList.dataValues.ownerID)
.then(user => {
const TagEmbed = new MessageEmbed()
2019-11-02 00:54:40 +01:00
.setColor(message.member.displayHexColor)
2019-07-12 05:43:32 +02:00
.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()
2019-11-02 00:54:40 +01:00
.setColor(message.member.displayHexColor)
2019-07-17 01:17:10 +02:00
.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-11-19 17:27:46 +01:00
if (!tagList[0]) return message.channel.send('This guild do not have any tag.');
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);
});
fs.writeFile(`${os.tmpdir()}/tagslist.txt`,JSON.stringify(tagArray, null, 2), function(err) {
2019-07-08 22:45:41 +02:00
if (err) return console.error(err);
return message.channel.send('Here are your tags', {files: [`${os.tmpdir()}/tagslist.txt`]});
2019-07-08 22:45:41 +02:00
});
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()
2019-11-02 00:54:40 +01:00
.setColor(message.member.displayHexColor)
2019-07-12 05:43:32 +02:00
.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;