mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-26 06:42:50 +02:00
Support GIF in what-anime
This commit is contained in:
@@ -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
@@ -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": {
|
||||||
|
|||||||
Reference in New Issue
Block a user