Nurutomo / wabot-aq

WhatsApp Bot
GNU General Public License v3.0
690 stars 1.38k forks source link

Togif #428

Closed FadliDarmawan closed 2 years ago

FadliDarmawan commented 3 years ago

Reply stickergif dan di jadikan gif oleh bot

tovideo untuk fotmat video

Ftwrr commented 3 years ago

cek pull request yang udah di close :|

bilal-08 commented 3 years ago

check the pull request that has been closed :|

what is the name of that pr :v?

Ftwrr commented 3 years ago

check the pull request that has been closed :|

what is the name of that pr :v?

cari sendiri lah, lu kan udah gede

Anshuljai commented 3 years ago

i will pull it...check after some time -_

Anshuljai commented 3 years ago

441 check it out ;)

FadliDarmawan commented 3 years ago

441 check it out ;)

Is it works?

Anshuljai commented 3 years ago

441 check it out ;)

Is it works?

no 🙄

FadliDarmawan commented 3 years ago

441 check it out ;)

Is it works?

no 🙄

Lol

ariffb25 commented 3 years ago
const fs = require("fs")
const Axios = require("axios")
const { MessageType, Mimetype } = require("@adiwajshing/baileys")
const cheerio = require("cheerio")
const FormData = require("form-data")

let handler = async (m, { conn, media, usedPrefix, command, isPrems }) => {
    if (!m.quoted) throw `*Mengubah stiker animasi menjadi gif, bukan mengubah gif menjadi stiker!*\n\nbalas stiker dengan caption *${usedPrefix + command}*\n\nkalo mau jadiin stiker itu perintahnya *${usedPrefix}stiker*`
    if (m.quoted.mtype != "stickerMessage") throw `*Mengubah stiker animasi menjadi gif, bukan mengubah gif menjadi stiker!*\n\nbalas stiker dengan caption *${usedPrefix + command}*\n\nkalo mau jadiin stiker itu perintahnya *${usedPrefix}stiker*`

    const filename = getRandom()
    const savedFilename = await conn.downloadAndSaveMediaMessage(m.quoted.fakeObj, `./tmp/${filename}`)

    await webp2mp4File(savedFilename)
        .then(async (rest) => {
            await Axios({
                method: "GET",
                url: rest.result,
                responseType: "stream",
            }).then(({ data }) => {
                const saving = data.pipe(fs.createWriteStream(`./tmp/${filename}-done.mp4`))
                saving.on("finish", () => {
                    conn.sendMessage(m.chat, fs.readFileSync(`./tmp/${filename}-done.mp4`), MessageType.video, {
                        mimetype: Mimetype.gif,
                        caption: `*© stikerin*`,
                        quoted: m,
                        thumbnail: Buffer.alloc(0)
                    })
                    if (fs.existsSync(savedFilename)) fs.unlinkSync(savedFilename)
                    if (fs.existsSync(`./tmp/${filename}-done.mp4`)) fs.unlinkSync(`./tmp/${filename}-done.mp4`)
                })
            })
        })
        .catch((e) => {
            if (fs.existsSync(savedFilename)) fs.unlinkSync(savedFilename)
            throw `Jika file tidak terkirim: ${rest.result}`
        })
}

handler.help = ["togif"]
handler.tags = ["sticker"]
handler.command = /^togif|tg$/i
handler.limit = true
module.exports = handler

const getRandom = () => {
    return `${Math.floor(Math.random() * 10000)}`
}

function webp2mp4File(path) {
    return new Promise(async (resolve, reject) => {
        const bodyForm = new FormData()
        bodyForm.append("new-image-url", "")
        bodyForm.append("new-image", fs.createReadStream(path))
        await Axios({
            method: "post",
            url: "https://s6.ezgif.com/webp-to-mp4",
            data: bodyForm,
            headers: {
                "Content-Type": `multipart/form-data boundary=${bodyForm._boundary}`,
            },
        })
            .then(async ({ data }) => {
                const bodyFormThen = new FormData()
                const $ = cheerio.load(data)
                const file = $('input[name="file"]').attr("value")
                const token = $('input[name="token"]').attr("value")
                const convert = $('input[name="file"]').attr("value")
                const gotdata = {
                    file: file,
                    token: token,
                    convert: convert,
                }
                bodyFormThen.append("file", gotdata.file)
                bodyFormThen.append("token", gotdata.token)
                bodyFormThen.append("convert", gotdata.convert)
                await Axios({
                    method: "post",
                    url: "https://ezgif.com/webp-to-mp4/" + gotdata.file,
                    data: bodyFormThen,
                    headers: {
                        "Content-Type": `multipart/form-data boundary=${bodyFormThen._boundary}`,
                    },
                })
                    .then(({ data }) => {
                        const $ = cheerio.load(data)
                        const result = "https:" + $("div#output > p.outfile > video > source").attr("src")
                        resolve({
                            status: true,
                            message: "Created By MRHRTZ",
                            result: result,
                        })
                    })
                    .catch(reject)
            })
            .catch(reject)
    })
}
FadliDarmawan commented 3 years ago
const fs = require("fs")
const Axios = require("axios")
const { MessageType, Mimetype } = require("@adiwajshing/baileys")
const cheerio = require("cheerio")
const FormData = require("form-data")

let handler = async (m, { conn, media, usedPrefix, command, isPrems }) => {
    if (!m.quoted) throw `*Mengubah stiker animasi menjadi gif, bukan mengubah gif menjadi stiker!*\n\nbalas stiker dengan caption *${usedPrefix + command}*\n\nkalo mau jadiin stiker itu perintahnya *${usedPrefix}stiker*`
    if (m.quoted.mtype != "stickerMessage") throw `*Mengubah stiker animasi menjadi gif, bukan mengubah gif menjadi stiker!*\n\nbalas stiker dengan caption *${usedPrefix + command}*\n\nkalo mau jadiin stiker itu perintahnya *${usedPrefix}stiker*`

    const filename = getRandom()
    const savedFilename = await conn.downloadAndSaveMediaMessage(m.quoted.fakeObj, `./tmp/${filename}`)

    await webp2mp4File(savedFilename)
        .then(async (rest) => {
            await Axios({
                method: "GET",
                url: rest.result,
                responseType: "stream",
            }).then(({ data }) => {
                const saving = data.pipe(fs.createWriteStream(`./tmp/${filename}-done.mp4`))
                saving.on("finish", () => {
                    conn.sendMessage(m.chat, fs.readFileSync(`./tmp/${filename}-done.mp4`), MessageType.video, {
                        mimetype: Mimetype.gif,
                        caption: `*© stikerin*`,
                        quoted: m,
                        thumbnail: Buffer.alloc(0)
                    })
                    if (fs.existsSync(savedFilename)) fs.unlinkSync(savedFilename)
                    if (fs.existsSync(`./tmp/${filename}-done.mp4`)) fs.unlinkSync(`./tmp/${filename}-done.mp4`)
                })
            })
        })
        .catch((e) => {
            if (fs.existsSync(savedFilename)) fs.unlinkSync(savedFilename)
            throw `Jika file tidak terkirim: ${rest.result}`
        })
}

handler.help = ["togif"]
handler.tags = ["sticker"]
handler.command = /^togif|tg$/i
handler.limit = true
module.exports = handler

const getRandom = () => {
    return `${Math.floor(Math.random() * 10000)}`
}

function webp2mp4File(path) {
    return new Promise(async (resolve, reject) => {
        const bodyForm = new FormData()
        bodyForm.append("new-image-url", "")
        bodyForm.append("new-image", fs.createReadStream(path))
        await Axios({
            method: "post",
            url: "https://s6.ezgif.com/webp-to-mp4",
            data: bodyForm,
            headers: {
                "Content-Type": `multipart/form-data boundary=${bodyForm._boundary}`,
            },
        })
            .then(async ({ data }) => {
                const bodyFormThen = new FormData()
                const $ = cheerio.load(data)
                const file = $('input[name="file"]').attr("value")
                const token = $('input[name="token"]').attr("value")
                const convert = $('input[name="file"]').attr("value")
                const gotdata = {
                    file: file,
                    token: token,
                    convert: convert,
                }
                bodyFormThen.append("file", gotdata.file)
                bodyFormThen.append("token", gotdata.token)
                bodyFormThen.append("convert", gotdata.convert)
                await Axios({
                    method: "post",
                    url: "https://ezgif.com/webp-to-mp4/" + gotdata.file,
                    data: bodyFormThen,
                    headers: {
                        "Content-Type": `multipart/form-data boundary=${bodyFormThen._boundary}`,
                    },
                })
                    .then(({ data }) => {
                        const $ = cheerio.load(data)
                        const result = "https:" + $("div#output > p.outfile > video > source").attr("src")
                        resolve({
                            status: true,
                            message: "Created By MRHRTZ",
                            result: result,
                        })
                    })
                    .catch(reject)
            })
            .catch(reject)
    })
}

Thx bro

ariffb25 commented 3 years ago

https://github.com/Nurutomo/wabot-aq/commit/ee319cb8c6899ab97cbfd2db2584b5044f12c782

github-actions[bot] commented 2 years ago

stale issue