mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-22 01:57:54 +02:00
Move some functions to Util, Bug Fixes, new stuff
This commit is contained in:
@@ -3,6 +3,7 @@ const { createCanvas, loadImage } = require('canvas');
|
||||
const GIFEncoder = require('gifencoder');
|
||||
const request = require('node-superfetch');
|
||||
const path = require('path');
|
||||
const { streamToArray } = require('../../util/Util');
|
||||
const { drawImageWithTint } = require('../../util/Canvas');
|
||||
const coord1 = [-25, -33, -42, -14];
|
||||
const coord2 = [-25, -13, -34, -10];
|
||||
@@ -62,39 +63,10 @@ module.exports = class TriggeredCommand extends Command {
|
||||
encoder.addFrame(ctx);
|
||||
}
|
||||
encoder.finish();
|
||||
const buffer = await this.streamToArray(stream);
|
||||
const buffer = await streamToArray(stream);
|
||||
return msg.say({ files: [{ attachment: Buffer.concat(buffer), name: 'triggered.gif' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
streamToArray(stream) {
|
||||
if (!stream.readable) return Promise.resolve([]);
|
||||
return new Promise((resolve, reject) => {
|
||||
const array = [];
|
||||
function onData(data) {
|
||||
array.push(data);
|
||||
}
|
||||
function onEnd(error) {
|
||||
if (error) reject(error);
|
||||
else resolve(array);
|
||||
cleanup();
|
||||
}
|
||||
function onClose() {
|
||||
resolve(array);
|
||||
cleanup();
|
||||
}
|
||||
function cleanup() {
|
||||
stream.removeListener('data', onData);
|
||||
stream.removeListener('end', onEnd);
|
||||
stream.removeListener('error', onEnd);
|
||||
stream.removeListener('close', onClose);
|
||||
}
|
||||
stream.on('data', onData);
|
||||
stream.on('end', onEnd);
|
||||
stream.on('error', onEnd);
|
||||
stream.on('close', onClose);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user