forked from BrunoSobrino/TheMystic-Bot-MD
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
15 additions
and
65 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
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 |
---|---|---|
@@ -1,63 +1,24 @@ | ||
import { BackgroundRemoval } from '@imgly/background-removal-node'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { sticker } from '../src/libraries/sticker.js'; | ||
import uploadImage from '../src/libraries/uploadImage.js'; | ||
import {sticker} from '../src/libraries/sticker.js'; | ||
|
||
const TempDirectory = path.join(process.cwd(), 'src/tmp/'); | ||
|
||
const handler = async (m, {conn, text}) => { | ||
const datas = global | ||
const idioma = datas.db.data.users[m.sender].language || global.defaultLenguaje | ||
const _translate = JSON.parse(fs.readFileSync(`./src/languages/${idioma}.json`)) | ||
const tradutor = _translate.plugins.sticker_sremovebg | ||
|
||
const generateTempFileName = () => { | ||
const now = new Date(); | ||
const timestamp = now.toISOString().replace(/[-:.]/g, ''); | ||
return `temp-${timestamp}.png`; | ||
}; | ||
|
||
|
||
if (!fs.existsSync(TempDirectory)) { | ||
fs.mkdirSync(TempDirectory, { recursive: true }); | ||
} | ||
|
||
const handler = async (m, { conn }) => { | ||
try { | ||
|
||
await m.reply('🛠️ Generando sticker...'); | ||
|
||
const q = m.quoted ? m.quoted : m; | ||
const q = m.quoted ? m.quoted : m; | ||
const mime = (q.msg || q).mimetype || ''; | ||
|
||
|
||
if (!mime || !mime.startsWith('image/')) { | ||
await conn.reply(m.chat, '❌ Por favor, envíe una imagen válida.', m); | ||
return; | ||
} | ||
|
||
const img = await q.download(); | ||
|
||
|
||
const inputPath = path.join(TempDirectory, generateTempFileName()); | ||
const outputPath = path.join(TempDirectory, generateTempFileName()); | ||
|
||
|
||
fs.writeFileSync(inputPath, img); | ||
|
||
|
||
await BackgroundRemoval.fromFile(inputPath).toFile(outputPath); | ||
|
||
|
||
const stickerResult = await sticker(fs.readFileSync(outputPath), null, global.packname, global.author); | ||
|
||
|
||
await conn.sendFile(m.chat, stickerResult, 'sticker.webp', '', m, { asSticker: true }); | ||
|
||
|
||
fs.unlinkSync(inputPath); | ||
fs.unlinkSync(outputPath); | ||
|
||
} catch (error) { | ||
console.error('Error:', error); / | ||
await conn.reply(m.chat, `❌ Error al generar el sticker: ${error.message}`, m); / | ||
const img = await q.download(); | ||
const url = await uploadImage(img); | ||
const sremovebg = global.API(`https://api.lolhuman.xyz/api/removebg?apikey=${lolkeysapi}&img=${url}`); | ||
const stickerr = await sticker(false, sremovebg, global.packname, global.author); | ||
conn.sendFile(m.chat, stickerr, 'sticker.webp', '', m, {asSticker: true}); | ||
} catch (e) { | ||
m.reply(tradutor.texto1); | ||
} | ||
}; | ||
|
||
handler.command = /^sremovebg|rmbg$/i; | ||
export default handler; |