diff --git a/commands/tags.js b/commands/tags.js index e6ac2a0..2c8c8bc 100644 --- a/commands/tags.js +++ b/commands/tags.js @@ -12,7 +12,8 @@ exports.run = async (message, args) => { if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to add!`; if (blacklist.includes(args[1].toLowerCase())) return `${message.author.mention}, you can't make a tag with that name!`; if (tags.has(args[1].toLowerCase())) return `${message.author.mention}, this tag already exists!`; - await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guild); + var result = await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guild); + if (result) return result; return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been added!`; case "delete": case "remove": @@ -66,13 +67,18 @@ exports.run = async (message, args) => { }; const setTag = async (content, name, message, guild) => { - if (content === undefined || content.length === 0) return `${message.author.mention}, you need to provide the content of the tag!`; - if (message.attachments.length !== 0) { + if ((!content || content.length === 0) && message.attachments.length === 0) return `${message.author.mention}, you need to provide the content of the tag!`; + if (message.attachments.length !== 0 && content) { guild.tags.set(name, { content: `${content} ${message.attachments[0].url}`, author: message.author.id }); + await guild.save(); + } else if (message.attachments.length !== 0) { + guild.tags.set(name, { content: message.attachments[0].url, author: message.author.id }); + await guild.save(); } else { guild.tags.set(name, { content: content, author: message.author.id }); + await guild.save(); } - await guild.save(); + return; }; exports.aliases = ["t", "tag", "ta"]; \ No newline at end of file diff --git a/utils/gmbuffer.js b/utils/gmbuffer.js index 17bcfc0..be17a24 100644 --- a/utils/gmbuffer.js +++ b/utils/gmbuffer.js @@ -1,37 +1,39 @@ // workaround for a gm bug where it doesn't output buffers properly // https://github.com/aheckmann/gm/issues/572#issuecomment-293768810 -module.exports = async (data, format) => { - if (format) { - data.stream(format, (err, stdout, stderr) => { - if (err) throw err; - const chunks = []; - stdout.on("data", (chunk) => { - chunks.push(chunk); +module.exports = (data, format) => { + return new Promise((resolve, reject) => { + if (format) { + data.stream(format, (err, stdout, stderr) => { + if (err) return reject(err); + const chunks = []; + stdout.on("data", (chunk) => { + chunks.push(chunk); + }); + // these are 'once' because they can and do fire multiple times for multiple errors, + // but this is a promise so you'll have to deal with them one at a time + stdout.once("end", () => { + resolve(Buffer.concat(chunks)); + }); + stderr.once("data", (data) => { + reject(String(data)); + }); }); - // these are 'once' because they can and do fire multiple times for multiple errors, - // but this is a promise so you'll have to deal with them one at a time - stdout.once("end", () => { - return Buffer.concat(chunks); + } else { + data.stream((err, stdout, stderr) => { + if (err) return reject(err); + const chunks = []; + stdout.on("data", (chunk) => { + chunks.push(chunk); + }); + // these are 'once' because they can and do fire multiple times for multiple errors, + // but this is a promise so you'll have to deal with them one at a time + stdout.once("end", () => { + resolve(Buffer.concat(chunks)); + }); + stderr.once("data", (data) => { + reject(String(data)); + }); }); - stderr.once("data", (data) => { - throw data; - }); - }); - } else { - data.stream((err, stdout, stderr) => { - if (err) throw err; - const chunks = []; - stdout.on("data", (chunk) => { - chunks.push(chunk); - }); - // these are 'once' because they can and do fire multiple times for multiple errors, - // but this is a promise so you'll have to deal with them one at a time - stdout.once("end", () => { - return Buffer.concat(chunks); - }); - stderr.once("data", (data) => { - throw data; - }); - }); - } -}; \ No newline at end of file + } + }); +}; diff --git a/utils/pagination/pagination.js b/utils/pagination/pagination.js index d306d4f..a18fc63 100644 --- a/utils/pagination/pagination.js +++ b/utils/pagination/pagination.js @@ -45,6 +45,7 @@ const paginationEmbed = async (message, pages, timeout = 120000) => { if (manageMessages) msg.removeReaction("▶", userID); break; case "🗑": + reactionCollector.emit("end"); currentPage.delete(); return; default: @@ -52,7 +53,7 @@ const paginationEmbed = async (message, pages, timeout = 120000) => { } } }); - reactionCollector.on("end", () => { + reactionCollector.once("end", () => { try { currentPage.removeReactions(); } catch (e) {