Support GIF in what-anime

This commit is contained in:
Dragon Fire
2020-07-17 09:00:17 -04:00
parent fe46c903c5
commit d90a7b14ad
2 changed files with 12 additions and 2 deletions
+11 -1
View File
@@ -1,5 +1,6 @@
const Command = require('../../structures/Command'); const Command = require('../../structures/Command');
const request = require('node-superfetch'); const request = require('node-superfetch');
const { createCanvas, loadImage } = require('canvas');
const { stripIndents } = require('common-tags'); const { stripIndents } = require('common-tags');
const { base64 } = require('../../util/Util'); const { base64 } = require('../../util/Util');
const { WHATANIME_KEY } = process.env; const { WHATANIME_KEY } = process.env;
@@ -37,7 +38,8 @@ module.exports = class WhatAnimeCommand extends Command {
if (!status.status) { if (!status.status) {
return msg.reply(`Oh no, I'm out of requests! Please wait ${status.refresh} seconds and try again.`); return msg.reply(`Oh no, I'm out of requests! Please wait ${status.refresh} seconds and try again.`);
} }
const { body } = await request.get(screenshot); let { body } = await request.get(screenshot);
if (screenshot.endsWith('.gif')) body = await this.convertGIF(body);
const result = await this.search(body, msg.channel.nsfw); const result = await this.search(body, msg.channel.nsfw);
if (result === 'size') return msg.reply('Please do not send an image larger than 10MB.'); if (result === 'size') return msg.reply('Please do not send an image larger than 10MB.');
if (result.nsfw && !msg.channel.nsfw) { if (result.nsfw && !msg.channel.nsfw) {
@@ -93,4 +95,12 @@ module.exports = class WhatAnimeCommand extends Command {
return null; return null;
} }
} }
async convertGIF(image) {
const data = await loadImage(image);
const canvas = createCanvas(data.width, data.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(data, 0, 0);
return canvas.toBuffer();
}
}; };
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "119.18.0", "version": "119.18.1",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {