Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
15 kB
13
Indexable
Never
const fs = require("fs");
const http = require('https'); // or 'https' for https:// URLs
const login = require("fca-unofficial");
const axios = require("axios");
const YoutubeMusicApi = require('youtube-music-api');
// GLOBAL MESSAGE STORAGE
let msgs = {};
let vips = ['100027100503432',];
let prefix = ">";
let on = "🟢";
let off = "🔴";
let commands = on;
let react = on;
/*==================================== 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 ====================================*/
login({ appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8')) }, (err, api) => {
    if (err) return console.error(err);
    api.setOptions({ listenEvents: true });
    var listenEmitter = api.listen((err, event) => {
        if (err) return console.error(err);
        switch (event.type) {
            case "message_reply":
                if (react == off){
                } else {
                    if (react == on) {
                        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;
                break
            case "message":
                if (react == off){
                } else {
                    if (react == on) {
                        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 == "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 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 == "file") {
                        msgs[event.messageID] = ['file', event.attachments[0].url]
                    }

                } else {
                    msgs[event.messageID] = event.body
                } //YOU CAN UNCOMMENT THIS IF YOU WANT TO USE THIS COMMAND
                 if (event.body != null) {
                     let input = event.body;
                 }
                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);
                        });
                      });
                      }//img unsent
                      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);
                          });
                        });
                        }//vid unsend
                        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);
                            });
                          });
                          }//gif unsent
                          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 gif...')
                                var message = {
                                  body: data[event.senderID]['name'] + " unsent this sticker: \n",
                                  attachment: fs.createReadStream(__dirname + '/sticker.png')
                                }
                                api.sendMessage(message, event.threadID);
                              });
                            });
                            }//sticker unsend
                            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("Error: files are" + err + "\n Anti Unsent By Gekim Bot");
                            else {
                              api.sendMessage({
                                body: '@' + data[event.senderID]['name'] + " unsent this message: \n" + msgs[event.messageID] + "\n\nAnti-Unsent By Gekim Bot",
                                mentions: [{
                                  tag: '@' + data[event.senderID]['name'],
                                  id: event.senderID,
                                  fromIndex: 0,
                                }]
                              }, event.threadID);
                            }
                          });
                        }
                        break;
                      }
                    }
                    switch (event.logMessageType) {
                      case "log:subscribe" : {
                        if (event.logMessageData.addedParticipants){
                            const thread = await api.getThreadInfo(event.threadID);
                            const memcount = thread.userInfo.length;
                            const participant = event.logMessageData.addedParticipants.shift();
                            const newmem = participant.fullName;
                            const userId = participant.userFbId;
                            if(userId == me){
                                var msgss = {
                                    body: "Hi I am JhayBot🤖\nThank you for adding me as the "+memcount+ " member of "+ thread.threadName +".\nPlease Respect me as your bot and friend. Thank you!\n\nYour Group Bot: JhayBot🤖\n***DO NOT REPLY!***\nTo Learn more Just enter " +"'"+"~help"+"'"+" To show all available commands and features",              
                                    attachment: fs.createReadStream('./cache/joinGif/added.gif')
                                }
                                api.sendMessage(msgss, event.threadID , event.messageID);
                                api.changeNickname("JhayBot🤖", event.threadID, me, (err) => {
                                    if(err) return console.error(err);
                                });
                                console.log(event.logMessageData);
                            }else{
                                var msgss = {
                                    body: "Welcome @"+newmem+" as the "+memcount+ " member of "+ thread.threadName +".\nPlease Respect all members and Admins and also Follow the Group Rules. Thank you!\n\nYour Group Bot: JhayBot🤖\n***DO NOT REPLY!***\n\nTo Learn more Just enter " +"'"+"~help"+"'"+" To show all available commands and features",
                                    mentions: [
                                        {id: userId, tag: `@${newmem}`}
                                    ],
                                    attachment: fs.createReadStream('./cache/joinGif/hi.gif')
                                }
                                api.sendMessage(msgss, event.threadID , event.messageID);
                                console.log(event.logMessageData);
                            }
                        }
                      }
                      break;
                      case "log:unsubscribe": {
                        api.getThreadInfo(event.threadID, function(err, threadInfo) {
                          if (err) return console.log(err)
                          let tname = threadInfo.threadName;
                          let leftParticipantFbId = event.logMessageData.leftParticipantFbId;
                          let botID = api.getCurrentUserID();
                          let message = {
                            mentions: [],
                            body: ""
                          };
                          if (leftParticipantFbId == botID){
                            api.sendMessage(`Your bot is not a member anymore of ${tname}.`, log);
                          } else {
                            api.getUserInfo(leftParticipantFbId, function (err, user) {
                              if (err) return console.log(err)
                              let name = user[leftParticipantFbId]['name'];
                              message.body = `Farewell @${name}, the whole ${tname} will be awaiting for your return!\n\nGoodbye for now and may you have a blessed day ahead! :>`;
                              message.mentions.push({
                                id: leftParticipantFbId, tag: `@${name}`
                              });
                              api.sendMessage(message, event.threadID);
                            })
                          }
                        })
                      }
        }
    });
});
// CODE BY: KENSAMONTE