Fixed empty buffer issue

This commit is contained in:
TheEssem 2020-02-25 19:57:44 -06:00
parent 838bbd63d3
commit ac47394ca2

View file

@ -1,5 +1,7 @@
const gm = require("gm");
const { promisify } = require("util");
const {
promisify
} = require("util");
const client = require("../utils/client.js");
const database = require("../utils/database.js");
const logger = require("../utils/logger.js");
@ -12,7 +14,9 @@ const twitter = process.env.TWITTER === "true" ? require("../utils/twitter.js")
module.exports = async () => {
// make sure settings/tags exist
for (const [id] of client.guilds) {
const guildDB = (await database.guilds.find({ id: id }).exec())[0];
const guildDB = (await database.guilds.find({
id: id
}).exec())[0];
if (!guildDB) {
logger.log(`Registering guild database entry for guild ${id}...`);
const newGuild = new database.guilds({
@ -31,7 +35,9 @@ module.exports = async () => {
// set activity (a.k.a. the gamer code)
(async function activityChanger() {
client.editStatus("dnd", { name: `${misc.random(messages)} | @esmBot help` });
client.editStatus("dnd", {
name: `${misc.random(messages)} | @esmBot help`
});
setTimeout(activityChanger, 900000);
})();
@ -40,32 +46,41 @@ module.exports = async () => {
gm.prototype.streamPromise = promisify(gm.prototype.stream);
gm.prototype.sizePromise = promisify(gm.prototype.size);
gm.prototype.identifyPromise = promisify(gm.prototype.identify);
gm.prototype.bufferPromise = promisify(gm.prototype.toBuffer);
/*gm.prototype.bufferPromise = async (format, type) => {
console.log(this);
const stream = await this.out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").streamPromise(format);
const chunks = [];
stream.stdout.on("data", (chunk) => {
chunks.push(chunk);
//gm.prototype.bufferPromise = promisify(gm.prototype.toBuffer);
gm.prototype.bufferPromise = function(format, type) {
return new Promise((resolve, reject) => {
this.out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").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(data.toString());
});
});
});
// these are 'once' because they can and do fire multiple times for multiple errors,
// but this is an async function so you'll have to deal with them one at a time
stream.stdout.once("end", () => {
return Buffer.concat(chunks);
});
stream.stderr.once("data", (data) => {
data.toString();
});
};*/
};
// tweet stuff
if (twitter !== null && twitter.active === false) {
const blocks = await twitter.client.get("blocks/ids", { stringify_ids: true });
const blocks = await twitter.client.get("blocks/ids", {
stringify_ids: true
});
const tweet = async () => {
const tweets = (await database.tweets.find({ enabled: true }).exec())[0];
const tweets = (await database.tweets.find({
enabled: true
}).exec())[0];
const tweetContent = await misc.getTweet(tweets);
try {
const info = await twitter.client.post("statuses/update", { status: tweetContent });
const info = await twitter.client.post("statuses/update", {
status: tweetContent
});
logger.log(`Tweet with id ${info.data.id_str} has been tweeted with status code ${info.resp.statusCode} ${info.resp.statusMessage}`);
} catch (e) {
const error = JSON.stringify(e);
@ -84,7 +99,9 @@ module.exports = async () => {
});
stream.on("tweet", async (tweet) => {
if (tweet.user.screen_name !== "esmBot_" && !blocks.data.ids.includes(tweet.user.id_str)) {
const tweets = (await database.tweets.find({ enabled: true }).exec())[0];
const tweets = (await database.tweets.find({
enabled: true
}).exec())[0];
let tweetContent;
if (tweet.text.includes("@this_vid") || tweet.text.includes("@DownloaderBot") || tweet.text.includes("@GetVideoBot") || tweet.text.includes("@DownloaderB0t") || tweet.text.includes("@thisvid_")) {
tweetContent = await misc.getTweet(tweet, true, true);
@ -102,4 +119,4 @@ module.exports = async () => {
}
logger.log("info", `Successfully started ${client.user.username}#${client.user.discriminator} with ${client.users.size} users in ${client.guilds.size} servers.`);
};
};