Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: image enhance api & command #171

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 69 additions & 68 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,68 +1,69 @@
{
"name": "chisato-bot",
"version": "1.0.4",
"description": "WhatsApp Bot Multi-Device using Baileys",
"main": "start.js",
"scripts": {
"build": "tsc --build",
"start": "node ./dist/auth/connect.js",
"pm2:start": "pm2 start dist/auth/connect.js && pm2 flush connect && pm2 logs connect",
"pm2:restart": "pm2 reload connect && pm2 flush connect && pm2 logs connect"
},
"prisma": {
"schema": "./prisma/schema.prisma"
},
"author": "Tobz",
"license": "GPL-3.0-only",
"dependencies": {
"@adiwajshing/keyed-db": "^0.2.4",
"@arugaz/ai2d": "^1.0.1-z.9",
"@tobyg74/tiktok-api-dl": "^1.0.13",
"awesome-phonenumber": "^3.2.0",
"axios": "^1.5.2",
"baileys": "github:TobyG74/baileys",
"cfonts": "^3.1.1",
"cheerio": "^1.0.0-rc.12",
"cli-color": "^2.0.3",
"crypto": "^1.0.1",
"dotenv": "^16.0.3",
"file-type": "16.5.4",
"fluent-ffmpeg": "^2.1.2",
"form-data": "^4.0.0",
"path": "^0.12.7",
"twitter-downloader": "^1.1.1",
"typed-emitter": "^2.1.0",
"util": "^0.12.4",
"wa-sticker-formatter": "^4.4.4",
"yt-search": "^2.10.3"
},
"devDependencies": {
"@prisma/client": "^5.7.0",
"@types/cli-color": "^2.0.5",
"@types/yt-search": "^2.10.3",
"croner": "^8.0.0",
"moment-timezone": "^0.5.34",
"pino": "^7.0.0",
"pm2": "^5.2.0",
"qrcode-terminal": "^0.12.0",
"typescript": "^5.3.3"
},
"keywords": [
"wa-bot",
"wabot",
"whatsapp-bot",
"whatsappbot",
"whatsappmd",
"chisato-bot",
"chisato-md",
"baileys"
],
"homepage": "https://github.com/TobyG74/ChisatoBOT#readme",
"repository": {
"type": "git",
"url": "https://github.com/TobyG74/ChisatoBOT.git"
},
"bugs": {
"url": "https://github.com/TobyG74/ChisatoBOT/issues"
}
}
{
"name": "chisato-bot",
"version": "1.0.4",
"description": "WhatsApp Bot Multi-Device using Baileys",
"main": "start.js",
"scripts": {
"build": "tsc --build",
"start": "node ./dist/auth/connect.js",
"pm2:start": "pm2 start dist/auth/connect.js && pm2 flush connect && pm2 logs connect",
"pm2:restart": "pm2 reload connect && pm2 flush connect && pm2 logs connect"
},
"prisma": {
"schema": "./prisma/schema.prisma"
},
"author": "Tobz",
"license": "GPL-3.0-only",
"dependencies": {
"@adiwajshing/keyed-db": "^0.2.4",
"@arugaz/ai2d": "^1.0.1-z.9",
"@tobyg74/tiktok-api-dl": "^1.0.13",
"awesome-phonenumber": "^3.2.0",
"axios": "^1.5.2",
"baileys": "github:TobyG74/baileys",
"cfonts": "^3.1.1",
"cheerio": "^1.0.0-rc.12",
"cli-color": "^2.0.3",
"crypto": "^1.0.1",
"dotenv": "^16.0.3",
"file-type": "16.5.4",
"fluent-ffmpeg": "^2.1.2",
"form-data": "^4.0.0",
"node-fetch": "^2.6.11",
"path": "^0.12.7",
"twitter-downloader": "^1.1.1",
"typed-emitter": "^2.1.0",
"util": "^0.12.4",
"wa-sticker-formatter": "^4.4.4",
"yt-search": "^2.10.3"
},
"devDependencies": {
"@prisma/client": "^5.7.0",
"@types/cli-color": "^2.0.5",
"@types/yt-search": "^2.10.3",
"croner": "^8.0.0",
"moment-timezone": "^0.5.34",
"pino": "^7.0.0",
"pm2": "^5.2.0",
"qrcode-terminal": "^0.12.0",
"typescript": "^5.3.3"
},
"keywords": [
"wa-bot",
"wabot",
"whatsapp-bot",
"whatsappbot",
"whatsappmd",
"chisato-bot",
"chisato-md",
"baileys"
],
"homepage": "https://github.com/TobyG74/ChisatoBOT#readme",
"repository": {
"type": "git",
"url": "https://github.com/TobyG74/ChisatoBOT.git"
},
"bugs": {
"url": "https://github.com/TobyG74/ChisatoBOT/issues"
}
}
37 changes: 37 additions & 0 deletions src/commands/converter/enhance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { ConfigCommands } from "../../types/structure/commands";
import { enhanceImage } from "../../utils/scrapers/converter/enhance";

export default <ConfigCommands>{
name: "enhance",
alias: ["remini", "tohd"],
usage: "<reply>",
category: "converter",
description: "Convert Image to hd Quality",
limit: 4,
cooldown: 10,
isPremium: true,
isProcess: true,
async run({ Chisato, from, message }) {
try {
let { quoted } = message;
let buffer: Buffer | null;
if (message?.type === "imageMessage" || quoted?.type === "imageMessage") {
buffer = quoted !== null ? await quoted.download() : await message.download();
const remini = await enhanceImage(buffer, "enhance")
await Chisato.sendImage(from, remini, null, message);
} else {
await Chisato.sendText(
from,
"*「 ! 」* Please reply to the image you want to enhance",
message
);
}
} catch (e) {
Chisato.sendText(
from,
"*「 ! 」* There is an error. Please report it to the bot creator immediately!",
message
);
}
},
};
36 changes: 36 additions & 0 deletions src/utils/scrapers/converter/enhance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import FormData from "form-data";
import fetch from "node-fetch";

export async function enhanceImage(store: Buffer, name: string): Promise<Buffer> {
const validExports = ["enhance", "recolor", "dehaze"];
name = validExports.includes(name) ? name : validExports[0];

const data = new FormData();
const apiUrl = `https://inferenceengine.vyro.ai/${name}`;

data.append("model_version", "1");
data.append("image", Buffer.from(store), {
filename: "enhance_image_body.jpg",
contentType: "image/jpeg",
});

try {
const response = await fetch(apiUrl, {
method: "POST",
body: data,
headers: {
"User-Agent": "okhttp/4.9.3",
Connection: "Keep-Alive",
"Accept-Encoding": "gzip",
},
});

if (!response.ok) {
throw new Error("Failed to fetch");
}

return await response.buffer();
} catch (error) {
throw new Error("Request failed");
}
}
Loading