-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from xbnfz01/master
feat: add image enhancement feature
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
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 { | ||
const { quoted } = message; | ||
const buffer = quoted ? await quoted.download() : await message.download(); | ||
|
||
if (buffer && (message.type === "imageMessage" || quoted?.type === "imageMessage")) { | ||
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 (error) { | ||
console.error(error); // Log the error for debugging | ||
await Chisato.sendText( | ||
from, | ||
"*「 ! 」* An error occurred. Please report it to the bot creator immediately!", | ||
message | ||
); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import FormData from "form-data"; | ||
import axios, { AxiosResponse } from "axios"; | ||
|
||
export async function enhanceImage(store: Buffer, name: string): Promise<Buffer> { | ||
return new Promise(async (resolve, reject) => { | ||
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: AxiosResponse = await axios.post(apiUrl, data, { | ||
headers: { | ||
"User-Agent": "okhttp/4.9.3", | ||
Connection: "Keep-Alive", | ||
"Accept-Encoding": "gzip", | ||
...data.getHeaders(), | ||
}, | ||
responseType: 'arraybuffer', | ||
}); | ||
|
||
resolve(Buffer.from(response.data)); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} |