User: sempurnakan kode ini kenapa sih setiap panjang seperti ini .bratvideo Azmil suka bokep dan sange 🤣 gagal itu 6 kata selalu gagal apa karna output nya cuman 4 jadi gagal? import fs from "fs";
import path from "path";
import axios from "axios";
import { execSync } from "child_process";
import fetch from "node-fetch";

let cooldown = new Map();

let handler = async (a, { conn: r, args: e }) => {
    var t = a.sender;
    let o;

    if (1 <= e.length) {
        o = e.join(" ");
    } else {
        if (!a.quoted || !a.quoted.text) return r.reply(a.chat, "Input atau reply text!", a);
        o = a.quoted.text;
    }

    if (!o) return r.reply(a.chat, "Contoh penggunaan: !bratvideo hello world", a);
    if (o.length > 250) return r.reply(a.chat, "Max 250 karakter!", a);

    if (cooldown.has(t)) {
        e = cooldown.get(t);
        e = (Date.now() - e) / 1e3;
        if (e < 10) return a.reply(`[❗] Tunggu ${Math.ceil(10 - e)} detik sebelum menggunakan perintah ini lagi.`);
    }

    cooldown.set(t, Date.now());
    r.sendReact(a.chat, "🕒", a.key);

    var n = o.split(" ");
    var i = path.resolve("tmp");
    var s = (fs.existsSync(i) || fs.mkdirSync(i), []);

    try {
        for (let e = 0; e < n.length; e++) {
            var p = n.slice(0, e + 1).join(" ");
            var c = await axios.get("https://brat.caliphdev.com/api/brat?text=" + encodeURIComponent(p), { responseType: "arraybuffer" }).catch(e => e.response);
            if (c.status !== 200) throw new Error(`Gagal mengambil data dari API: ${c.statusText}`);
            
            var l = path.join(i, `frame${e}.mp4`);
            fs.writeFileSync(l, c.data);
            s.push(l);
        }

        var f = path.join(i, "filelist.txt");
        let t = "";
        for (let e = 0; e < s.length; e++) {
            t += `file '${s[e]}'\nduration 0.7\n`;
        }
        t += `file '${s[s.length - 1]}'\nduration 2\n`;
        fs.writeFileSync(f, t);

        var h = path.join(i, "output.mp4");
        execSync(`ffmpeg -y -f concat -safe 0 -i ${f} -vf "fps=30" -c:v libx264 -preset ultrafast -pix_fmt yuv420p ${h}`);
        
        // Pastikan file output ada sebelum dibaca
        if (!fs.existsSync(h)) throw new Error("Output video tidak ditemukan.");

        var videoBuffer = fs.readFileSync(h);
        var m = await mp4ToWebp(videoBuffer, { pack: global.packname, author: global.author });

        r.sendFile(a.chat, m, "sticker.webp", o, a);
        
        // Menghapus file yang telah digunakan
        s.forEach(e => { fs.existsSync(e) && fs.unlinkSync(e); });
        fs.existsSync(f) && fs.unlinkSync(f);
        fs.existsSync(h) && fs.unlinkSync(h);
    } catch (e) {
        r.reply(a.chat, `Maaf, terjadi kesalahan saat mengambil output.\n- ${e.message}`, a);
    }
};

async function mp4ToWebp(buffer, options) {
    options = options || { pack: "‎", author: "‎", crop: false };
    const data = {
        file: "data:video/mp4;base64," + buffer.toString("base64"),
        processOptions: {
            crop: options.crop,
            startTime: "00:00:00.0",
            endTime: "00:00:07.0",
            loop: 0
        },
        stickerMetadata: { ...options }
    };

    const response = await fetch("https://sticker-api.openwa.dev/convertMp4BufferToWebpDataUrl", {
        method: "POST",
        headers: {
            Accept: "application/json, text/plain, */*",
            "Content-Type": "application/json;charset=utf-8"
        },
        body: JSON.stringify(data)
    });

    if (!response.ok) throw new Error("Gagal mengkonversi video ke webp.");

    const responseData = await response.text();
    return Buffer.from(responseData.split(";base64,")[1], "base64");
}

handler.help = handler.command = ["bratvideo"];
handler.tags = ["tools"];
export default handler;
User: sempurnakan kode ini kenapa sih setiap panjang seperti ini .bratvideo Azmil suka bokep dan sange 🤣 gagal itu 6 kata selalu gagal apa karna output nya cuman 4 jadi gagal? import fs from "fs";
import path from "path";
import axios from "axios";
import { execSync } from "child_process";
import fetch from "node-fetch";

let cooldown = new Map();

let handler = async (a, { conn: r, args: e }) => {
    var t = a.sender;
    let o;

    if (1 <= e.length) {
        o = e.join(" ");
    } else {
        if (!a.quoted || !a.quoted.text) return r.reply(a.chat, "Input atau reply text!", a);
        o = a.quoted.text;
    }

    if (!o) return r.reply(a.chat, "Contoh penggunaan: !bratvideo hello world", a);
    if (o.length > 250) return r.reply(a.chat, "Max 250 karakter!", a);

    if (cooldown.has(t)) {
        e = cooldown.get(t);
        e = (Date.now() - e) / 1e3;
        if (e < 10) return a.reply(`[❗] Tunggu ${Math.ceil(10 - e)} detik sebelum menggunakan perintah ini lagi.`);
    }

    cooldown.set(t, Date.now());
    r.sendReact(a.chat, "🕒", a.key);

    var n = o.split(" ");
    var i = path.resolve("tmp");
    var s = (fs.existsSync(i) || fs.mkdirSync(i), []);

    try {
        for (let e = 0; e < n.length; e++) {
            var p = n.slice(0, e + 1).join(" ");
            var c = await axios.get("https://brat.caliphdev.com/api/brat?text=" + encodeURIComponent(p), { responseType: "arraybuffer" }).catch(e => e.response);
            if (c.status !== 200) throw new Error(`Gagal mengambil data dari API: ${c.statusText}`);
            
            var l = path.join(i, `frame${e}.mp4`);
            fs.writeFileSync(l, c.data);
            s.push(l);
        }

        var f = path.join(i, "filelist.txt");
        let t = "";
        for (let e = 0; e < s.length; e++) {
            t += `file '${s[e]}'\nduration 0.7\n`;
        }
        t += `file '${s[s.length - 1]}'\nduration 2\n`;
        fs.writeFileSync(f, t);

        var h = path.join(i, "output.mp4");
        execSync(`ffmpeg -y -f concat -safe 0 -i ${f} -vf "fps=30" -c:v libx264 -preset ultrafast -pix_fmt yuv420p ${h}`);
        
        // Pastikan file output ada sebelum dibaca
        if (!fs.existsSync(h)) throw new Error("Output video tidak ditemukan.");

        var videoBuffer = fs.readFileSync(h);
        var m = await mp4ToWebp(videoBuffer, { pack: global.packname, author: global.author });

        r.sendFile(a.chat, m, "sticker.webp", o, a);
        
        // Menghapus file yang telah digunakan
        s.forEach(e => { fs.existsSync(e) && fs.unlinkSync(e); });
        fs.existsSync(f) && fs.unlinkSync(f);
        fs.existsSync(h) && fs.unlinkSync(h);
    } catch (e) {
        r.reply(a.chat, `Maaf, terjadi kesalahan saat mengambil output.\n- ${e.message}`, a);
    }
};

async function mp4ToWebp(buffer, options) {
    options = options || { pack: "‎", author: "‎", crop: false };
    const data = {
        file: "data:video/mp4;base64," + buffer.toString("base64"),
        processOptions: {
            crop: options.crop,
            startTime: "00:00:00.0",
            endTime: "00:00:07.0",
            loop: 0
        },
        stickerMetadata: { ...options }
    };

    const response = await fetch("https://sticker-api.openwa.dev/convertMp4BufferToWebpDataUrl", {
        method: "POST",
        headers: {
            Accept: "application/json, text/plain, */*",
            "Content-Type": "application/json;charset=utf-8"
        },
        body: JSON.stringify(data)
    });

    if (!response.ok) throw new Error("Gagal mengkonversi video ke webp.");

    const responseData = await response.text();
    return Buffer.from(responseData.split(";base64,")[1], "base64");
}

handler.help = handler.command = ["bratvideo"];
handler.tags = ["tools"];
export default handler;
Assistant: