Add classic option flag for sketch

This commit is contained in:
Dragon Fire
2024-11-05 10:23:07 -05:00
parent 1786cf036d
commit 22350364d2
2 changed files with 35 additions and 12 deletions
+28 -5
View File
@@ -1,9 +1,10 @@
const Command = require('../../framework/Command');
const { PermissionFlagsBits } = require('discord.js');
const gm = require('gm').subClass({ imageMagick: '7+' });
const request = require('node-superfetch');
const { readFile } = require('fs/promises');
const path = require('path');
const { reactIfAble } = require('../../util/Util');
const { magikToBuffer, reactIfAble } = require('../../util/Util');
const { LOADING_EMOJI_ID, SUCCESS_EMOJI_ID } = process.env;
module.exports = class SketchCommand extends Command {
@@ -26,6 +27,16 @@ module.exports = class SketchCommand extends Command {
reasonURL: 'https://github.com/reiinakano/arbitrary-image-stylization-tfjs/'
}
],
flags: [
{
key: 'classic',
description: 'Uses the old sketch method.'
},
{
key: 'c',
description: 'Alias for classic.'
}
],
args: [
{
key: 'image',
@@ -38,13 +49,25 @@ module.exports = class SketchCommand extends Command {
});
}
async run(msg, { image }) {
async run(msg, { image, flags }) {
const { body } = await request.get(image);
const style = await readFile(path.join(__dirname, '..', '..', 'assets', 'images', 'sketch.jpg'));
await reactIfAble(msg, msg.author, LOADING_EMOJI_ID, '💬');
const attachment = await this.client.tensorflow.stylizeImage(body, style);
let format = 'jpg';
let attachment;
if (flags.classic || flags.c) {
const magik = gm(body);
magik.colorspace('gray');
magik.out('-sketch');
magik.out('0x20+120');
magik.setFormat('png');
attachment = await magikToBuffer(magik);
format = 'png';
} else {
const style = await readFile(path.join(__dirname, '..', '..', 'assets', 'images', 'sketch.jpg'));
attachment = await this.client.tensorflow.stylizeImage(body, style);
}
await reactIfAble(msg, msg.author, SUCCESS_EMOJI_ID, '✅');
if (Buffer.byteLength(attachment) > 2.5e+7) return msg.reply('Resulting image was above 25 MB.');
return msg.say({ files: [{ attachment, name: 'sketch.jpg' }] });
return msg.say({ files: [{ attachment, name: `sketch.${format}` }] });
}
};
+7 -7
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "152.3.1",
"version": "152.4.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
@@ -32,7 +32,7 @@
"@discordjs/opus": "^0.9.0",
"@discordjs/voice": "^0.17.0",
"@mediapipe/face_detection": "^0.4.1646425229",
"@napi-rs/canvas": "^0.1.58",
"@napi-rs/canvas": "^0.1.59",
"@tensorflow-models/face-detection": "^1.0.3",
"@tensorflow/tfjs-node": "^4.22.0",
"@twemoji/parser": "^15.1.1",
@@ -79,7 +79,7 @@
"twitter-openapi-typescript": "^0.0.43",
"valid-url": "^1.0.9",
"wavefile": "^11.0.0",
"winston": "^3.15.0",
"winston": "^3.16.0",
"wuzzy": "^0.1.8",
"ytdl-core": "^4.11.5",
"zip-to-timezone": "^1.2.1"
@@ -87,14 +87,14 @@
"optionalDependencies": {
"bufferutil": "^4.0.8",
"sodium-native": "^4.2.2",
"utf-8-validate": "^6.0.4",
"utf-8-validate": "^6.0.5",
"zlib-sync": "^0.1.9"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
"eslint": "^9.13.0",
"@eslint/js": "^9.14.0",
"eslint": "^9.14.0",
"eslint-config-amber": "^2.0.4",
"eslint-plugin-jsonc": "^2.16.0",
"globals": "^15.11.0"
"globals": "^15.12.0"
}
}