Kim Ji Bot

Lmao
mail@pastecode.io avatar
unknown
aql
2 years ago
29 kB
3
Indexable
Never
const Innertube = require('youtubei.js');
const fs = require("fs");
const { keep_alive } = require("./keep_alive.js");
const http = require('https'); // or 'https' for https:// URLs
const login = require("fca-unofficial");
const axios = require("axios");
const YoutubeMusicApi = require('youtube-music-api')
const google = require("googlethis");
const ytdl = require('ytdl-core');
const ffmpeg = require('@ffmpeg-installer/ffmpeg');
const ffmpegs = require('fluent-ffmpeg');
ffmpegs.setFfmpegPath(ffmpeg.path);
const musicApi = new YoutubeMusicApi()
// GLOBAL MESSAGE STORAGE
let msgs = {};
let vips = ['100056442565207', '100063176375996', '100083133669244'];
let cd = {};

/*==================================== LEECH tiktok FUNC ====================================*/

async function leechTT(link) {
    out = await axios.get("https://www.tiktokdownloader.org/check.php?v=" + link).then((response) => { return response.data.download_url }).catch((error) => { return "err" })
    return out
}
/*==================================== LEECH tiktok FUNC ====================================*/

/*==================================== LEECH MP3 FUNC ====================================*/
async function conv(v, t, e) {
    const headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'X-Requested-Key': 'de0cfuirtgf67a'
    }
    results = await axios.post("https://backend.svcenter.xyz/api/convert-by-45fc4be8916916ba3b8d61dd6e0d6994", "v_id=" + v + "&ftype=mp3&fquality=128&token=" + t + "&timeExpire=" + e + "&client=yt5s.com", { headers: headers }).then((response) => { return response.data.d_url }).catch((error) => { return error.message });
    return results
}
async function fetch(query) {
    const headers = {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
    results = await axios.post("https://yt5s.com/api/ajaxSearch", "q=" + query + "&vt=mp3", { headers: headers }).then((response) => { return response.data }).catch((error) => { return error.message });
    return results
}

async function leechmp3(query) {
    var songs = fetch(query);
    let resp = await songs.then((response) => {
        let slist = response;
        if (slist == "err") {
            return "err"
        }
        else if (slist.t < 1300) {
            let d_url = conv(slist.vid, slist.token, slist.timeExpires).then((response) => {
                return [response, slist.title]
            });
            return d_url
        }
        else if (slist.p == "search") {
            return 'err'
        }
        else if (slist.mess.startsWith("The video you want to download is posted on TikTok.")) {
            return 'tiktok'
        }
        else {
            return 'pakyo'
        }
    });
    return resp
}

/*==================================== LEECH MP3 FUNC ====================================*/

/*==================================== RANDOM QOUTES FUNC ====================================*/

async function getWiki(q) {
  out = await axios.get("https://en.wikipedia.org/api/rest_v1/page/summary/" + q).then((response) => { return response.data}).catch((error) => { return error })
  return out
}
async function qt() {
    let qoute = await axios.get("https://zenquotes.io/api/random").then((response) => { return response.data[0] }).catch((err) => { return "err " });
    return qoute
}
/*==================================== RANDOM QOUTES FUNC ====================================*/

/*======================================== BIBLE VERSE ============================================*/

async function verse(){
    let v = await axios.get("http://labs.bible.org/api/?passage=random&type=json").then((response) => {
        return response.data[0]
    }).catch((err) => {
        return "Error"
    })
    return v
}

/*====================================== BIBLE VERSE ==============================================*/

login({ appState: JSON.parse(fs.readFileSync('fbstate.json', 'utf8')) }, (err, api) => {
    if (err) return console.error(err);
    api.setOptions({ listenEvents: true, selfListen: true });
    const listenEmitter = api.listen(async (err, event) => {
        if (err) return console.error(err);
        switch (event.type) {
            case "message_reply":
 if (vips.includes(event.senderID)) {
                     api.setMessageReaction("😘", event.messageID, (err) => {
                  }, true);
                }
               // else {
                    // api.setMessageReaction("😆", //event.messageID, (err) => {
                 //   }, true);
              //  }
                let msgid = event.messageID
                let input = event.body;
                msgs[msgid] = input;
                
                if (input.startsWith("+redeem")) {
                    let data = input.split(" ");
                    if (data.length < 3) {
                        api.sendMessage("❌Invalid Use Of Command!\n💡Usage: redeem id vcode", event.threadID);
                    } else {
                        try {
                            let gameid = data[1];
                            let vcode = data[2];
                            let code = event.messageReply.body;
                            function redeem(gameid, vcode, code) {
                                (async () => {
                                    try {
                                        const response = await axios.post('https://api.mobilelegends.com/mlweb/sendCdk', { "redeemCode": code, "roleId": gameid, "vCode": vcode, "language": "en" });
                                        const msgs = ('{"-20023": "Invalid Game ID","-20027":"Request too Frequent!...","-20010":"Invalid Verification Code!","0":"Redeemed Successfully!","1401":"redeem in specified zone","1402":"This CDKey does not exist","1403":"CDKey expired","1404":"Incorrect format of CDKey","1405":"This CDKey has been redeemed.","1406":"Bound Account CDKey. Incorrect account.","1407":"Exceeds exchange amount limit.","1408":"Can only redeem in specified zone.","1409":"Restriction Requirement Configuration Error","1410":"This CDKey is being redeemed by many players. The Server is processing... Please try again later.","1411":"It\'s not exchange time, please wait.","1412":"Limit reached for number of people exchanging.","1413":"You are not a new user","1414":"You haven\'t purchased yet","1415":"Your level is too high","1416":"You can not redeem the CDKey through your channel","1036":"The amount limitation of CDKey redeemption"}');
                                        let responses = JSON.parse(msgs);
                                        let resp = response.data.code;
                                        let respcode = resp.toString();
                                        let msg = responses[respcode];
                                        let stat = response.data.status;
                                        api.sendMessage("💠Kevz Bot x Redeemer💠\n\n🆔Game Id: " + gameid + "\n🔰Status: " + stat + "\n📧Message: " + msg + "", event.threadID);
                                    } catch (error) {
                                        console.log(error.message);
                                    }
                                })();
                            }
                            api.sendMessage("🔁Trying to Redeem...(" + code + ")", event.threadID);
                            redeem(gameid, vcode, code);
                        } catch (err) {
                            api.sendMessage("❌Error: " + err.message, event.threadID);
                        }
                    }
                }

                break
            case "message":
if (vips.includes(event.senderID)) {
                     api.setMessageReaction("😘", event.messageID, (err) => {
                  }, true);
                }
              //  else {
                    // api.setMessageReaction("😆", //event.messageID, (err) => {
                  //  }, true);
             //    }
                if (event.attachments.length != 0) {
                    if (event.attachments[0].type == "photo") {
                        msgs[event.messageID] = ['img', event.attachments[0].url]
                    }
                    else if (event.attachments[0].type == "animated_image") {
                        msgs[event.messageID] = ['gif', event.attachments[0].url]
                    }
                     else if (event.attachments[0].type == "sticker") {
                        msgs[event.messageID] = ['sticker', event.attachments[0].url]
                    }
                    else if (event.attachments[0].type == "video") {
                        msgs[event.messageID] = ['vid', event.attachments[0].url]
                    }
                    else if (event.attachments[0].type == "audio") {
                        msgs[event.messageID] = ['vm', event.attachments[0].url]
                    }
                } else {
                    msgs[event.messageID] = event.body
                }
                if (event.body != null) {
                    let input = event.body;


// THIS BOT IS EXPEREMENTAL MADE BY KEVZ CREDITS TO EARL!
if (input.startsWith("+help")) {
 
                        let data = input.split(" ");
                        if (data.length < 2) {
                        api.getUserID("Zodiac.lang.malakas", (err,data) =>{
                                api.sendMessage({
                                    body: "List of Commands\n\nPrefix: +\n\n+music (music title)\n\n+leech (yt link)\n\n+tiktokdl (tiktok link)\n\n+wiki (word)\n\n+meme\n\n+info\n\n\nMade by:  " + '@Nerf Kevz'+ "" + "\n\n\n",
                                    mentions: [{
                                        tag: '@Kim Ji Bot',
                                        id: data[0].userID,
                                    }]
                                }, event.threadID,event.messageID);
                            });
                       }
                  }
                   
else if (input.startsWith(">info")) {
 
                        let data = input.split(" ");
                        if (data.length < 2) {
                        api.getUserID("Zodiac.lang.malakas", (err,data) =>{
                                api.sendMessage({
                                    body: "📄Test Bot📄\n\n🛡Created by:  " + '@Nerf Kevz'+ "\n📜Description: Test Bot is a Facebook messenger chat bot made using NodeJS, Axios and the Unofficial Facebook Chat API. This bot is for test and expermental purpose only. Credits to all Who help in making this.\n\n\n" + "\n\n\n",
                                    mentions: [{
                                        tag: '@Kim Ji Bot',
                                        id: data[0].userID,
                                    }]
                                }, event.threadID,event.messageID);
                            });
                            
                            }
                            }

else if(input.startsWith("+verse")){
                                    let v = verse()
                                    v.then((response) => {
                                        api.sendMessage("From the book of " + response.bookname + " chapter " + response.chapter + " verse " + response.verse + "\n\n" + response.text, event.threadID)
                                    }).catch((err) => {
                                        console.log(err)
                                    })

                                    }


else if (input.startsWith("+meme")){
                                
          axios.get('https://meme-api.herokuapp.com/gimme/memes')
                  .then(response => {
                    var mention = Object.keys(event.mentions)[0];
                     var file = fs.createWriteStream("memes.png");
                     var targetUrl = response.data.url;
                     var gifRequest = http.get(targetUrl, function (gifResponse) {
                        gifResponse.pipe(file);
                        file.on('finish', function () {
                           console.log('Memes Downloading!')
                           var message = {
                              body: response.data.title + "\n\nAuthor: " + response.data.author,
                              attachment: fs.createReadStream(__dirname + '/memes.png')
                           }
                           api.sendMessage(message, event.threadID, event.messageID);
                           api.setMessageReaction("✅", event.messageID, (err) => {}, true);
                        });
                     });
                  })
                  .catch(error => {
                     api.sendMessage("Failed to generate Memes, please try again!", event.threadID, event.messageID);
                  }) 

}                                 
else if (input.startsWith("+music")){
  
var text = input;     
text = text.substring(7)
let data = input.split(" ")

if (data.length < 2) {
                                api.sendMessage("⚠️Invalid Use Of Command!\n💡Usage: +music <name of video>", event.threadID);
                                      }else{if (!(vips.includes(event.senderID))) {
                                if (!(event.senderID in cd)) {
                                    cd[event.senderID] = Math.floor(Date.now() / 1000) + (60 * 3);
                                }
                                else if (Math.floor(Date.now() / 1000) < cd[event.senderID]) {
                                    api.sendMessage("⏱️Opps you're going to fast! Wait for " + Math.floor((cd[event.senderID] - Math.floor(Date.now() / 1000)) / 60) + " mins and " + (cd[event.senderID] - Math.floor(Date.now() / 1000)) % 60 + " seconds", event.threadID, event.messageID);
return
   }
else {                                  cd[event.senderID] = Math.floor(Date.now() / 1000) + (60 * 3);
                                }
 }data.shift()
const youtube = await new Innertube();
  const search = await youtube.search(text);
if (search.videos[0] === undefined){api.sendMessage("Error: Invalid request.",event.threadID,event.messageID);}else{api.sendMessage("🔁Connecting to YouTube!", event.threadID,event.messageID);

var timeleft = 3;
var downloadTimer = setInterval(function(){
  if(timeleft <= 0){
    clearInterval(downloadTimer);
    api.sendMessage("A music has found!\n\n⬇️Starting to Download", event.threadID, event.messageID);
    }
  timeleft -= 1;
}, 1000);
  const stream = youtube.download(search.videos[0].id, { 
    format: 'mp3',
    quality: '480p', 
    type: 'videoandaudio',
    bitrate: '2500',
    audioQuality: 'highest',
    loudnessDB: '20',
    audioBitrate: '550', 
    fps: '30'
      });
    stream.pipe(fs.createWriteStream(__dirname + '/audio.mp3'));
 
  stream.on('start', () => {
    console.info('[DOWNLOADER]', 'Starting download now!');
  }); 
  stream.on('info', (info) => {
    console.info('[DOWNLOADER]',`Downloading ${info.video_details.title} by ${info.video_details.metadata.channel_name}`);
  });
  stream.on('end', () => {console.info('[DOWNLOADER]','Done!')
    var message = {
          body:("💠Kim Ji Bot x YT Music Downloader💠\n\n"+search.videos[0].title),
         attachment:[ 
fs.createReadStream(__dirname + '/audio.mp3')]}
           api.sendMessage(message, event.threadID,event.messageID).catch((err)=> api.sendMessage("⚠️[ERR]: "+err,event.threadID,event.messageID) );
  }); stream.on('error', (err)=> console.error('[ERROR]',err));
}}}
                
   
                   else if (input.startsWith("+leech")) {
                        let data = input.split(" ");
                        if (data.length < 2) {
                            api.sendMessage("⚠️Invalid Use Of Command!\n💡Usage: +leech yt_url", event.threadID);
                        } else {
                            api.sendMessage("🔃Trying to Download...", event.threadID, event.messageID);
                            try {
                                let s = leechmp3(data[1]);
                                s.then((response) => {
                                    if (response == "pakyo") {
                                        api.setMessageReaction("🖕🏾", event.messageID, (err) => {
                                        }, true);
                                        api.sendMessage("TANGINA MO PAKYOOO😠\nULOL 20mins Max Duration Only!😝", event.threadID, event.messageID);
                                    }
                                    else if (response == "err") {
                                        api.sendMessage("❌Invalid Input", event.threadID, event.messageID);
                                        api.setMessageReaction("😭", event.messageID, (err) => {

                                        }, true);
                                    }
                                    else if (response == "tiktok") {
                                        api.sendMessage("❌Youtube Only, Bawal Tiktok!", event.threadID, event.messageID);
                                        api.setMessageReaction("😡", event.messageID, (err) => {

                                        }, true);
                                    }
                                    else if (response[0] != undefined) {
                                        var file = fs.createWriteStream("song.mp3");
                                        var targetUrl = response[0];
                                        var gifRequest = http.get(targetUrl, function (gifResponse) {
                                            gifResponse.pipe(file);
                                            file.on('finish', function () {
                                                console.log('finished downloading..')
                                                api.sendMessage('✅Download Complete! Uploading...', event.threadID)
                                                var message = {
                                                    body: "Here's what ya ordered!\n\n🎶Song Title: " + response[1] + "\n\nEnjoy your meal!",
                                                    attachment: fs.createReadStream(__dirname + '/song.mp3')
                                                }
                                                api.sendMessage(message, event.threadID);
                                            });
                                        });
                                    }
                                });
                            } catch (err) {
                                api.sendMessage("⚠️Error: " + err.message, event.threadID);
                            }
                        }
                    }
                    else if (input.startsWith("+tiktokdl")) {
                        let data = input.split(" ");
                        if (data.length < 2) {
                            api.sendMessage("⚠️Invalid Use Of Command!\n💡Usage: +tiktok vid_url", event.threadID);
                        } else {
                            api.sendMessage("🔃Trying to Download...", event.threadID, event.messageID);
                            try {
                                let s = leechTT(data[1]);
                                s.then((response) => {
                                    if (response == "err") {
                                        api.sendMessage("❌Invalid Input", event.threadID, event.messageID);
                                        api.setMessageReaction("😭", event.messageID, (err) => {

                                        }, true);
                                    }
                                    else {
                                        var file = fs.createWriteStream("tiktok.mp4");
                                        var targetUrl = response;
                                        var gifRequest = http.get(targetUrl, function (gifResponse) {
                                            gifResponse.pipe(file);
                                            file.on('finish', function () {
                                                console.log('finished downloading..')
                                                api.sendMessage('✅Download Complete! Uploading...', event.threadID)
                                                var message = {
                                                    body: "Here's what ya ordered!\n\nEnjoy your meal!",
                                                    attachment: fs.createReadStream(__dirname + '/tiktok.mp4')
                                                }
                                                api.sendMessage(message, event.threadID);
                                            });
                                        });
                                    }
                                });
                            } catch (err) {
                                api.sendMessage("⚠️Error: " + err.message, event.threadID);
                            }
                        }

                    }
                    else if (input.startsWith("+wiki")) {
                        
                        let data = input.split(" ");
                        if (data.length < 2) {
                            api.sendMessage("⚠️Invalid Use Of Command!\n💡Usage: +wiki word", event.threadID);
                        } else {
                            try {
                                data.shift()
                                var txtWiki = "";
                                let res = await getWiki(data.join(" "));
                                if(res === undefined){
                                    throw new Error(`API RETURNED THIS: ${res}`)
                                }
                                if(res.title === undefined) {
                                  throw new Error(`API RETURNED THIS: ${res}`)
                                }
                                txtWiki += `🔎You search the word ${res.title} \n\nTimeStamp: ${res.timestamp}\n\n💡Description: ${res.description}\n\n💡Info: ${res.extract}`
                                
                                api.sendMessage(`${txtWiki}`, event.threadID, event.messageID);
                            }
                            catch (err) {
                                api.sendMessage(`⚠️${err.message}`, event.threadID, event.messageID);
                            }
                        }
                    }
                    else if (input.startsWith("+motivation")) {
                        let rqt = qt();
                        rqt.then((response) => {
                            api.sendMessage(response.q + "\n- " + response.a, event.threadID, event.messageID);
                        })
                    }
                }
                break;
            case "message_unsend":
                if (!vips.includes(event.senderID)) {
                    let d = msgs[event.messageID];
                    if (typeof (d) == "object") {
                        api.getUserInfo(event.senderID, (err, data) => {
                            if (err) return console.error(err);
                            else {
                                if (d[0] == "img") {
                                    var file = fs.createWriteStream("photo.jpg");
                                    var gifRequest = http.get(d[1], function (gifResponse) {
                                        gifResponse.pipe(file);
                                        file.on('finish', function () {
                                            console.log('finished downloading photo..')
                                            var message = {
                                                body: data[event.senderID]['name'] + " unsent this photo: \n",
                                                attachment: fs.createReadStream(__dirname + '/photo.jpg')
                                            }
                                            api.sendMessage(message, event.threadID);
                                        });
                                    });
                                }
                                else if (d[0] == "gif") {
                                    var file = fs.createWriteStream("animated_image.gif");
                                    var gifRequest = http.get(d[1], function (gifResponse) {
                                        gifResponse.pipe(file);
                                        file.on('finish', function () {
                                            console.log('finished downloading gif..')
                                            var message = {
                                                body: data[event.senderID]['name'] + " unsent this GIF: \n",
                                                attachment: fs.createReadStream(__dirname + '/animated_image.gif')
                                            }
                                            api.sendMessage(message, event.threadID);
                                        });
                                    });
                                }
                                else if (d[0] == "sticker") {
                                    var file = fs.createWriteStream("sticker.png");
                                    var gifRequest = http.get(d[1], function (gifResponse) {
                                        gifResponse.pipe(file);
                                        file.on('finish', function () {
                                            console.log('finished downloading sticker..')
                                            var message = {
                                                body: data[event.senderID]['name'] + " unsent this Sticker: \n",
                                                attachment: fs.createReadStream(__dirname + '/sticker.png')
                                            }
                                            api.sendMessage(message, event.threadID);
                                        });
                                    });
                                }
                                else if (d[0] == "vid") {
                                    var file = fs.createWriteStream("video.mp4");
                                    var gifRequest = http.get(d[1], function (gifResponse) {
                                        gifResponse.pipe(file);
                                        file.on('finish', function () {
                                            console.log('finished downloading video..')
                                            var message = {
                                                body: data[event.senderID]['name'] + " unsent this video: \n",
                                                attachment: fs.createReadStream(__dirname + '/video.mp4')
                                            }
                                            api.sendMessage(message, event.threadID);
                                        });
                                    });
                                }
                                else if (d[0] == "vm") {
                                    var file = fs.createWriteStream("vm.mp3");
                                    var gifRequest = http.get(d[1], function (gifResponse) {
                                        gifResponse.pipe(file);
                                        file.on('finish', function () {
                                            console.log('finished downloading audio..')
                                            var message = {
                                                body: data[event.senderID]['name'] + " unsent this audio: \n",
                                                attachment: fs.createReadStream(__dirname + '/vm.mp3')
                                            }
                                            api.sendMessage(message, event.threadID);
                                        });
                                    });
                                }
                            }
                        });
                    }
                    else {
                        api.getUserInfo(event.senderID, (err, data) => {
                            if (err) return console.error(err);
                            else {
                                api.sendMessage(data[event.senderID]['name'] + " unsent this message: \n\n" + msgs[event.messageID] + "\n\nAnti Unsent By Nerf Kevz", event.threadID);
                            }
                        });
                    }
                    break;
                }
        }
    });
});