Show tag
This commit is contained in:
parent
94b9e77437
commit
57f4c797e9
1 changed files with 18 additions and 41 deletions
|
@ -1,8 +1,8 @@
|
||||||
const { Command } = require('discord-akairo');
|
const { Command } = require('discord-akairo');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const Tag = require('../../models').Tag;
|
||||||
const reload = require('auto-reload');
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
|
|
||||||
class taglistCommand extends Command {
|
class taglistCommand extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super('taglist', {
|
super('taglist', {
|
||||||
|
@ -12,7 +12,8 @@ class taglistCommand extends Command {
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
id: 'raw',
|
id: 'raw',
|
||||||
type: 'string',
|
match: 'rest',
|
||||||
|
optional: true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
description: {
|
description: {
|
||||||
|
@ -24,46 +25,22 @@ class taglistCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
async exec(message, args) {
|
async exec(message, args) {
|
||||||
try {
|
if (args.raw) {
|
||||||
var customresponse = reload(`../../tag/${message.guild.id}.json`);
|
let tagList = await Tag.findOne({attributes: ['trigger','response','ownerID'], where: {trigger: args.raw, serverID: message.guild.id}});
|
||||||
var count = Object.keys(customresponse).length;
|
|
||||||
} catch (err) {
|
|
||||||
message.channel.send('An error has occured, do you have any tags on the server?');
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
await fs.readFile(`./tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data) {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
|
|
||||||
return;
|
return message.channel.send(JSON.stringify(tagList, null, 2), {code: true});
|
||||||
}
|
} else {
|
||||||
let json = JSON.parse(data);
|
let tagList = await Tag.findAll({attributes: ['trigger','response','ownerID'], where: {serverID: message.guild.id}});
|
||||||
if (args.raw) {
|
let tagArray = [];
|
||||||
const tagEmbed = new MessageEmbed()
|
tagList.forEach(tag => {
|
||||||
.setColor('#ff9900')
|
tagArray.push(tag['dataValues']);
|
||||||
.setTitle(args.raw)
|
|
||||||
.setDescription(json[args.raw]);
|
|
||||||
|
|
||||||
return message.channel.send(tagEmbed);
|
|
||||||
}
|
|
||||||
|
|
||||||
json = JSON.stringify(data);
|
|
||||||
json = json.replace(/[{}'\\]+/g, '');
|
|
||||||
json = json.replace(/,+/g, '\n');
|
|
||||||
json = json.replace(/"/g, ' ');
|
|
||||||
|
|
||||||
const tagEmbed = new MessageEmbed()
|
|
||||||
.setColor('#ff9900')
|
|
||||||
.setTitle('Tags list')
|
|
||||||
.setDescription(`Trigger:Response\n\n${json}`)
|
|
||||||
.setFooter(`You have ${count} tags on this server`);
|
|
||||||
|
|
||||||
message.channel.send(tagEmbed).catch(() => {
|
|
||||||
return message.channel.send('There is too much tag to be shown in an embed, sending file', {files: [`./tag/${message.guild.id}.json`]});
|
|
||||||
});
|
});
|
||||||
});
|
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;
|
module.exports = taglistCommand;
|
Loading…
Reference in a new issue