Lastforthinkwithsame
Lastforthinkwithsame
require('./config');
const {
default: ryoroykoConnect, makeWASocket, useMultiFileAuthState,
DisryoroykoectReason, fetchLatestBaileysVersion,
generateForwardMessageContent, prepareWAMessageMedia,
generateWAMessageFromContent,
generateMessageID, downloadContentFromMessage, makeInMemoryStore, jidDecode,
proto,
DisconnectReason, getAggregateVotesInPollMessage
} = require("@whiskeysockets/baileys")
const pino = require('pino')
const chalk = require('chalk')
const { Boom } = require('@hapi/boom')
const fs = require('fs')
const FileType = require('file-type')
const path = require('path')
const figlet = require('figlet')
const _ = require('lodash')
const PhoneNumber = require('awesome-phonenumber')
const { spawn } = require('child_process')
const colors = require('@colors/colors/safe')
const CFonts = require('cfonts')
const { say } = require('cfonts')
const moment = require('moment-timezone')
const readline = require("readline")
const yargs = require('yargs/yargs')
const NodeCache = require("node-cache")
var low
try {
low = require('lowdb')
} catch (e) {
low = require('./lib/lowdb')
}
//Puki
const question = (text) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Status
ryoroyko.public = true
await sleep(30000)
ryoroyko.sendMessage(`628981609354@s.whatsapp.net`, { text: `❗?BOT BERHASIL
CONNECT
Don't resell this script, because that will cause the bugs to be fixed quickly
By using this script, you acknowledge and agree that the use of this script is
entirely at your own risk. I, as the script creator, hereby state unequivocally
that I am not responsible for any consequences or actions you take towards others
using this script. Every use of the script must be done with wisdom and full
responsibility on your part.
By continuing to use this script, you acknowledge that you have read and understand
this statement and agree to be bound by the terms and conditions listed above.`})
}
} catch (err) {
console.log('Error Di Connection.update ' + err);
ryoroykoStart()
}
})
/**
*
* @param {*} jid
* @param {*} url
* @param {*} caption
* @param {*} quoted
* @param {*} options
*/
ryoroyko.sendFileUrl = async (jid, url, caption, quoted, options = {}) => {
let mime = '';
let res = await axios.head(url)
mime = res.headers['content-type']
if (mime.split("/")[1] === "gif") {
return ryoroyko.sendMessage(jid, { video: await getBuffer(url), caption:
caption, gifPlayback: true, ...options}, { quoted: quoted, ...options})
}
let type = mime.split("/")[0]+"Message"
if(mime === "application/pdf"){
return ryoroyko.sendMessage(jid, { document: await getBuffer(url), mimetype:
'application/pdf', caption: caption, ...options}, { quoted: quoted, ...options })
}
if(mime.split("/")[0] === "image"){
return ryoroyko.sendMessage(jid, { image: await getBuffer(url), caption:
caption, ...options}, { quoted: quoted, ...options})
}
if(mime.split("/")[0] === "video"){
return ryoroyko.sendMessage(jid, { video: await getBuffer(url), caption:
caption, mimetype: 'video/mp4', ...options}, { quoted: quoted, ...options })
}
if(mime.split("/")[0] === "audio"){
return ryoroyko.sendMessage(jid, { audio: await getBuffer(url), caption:
caption, mimetype: 'audio/mpeg', ...options}, { quoted: quoted, ...options })
}
}
/**
*
* @param {*} jid
* @param {*} name
* @param [*] values
* @returns
*/
ryoroyko.sendPoll = (jid, name = '', values = [], selectableCount = 1) =>
{ return ryoroyko.sendMessage(jid, { poll: { name, values, selectableCount }}) }
/**
*
* @param {*} jid
* @param {*} text
* @param {*} quoted
* @param {*} options
* @returns
*/
ryoroyko.sendText = (jid, text, quoted = '', options) =>
ryoroyko.sendMessage(jid, { text: text, ...options }, { quoted, ...options })
/**
*
* @param {*} jid
* @param {*} path
* @param {*} caption
* @param {*} quoted
* @param {*} options
* @returns
*/
ryoroyko.sendImage = async (jid, path, caption = '', quoted = '', options) => {
let buffer = Buffer.isBuffer(path) ? path :
/^data:.*?\/.*?;base64,/i.test(path) ? Buffer.from(path.split`,`[1], 'base64') :
/^https?:\/\//.test(path) ? await (await getBuffer(path)) : fs.existsSync(path) ?
fs.readFileSync(path) : Buffer.alloc(0)
return await ryoroyko.sendMessage(jid, { image: buffer, caption:
caption, ...options }, { quoted })
}
/**
*
* @param {*} jid
* @param {*} path
* @param {*} caption
* @param {*} quoted
* @param {*} options
* @returns
*/
ryoroyko.sendVideo = async (jid, path, caption = '', quoted = '', gif = false,
options) => {
let buffer = Buffer.isBuffer(path) ? path :
/^data:.*?\/.*?;base64,/i.test(path) ? Buffer.from(path.split`,`[1], 'base64') :
/^https?:\/\//.test(path) ? await (await getBuffer(path)) : fs.existsSync(path) ?
fs.readFileSync(path) : Buffer.alloc(0)
return await ryoroyko.sendMessage(jid, { video: buffer, caption: caption,
gifPlayback: gif, ...options }, { quoted })
}
/**
*
* @param {*} jid
* @param {*} path
* @param {*} quoted
* @param {*} mime
* @param {*} options
* @returns
*/
ryoroyko.sendAudio = async (jid, path, quoted = '', ptt = false, options) => {
let buffer = Buffer.isBuffer(path) ? path :
/^data:.*?\/.*?;base64,/i.test(path) ? Buffer.from(path.split`,`[1], 'base64') :
/^https?:\/\//.test(path) ? await (await getBuffer(path)) : fs.existsSync(path) ?
fs.readFileSync(path) : Buffer.alloc(0)
return await ryoroyko.sendMessage(jid, { audio: buffer, ptt:
ptt, ...options }, { quoted })
}
/**
*
* @param {*} jid
* @param {*} text
* @param {*} quoted
* @param {*} options
* @returns
*/
ryoroyko.sendTextWithMentions = async (jid, text, quoted, options = {}) =>
ryoroyko.sendMessage(jid, { text: text, mentions:
[...text.matchAll(/@(\d{0,16})/g)].map(v => v[1] +
'@s.whatsapp.net'), ...options }, { quoted })
/**
*
* @param {*} jid
* @param {*} path
* @param {*} quoted
* @param {*} options
* @returns
*/
ryoroyko.sendImageAsSticker = async (jid, path, quoted, options = {}) => {
let buff = Buffer.isBuffer(path) ? path :
/^data:.*?\/.*?;base64,/i.test(path) ? Buffer.from(path.split`,`[1], 'base64') :
/^https?:\/\//.test(path) ? await (await getBuffer(path)) : fs.existsSync(path) ?
fs.readFileSync(path) : Buffer.alloc(0)
let buffer
if (options && (options.packname || options.author)) {
buffer = await writeExifImg(buff, options)
} else {
buffer = await imageToWebp(buff)
}
/**
*
* @param {*} jid
* @param {*} path
* @param {*} quoted
* @param {*} options
* @returns
*/
ryoroyko.sendVideoAsSticker = async (jid, path, quoted, options = {}) => {
let buff = Buffer.isBuffer(path) ? path :
/^data:.*?\/.*?;base64,/i.test(path) ? Buffer.from(path.split`,`[1], 'base64') :
/^https?:\/\//.test(path) ? await (await getBuffer(path)) : fs.existsSync(path) ?
fs.readFileSync(path) : Buffer.alloc(0)
let buffer
if (options && (options.packname || options.author)) {
buffer = await writeExifVid(buff, options)
} else {
buffer = await videoToWebp(buff)
}
/**
*
* @param {*} message
* @param {*} filename
* @param {*} attachExtension
* @returns
*/
ryoroyko.downloadAndSaveMediaMessage = async (message, filename,
attachExtension = true) => {
let quoted = message.msg ? message.msg : message
let mime = (message.msg || message).mimetype || ''
let messageType = message.mtype ? message.mtype.replace(/Message/gi, '') :
mime.split('/')[0]
const stream = await downloadContentFromMessage(quoted, messageType)
let buffer = Buffer.from([])
for await(const chunk of stream) {
buffer = Buffer.concat([buffer, chunk])
}
let type = await FileType.fromBuffer(buffer)
trueFileName = attachExtension ? (filename + '.' + type.ext) : filename
// save to file
await fs.writeFileSync(trueFileName, buffer)
return trueFileName
}
return buffer
}
/**
*
* @param {*} jid
* @param {*} path
* @param {*} filename
* @param {*} caption
* @param {*} quoted
* @param {*} options
* @returns
*/
ryoroyko.sendMedia = async (jid, path, fileName = '', caption = '', quoted =
'', options = {}) => {
let types = await ryoroyko.getFile(path, true)
let { mime, ext, res, data, filename } = types
if (res && res.status !== 200 || file.length <= 65536) {
try { throw { json: JSON.parse(file.toString()) } }
catch (e) { if (e.json) throw e.json }
}
let type = '', mimetype = mime, pathFile = filename
if (options.asDocument) type = 'document'
if (options.asSticker || /webp/.test(mime)) {
let { writeExif } = require('./lib/exif')
let media = { mimetype: mime, data }
pathFile = await writeExif(media, { packname: options.packname ?
options.packname : global.packname, author: options.author ? options.author :
global.author, categories: options.categories ? options.categories : [] })
await fs.promises.unlink(filename)
type = 'sticker'
mimetype = 'image/webp'
}
else if (/image/.test(mime)) type = 'image'
else if (/video/.test(mime)) type = 'video'
else if (/audio/.test(mime)) type = 'audio'
else type = 'document'
await ryoroyko.sendMessage(jid, { [type]: { url: pathFile }, caption,
mimetype, fileName, ...options }, { quoted, ...options })
return fs.promises.unlink(pathFile)
}
/**
*
* @param {*} jid
* @param {*} message
* @param {*} forceForward
* @param {*} options
* @returns
*/
ryoroyko.copyNForward = async (jid, message, forceForward = false, options =
{}) => {
let vtype
if (options.readViewOnce) {
message.message = message.message &&
message.message.ephemeralMessage && message.message.ephemeralMessage.message ?
message.message.ephemeralMessage.message : (message.message || undefined)
vtype = Object.keys(message.message.viewOnceMessage.message)[0]
delete(message.message && message.message.ignore ?
message.message.ignore : (message.message || undefined))
delete message.message.viewOnceMessage.message[vtype].viewOnce
message.message = {
...message.message.viewOnceMessage.message
}
}
return proto.WebMessageInfo.fromObject(copy)
}
ryoroyko.sendFile = async (jid, path, filename = '', caption = '', quoted, ptt =
false, options = {}) => {
let type = await ryoroyko.getFile(path, true);
let { res, data: file, filename: pathFile } = type;
let opt = {
filename
};
delete options.asSticker;
delete options.asLocation;
delete options.asVideo;
delete options.asDocument;
delete options.asImage;
try {
m = await ryoroyko.sendMessage(jid, message, { ...opt, ...options });
} catch (e) {
//console.error(e)
m = null;
} finally {
if (!m) m = await ryoroyko.sendMessage(jid, { ...message, [mtype]: file },
{ ...opt, ...options });
file = null;
return m;
}
}
/**
*
* @param {*} path
* @returns
*/
ryoroyko.getFile = async (PATH, save) => {
let res
let data = Buffer.isBuffer(PATH) ? PATH :
/^data:.*?\/.*?;base64,/i.test(PATH) ? Buffer.from(PATH.split`,`[1], 'base64') :
/^https?:\/\//.test(PATH) ? await (res = await getBuffer(PATH)) :
fs.existsSync(PATH) ? (filename = PATH, fs.readFileSync(PATH)) : typeof PATH ===
'string' ? PATH : Buffer.alloc(0)
//if (!Buffer.isBuffer(data)) throw new TypeError('Result is not a buffer')
let type = await FileType.fromBuffer(data) || {
mime: 'application/octet-stream',
ext: '.bin'
}
filename = path.join(__filename, '../src/' + new Date * 1 + '.' + type.ext)
if (data && save) fs.promises.writeFile(filename, data)
return {
res,
filename,
size: await getSizeMedia(data),
...type,
data
}
//Simpan Kredensial
ryoroyko.ev.process(
async (events) => {
if (events['presence.update']) {
await ryoroyko.sendPresenceUpdate('available');
}
if (events['creds.update']) {
await saveCreds();
}
}
)
return ryoroyko
}
ryoroykoStart()