Fixed empty buffer issue
This commit is contained in:
parent
838bbd63d3
commit
ac47394ca2
1 changed files with 41 additions and 24 deletions
|
@ -1,5 +1,7 @@
|
||||||
const gm = require("gm");
|
const gm = require("gm");
|
||||||
const { promisify } = require("util");
|
const {
|
||||||
|
promisify
|
||||||
|
} = require("util");
|
||||||
const client = require("../utils/client.js");
|
const client = require("../utils/client.js");
|
||||||
const database = require("../utils/database.js");
|
const database = require("../utils/database.js");
|
||||||
const logger = require("../utils/logger.js");
|
const logger = require("../utils/logger.js");
|
||||||
|
@ -12,7 +14,9 @@ const twitter = process.env.TWITTER === "true" ? require("../utils/twitter.js")
|
||||||
module.exports = async () => {
|
module.exports = async () => {
|
||||||
// make sure settings/tags exist
|
// make sure settings/tags exist
|
||||||
for (const [id] of client.guilds) {
|
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) {
|
if (!guildDB) {
|
||||||
logger.log(`Registering guild database entry for guild ${id}...`);
|
logger.log(`Registering guild database entry for guild ${id}...`);
|
||||||
const newGuild = new database.guilds({
|
const newGuild = new database.guilds({
|
||||||
|
@ -31,7 +35,9 @@ module.exports = async () => {
|
||||||
|
|
||||||
// set activity (a.k.a. the gamer code)
|
// set activity (a.k.a. the gamer code)
|
||||||
(async function activityChanger() {
|
(async function activityChanger() {
|
||||||
client.editStatus("dnd", { name: `${misc.random(messages)} | @esmBot help` });
|
client.editStatus("dnd", {
|
||||||
|
name: `${misc.random(messages)} | @esmBot help`
|
||||||
|
});
|
||||||
setTimeout(activityChanger, 900000);
|
setTimeout(activityChanger, 900000);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
@ -40,32 +46,41 @@ module.exports = async () => {
|
||||||
gm.prototype.streamPromise = promisify(gm.prototype.stream);
|
gm.prototype.streamPromise = promisify(gm.prototype.stream);
|
||||||
gm.prototype.sizePromise = promisify(gm.prototype.size);
|
gm.prototype.sizePromise = promisify(gm.prototype.size);
|
||||||
gm.prototype.identifyPromise = promisify(gm.prototype.identify);
|
gm.prototype.identifyPromise = promisify(gm.prototype.identify);
|
||||||
gm.prototype.bufferPromise = promisify(gm.prototype.toBuffer);
|
//gm.prototype.bufferPromise = promisify(gm.prototype.toBuffer);
|
||||||
/*gm.prototype.bufferPromise = async (format, type) => {
|
gm.prototype.bufferPromise = function(format, type) {
|
||||||
console.log(this);
|
return new Promise((resolve, reject) => {
|
||||||
const stream = await this.out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").streamPromise(format);
|
this.out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").stream(format, (err, stdout, stderr) => {
|
||||||
const chunks = [];
|
if (err) return reject(err);
|
||||||
stream.stdout.on("data", (chunk) => {
|
const chunks = [];
|
||||||
chunks.push(chunk);
|
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
|
// tweet stuff
|
||||||
if (twitter !== null && twitter.active === false) {
|
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 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);
|
const tweetContent = await misc.getTweet(tweets);
|
||||||
try {
|
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}`);
|
logger.log(`Tweet with id ${info.data.id_str} has been tweeted with status code ${info.resp.statusCode} ${info.resp.statusMessage}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const error = JSON.stringify(e);
|
const error = JSON.stringify(e);
|
||||||
|
@ -84,7 +99,9 @@ module.exports = async () => {
|
||||||
});
|
});
|
||||||
stream.on("tweet", async (tweet) => {
|
stream.on("tweet", async (tweet) => {
|
||||||
if (tweet.user.screen_name !== "esmBot_" && !blocks.data.ids.includes(tweet.user.id_str)) {
|
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;
|
let tweetContent;
|
||||||
if (tweet.text.includes("@this_vid") || tweet.text.includes("@DownloaderBot") || tweet.text.includes("@GetVideoBot") || tweet.text.includes("@DownloaderB0t") || tweet.text.includes("@thisvid_")) {
|
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);
|
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.`);
|
logger.log("info", `Successfully started ${client.user.username}#${client.user.discriminator} with ${client.users.size} users in ${client.guilds.size} servers.`);
|
||||||
};
|
};
|
Loading…
Add table
Add a link
Reference in a new issue