Revert gmbuffer.js, improved tags a bit more, some more pagination work

This commit is contained in:
TheEssem 2019-11-30 09:48:05 -06:00
parent 16927d8667
commit c9f0ff3827
3 changed files with 47 additions and 38 deletions

View File

@ -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 (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 (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!`; 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!`; return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been added!`;
case "delete": case "delete":
case "remove": case "remove":
@ -66,13 +67,18 @@ exports.run = async (message, args) => {
}; };
const setTag = async (content, name, message, guild) => { 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 ((!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) { if (message.attachments.length !== 0 && content) {
guild.tags.set(name, { content: `${content} ${message.attachments[0].url}`, author: message.author.id }); 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 { } else {
guild.tags.set(name, { content: content, author: message.author.id }); guild.tags.set(name, { content: content, author: message.author.id });
}
await guild.save(); await guild.save();
}
return;
}; };
exports.aliases = ["t", "tag", "ta"]; exports.aliases = ["t", "tag", "ta"];

View File

@ -1,9 +1,10 @@
// workaround for a gm bug where it doesn't output buffers properly // workaround for a gm bug where it doesn't output buffers properly
// https://github.com/aheckmann/gm/issues/572#issuecomment-293768810 // https://github.com/aheckmann/gm/issues/572#issuecomment-293768810
module.exports = async (data, format) => { module.exports = (data, format) => {
return new Promise((resolve, reject) => {
if (format) { if (format) {
data.stream(format, (err, stdout, stderr) => { data.stream(format, (err, stdout, stderr) => {
if (err) throw err; if (err) return reject(err);
const chunks = []; const chunks = [];
stdout.on("data", (chunk) => { stdout.on("data", (chunk) => {
chunks.push(chunk); chunks.push(chunk);
@ -11,15 +12,15 @@ module.exports = async (data, format) => {
// these are 'once' because they can and do fire multiple times for multiple errors, // 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 // but this is a promise so you'll have to deal with them one at a time
stdout.once("end", () => { stdout.once("end", () => {
return Buffer.concat(chunks); resolve(Buffer.concat(chunks));
}); });
stderr.once("data", (data) => { stderr.once("data", (data) => {
throw data; reject(String(data));
}); });
}); });
} else { } else {
data.stream((err, stdout, stderr) => { data.stream((err, stdout, stderr) => {
if (err) throw err; if (err) return reject(err);
const chunks = []; const chunks = [];
stdout.on("data", (chunk) => { stdout.on("data", (chunk) => {
chunks.push(chunk); chunks.push(chunk);
@ -27,11 +28,12 @@ module.exports = async (data, format) => {
// these are 'once' because they can and do fire multiple times for multiple errors, // 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 // but this is a promise so you'll have to deal with them one at a time
stdout.once("end", () => { stdout.once("end", () => {
return Buffer.concat(chunks); resolve(Buffer.concat(chunks));
}); });
stderr.once("data", (data) => { stderr.once("data", (data) => {
throw data; reject(String(data));
}); });
}); });
} }
});
}; };

View File

@ -45,6 +45,7 @@ const paginationEmbed = async (message, pages, timeout = 120000) => {
if (manageMessages) msg.removeReaction("▶", userID); if (manageMessages) msg.removeReaction("▶", userID);
break; break;
case "🗑": case "🗑":
reactionCollector.emit("end");
currentPage.delete(); currentPage.delete();
return; return;
default: default:
@ -52,7 +53,7 @@ const paginationEmbed = async (message, pages, timeout = 120000) => {
} }
} }
}); });
reactionCollector.on("end", () => { reactionCollector.once("end", () => {
try { try {
currentPage.removeReactions(); currentPage.removeReactions();
} catch (e) { } catch (e) {