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 (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"];

View file

@ -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;
});
});
}
};
}
});
};

View file

@ -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) {