File size: 22,440 Bytes
6c07b9a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 |
const axios = require('axios')
const { jidDecode, delay, generateWAMessageFromContent, proto } = require('baileys')
const id3 = require('browser-id3-writer')
const { fromBuffer } = require('file-type')
const path = require('path')
const FormData = require('form-data')
const { spawn } = require('child_process')
const { default: fetch } = require('node-fetch')
let { JSDOM } = require('jsdom')
const cheerio = require('cheerio')
const { commands } = require('./plugins')
const config = require('../config')
const jsQR = require('jsqr')
const fs = require('fs')
const jimp = require('jimp')
const { loadMessage } = require('./database/StoreDb')
const { tmpdir } = require('os')
const { exec } = require('child_process')
const streamBuffers = require('stream-buffers')
const { URLSearchParams } = require('url')
async function editAudio(message, effect = 'bass', options = '') {
if (!message.quoted) {
return await message.send('*Reply to audio*')
}
let mediaType = message.quoted.mtype || message.mtype
if (!/audio/.test(mediaType)) {
return await message.send('*_Reply Audio_*', {}, '', options)
}
let filterCommand = '-af equalizer=f=54:width_type=o:width=2:g=20'
switch (effect.toLowerCase()) {
case 'bass':
filterCommand = '-af equalizer=f=54:width_type=o:width=2:g=20'
break
case 'blown':
filterCommand = '-af acrusher=.1:1:64:0:log'
break
case 'deep':
filterCommand = '-af atempo=4/4,asetrate=44500*2/3'
break
case 'earrape':
filterCommand = '-af volume=12'
break
case 'fast':
filterCommand = '-filter:a "atempo=1.63,asetrate=44100"'
break
case 'fat':
filterCommand = '-filter:a "atempo=1.6,asetrate=22100"'
break
case 'nightcore':
filterCommand = '-filter:a atempo=1.06,asetrate=44100*1.25'
break
case 'reverse':
filterCommand = '-filter_complex "areverse"'
break
case 'robot':
filterCommand = "-filter_complex \"afftfilt=real='hypot(re,im)*sin(0)':imag='hypot(re,im)*cos(0)':win_size=512:overlap=0.75\""
break
case 'slow':
filterCommand = '-filter:a "atempo=0.7,asetrate=44100"'
break
case 'smooth':
filterCommand = '-filter:v "minterpolate=\'mi_mode=mci:mc_mode=aobmc:vsbmc=1:fps=120\'"'
break
case 'tupai':
filterCommand = '-filter:a "atempo=0.5,asetrate=65100"'
break
default:
break
}
let audioFilePath = await message.client.downloadAndSaveMediaMessage(message.quoted)
let outputFilePath = 'temp/' + (message.sender.slice(6) + effect) + '.mp3'
exec(`ffmpeg -i ${audioFilePath} ${filterCommand} ${outputFilePath}`, async (error, stdout, stderr) => {
try {
fs.unlinkSync(audioFilePath)
} catch {}
if (error) {
return message.error(error)
} else {
let editedAudio = fs.readFileSync(outputFilePath)
try {
fs.unlinkSync(outputFilePath)
} catch {}
let contextInfo = {
...(await message.bot.contextInfo('Sir ' + message.senderName + ' 🤍', '⇆ㅤ ||◁ㅤ❚❚ㅤ▷||ㅤ ⇆')),
}
return message.bot.sendMessage(
message.chat,
{
audio: editedAudio,
mimetype: 'audio/mpeg',
ptt: /ptt|voice/.test(message.test || '') ? true : false,
contextInfo: contextInfo,
},
{
quoted: message,
messageId: message.bot.messageId(),
}
)
}
})
}
const captureScreenshot = (url, device = 'desktop') => {
return new Promise((resolve, reject) => {
const screenshotApiUrl = 'https://www.screenshotmachine.com/capture.php'
const requestData = {
url,
device,
cacheLimit: 0,
}
axios
.post(screenshotApiUrl, new URLSearchParams(requestData), {
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
})
.then((response) => {
const cookies = response.headers['set-cookie']
if (response.data.status === 'success') {
axios
.get(`https://www.screenshotmachine.com/${response.data.link}`, {
headers: { cookie: cookies.join('') },
responseType: 'arraybuffer',
})
.then(({ data }) => {
resolve({ status: 200, result: data })
})
} else {
reject({
status: 404,
statusText: 'Link Error',
message: response.data,
})
}
})
.catch(reject)
})
}
async function m3u82Mp4(m3u8Url) {
return new Promise((resolve, reject) => {
const writableStreamBuffer = new streamBuffers.WritableStreamBuffer({
initialSize: 100 * 1024,
incrementAmount: 10 * 1024,
})
const tempOutputFile = 'output.mp4'
const command = `"${ffmpegPath}" -i "${m3u8Url}" -c copy "${tempOutputFile}"`
const ffmpegProcess = exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error occurred: ${error.message}`)
return reject(error)
}
// Read the resulting MP4 file into a buffer
fs.readFile(tempOutputFile, (err, data) => {
if (err) {
return reject(err)
}
writableStreamBuffer.write(data)
writableStreamBuffer.end()
fs.unlinkSync(tempOutputFile)
resolve(writableStreamBuffer.getContents())
})
})
ffmpegProcess.stderr.on('data', (data) => {
const progressLine = data.toString()
const timeMatch = progressLine.match(/time=(\d{2}:\d{2}:\d{2}\.\d{2})/)
if (timeMatch) {
const elapsedTime = timeMatch[1]
console.log(`Conversion progress: ${elapsedTime}`)
}
})
})
}
/**
* Convert a buffer to a file and save it
* @param {Buffer} buffer The buffer to convert
* @param {String} filename The name of the file
* @returns {String} The path to the saved file
* @example
* const path = await bufferToFile(buffer, 'file.txt')
* console.log(path)
*/
async function buffToFile(buffer, filename) {
if (!filename) filename = Date.now()
let { ext } = await fromBuffer(buffer)
let filePath = path.join(tmpdir(), `${filename}.${ext}`)
await fs.promises.writeFile(filePath, buffer)
return filePath
}
/**
*
* @param {Buffer} imageBuffer
* @returns {Buffer|null} [Buffer|null
*/
const removeBg = async (imageBuffer) => {
const formData = new FormData()
const inputPath = await buffToFile(imageBuffer)
formData.append('size', 'auto')
formData.append('image_file', fs.createReadStream(inputPath), path.basename(inputPath))
try {
const response = await axios({
method: 'post',
url: 'https://api.remove.bg/v1.0/removebg',
data: formData,
responseType: 'arraybuffer',
headers: {
...formData.getHeaders(),
'X-Api-Key': config.REMOVEBG,
},
encoding: null,
})
if (response.status !== 200) {
console.error('Error:', response.status, response.statusText)
return null
}
return response.data
} catch (error) {
console.error('Request failed:', error)
return null
}
}
async function validatAndSaveDeleted(client, msg) {
if (msg.type === 'protocolMessage') {
if (msg.message.protocolMessage.type === 'REVOKE') {
await client.sendMessage(msg.key.remoteJid, { text: 'Message Deleted' })
let jid = config.DELETED_LOG_CHAT
let message = await loadMessage(msg.message.protocolMessage.key.id)
const m = generateWAMessageFromContent(jid, message.message, {
userJid: client.user.id,
})
await client.relayMessage(jid, m.message, {
messageId: m.key.id,
})
return m
}
}
}
async function textToImg(text) {
try {
const words = text.split(' ')
const lines = []
let line = ''
words.forEach((word) => {
if (line.length + word.length < 30) {
line += word + ' '
} else {
lines.push(line)
line = word + ' '
}
})
lines.push(line)
text = lines.join('\n')
const font = await jimp.loadFont(jimp.FONT_SANS_64_WHITE)
const textWidth = jimp.measureText(font, text.substring(0, 35))
const textHeight = jimp.measureTextHeight(font, text)
const canvasWidth = textWidth
const canvasHeight = textHeight + -(textHeight * 0.8)
const image = new jimp(canvasWidth, canvasHeight, 0x075e54ff)
const x = 5
const y = 5
image.print(font, x, y, text, textWidth, textHeight)
image.shadow({ blur: 3, x: 6, y: 5, color: '#000000' })
const buffer = await image.getBufferAsync(jimp.MIME_PNG)
return buffer
} catch (err) {
throw new Error(err)
}
}
/**
* Reads a QR code from an image buffer.
* @param {Buffer} imageBuffer - The image buffer containing the QR code.
* @returns {string|null} The decoded QR code data, or null if no QR code was found.
*/
async function readQr(imageBuffer) {
try {
const image = await jimp.read(imageBuffer)
const { data, width, height } = image.bitmap
const code = jsQR(data, width, height)
if (code) {
return code.data
}
} catch (err) {
throw new Error(`Error reading QR code: ${err.message}`)
}
return null
}
function createInteractiveMessage(data, options = {}) {
const { jid, button, header, footer, body } = data
let buttons = []
for (let i = 0; i < button.length; i++) {
let btn = button[i]
let Button = {}
Button.buttonParamsJson = JSON.stringify(btn.params)
switch (btn.type) {
case 'copy':
Button.name = 'cta_copy'
break
case 'url':
Button.name = 'cta_url'
break
case 'location':
Button.name = 'send_location'
break
case 'address':
Button.name = 'address_message'
break
case 'call':
Button.name = 'cta_call'
break
case 'reply':
Button.name = 'quick_reply'
break
case 'list':
Button.name = 'single_select'
break
default:
Button.name = 'quick_reply'
break
}
buttons.push(Button)
}
const mess = {
viewOnceMessage: {
message: {
messageContextInfo: {
deviceListMetadata: {},
deviceListMetadataVersion: 2,
},
interactiveMessage: proto.Message.InteractiveMessage.create({
body: proto.Message.InteractiveMessage.Body.create({ ...body }),
footer: proto.Message.InteractiveMessage.Footer.create({ ...footer }),
header: proto.Message.InteractiveMessage.Header.create({ ...header }),
nativeFlowMessage: proto.Message.InteractiveMessage.NativeFlowMessage.create({
buttons: buttons,
}),
}),
},
},
}
let optional = generateWAMessageFromContent(jid, mess, options)
return optional
}
function ffmpeg(buffer, args = [], ext = '', ext2 = '') {
return new Promise(async (resolve, reject) => {
try {
let tmp = path.join(tmpdir() + '/' + new Date() + '.' + ext)
let out = tmp + '.' + ext2
await fs.promises.writeFile(tmp, buffer)
const ffmpegProcess = spawn('ffmpeg', ['-y', '-i', tmp, ...args, out])
.on('error', reject)
.on('close', async (code) => {
try {
await fs.promises.unlink(tmp)
if (code !== 0) {
reject(new Error(`FFmpeg process exited with code ${code}`))
return
}
const processedData = await fs.promises.readFile(out)
await fs.promises.unlink(out)
resolve(processedData)
} catch (e) {
reject(e)
}
})
} catch (e) {
reject(e)
}
})
}
/**
* Convert Audio to Playable WhatsApp Audio
* @param {Buffer} buffer Audio Buffer
* @param {String} ext File Extension
*/
function toAudio(buffer, ext) {
return ffmpeg(buffer, ['-vn', '-ac', '2', '-b:a', '128k', '-ar', '44100', '-f', 'mp3'], ext, 'mp3')
}
/**
* Convert Audio to Playable WhatsApp PTT
* @param {Buffer} buffer Audio Buffer
* @param {String} ext File Extension
*/
function toPTT(buffer, ext) {
return ffmpeg(buffer, ['-vn', '-c:a', 'libopus', '-b:a', '128k', '-vbr', 'on', '-compression_level', '10'], ext, 'opus')
}
/**
* Convert Audio to Playable WhatsApp Video
* @param {Buffer} buffer Video Buffer
* @param {String} ext File Extension
*/
function toVideo(buffer, ext) {
return ffmpeg(buffer, ['-c:v', 'libx264', '-c:a', 'aac', '-ab', '128k', '-ar', '44100', '-crf', '32', '-preset', 'slow'], ext, 'mp4')
}
async function getBuffer(url, options = {}) {
try {
const res = await axios({
method: 'get',
url,
headers: {
DNT: 1,
'Upgrade-Insecure-Request': 1,
},
...options,
responseType: 'arraybuffer',
})
return res.data
} catch (error) {
throw new Error(`Error: ${error.message}`)
}
}
const decodeJid = (jid) => {
if (!jid) return jid
if (/:\d+@/gi.test(jid)) {
const decode = jidDecode(jid) || {}
return decode.user && decode.server ? `${decode.user}@${decode.server}` : jid
} else {
return jid
}
}
async function FiletypeFromUrl(url) {
const buffer = await getBuffer(url)
const out = await fromBuffer(buffer)
let type
if (out) {
type = out.mime.split('/')[0]
}
return { type, buffer }
}
function extractUrlFromMessage(message) {
const urlRegex = /(https?:\/\/[^\s]+)/gi
const match = urlRegex.exec(message)
return match ? match[0] : null
}
const removeCommand = async (name) => {
return new Promise((resolve, reject) => {
commands.map(async (command, index) => {
if (command.pattern !== undefined && command.pattern.test(new RegExp(`${config.HANDLERS}( ?${name})`, 'is'))) {
commands.splice(index, 1)
return resolve(true)
}
})
resolve(false)
})
}
async function igdl(igurl) {
const data = `q=${encodeURIComponent(igurl)}&t=media&lang=en`
const config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://v3.saveig.app/api/ajaxSearch',
headers: {
Accept: '/',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
data: data,
}
const response = await axios.request(config)
const html = response.data.data
const $ = cheerio.load(html, { decodeEntities: true })
const downloadItems = $('.download-items')
const result = []
downloadItems.each((index, element) => {
let url = $(element).find('.download-items__btn > a').attr('href')
if (url.includes('file')) {
let newUrl = new URL(url)
let encodedUrl = newUrl.searchParams.get('file')
let decodedUrl = Buffer.from(encodedUrl, 'base64').toString('utf-8')
result.push(decodedUrl)
} else {
result.push(url)
}
})
return result
}
function aiImage(prompt) {
return new Promise((resolve, reject) => {
axios
.post(
'https://socket.xasena.me/generate-image',
{
prompt: prompt,
},
{
headers: {
Accept: '*/*',
'User-Agent': 'Thunder Client (https://www.thunderclient.com)',
'Content-Type': 'application/json',
},
responseType: 'arraybuffer',
}
)
.then(function (response) {
if (response.status === 400) {
resolve(response.data)
} else {
resolve(Buffer.from(response.data, 'binary'))
}
})
.catch(function (error) {
reject(error)
})
})
}
async function getJson(url, options) {
try {
options ? options : {}
const res = await axios({
method: 'GET',
url: url,
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36',
},
...options,
})
return res.data
} catch (err) {
return err
}
}
const API_KEY = 'e6d0cd0023b7ee562a97be33d3c5f524'
const BASE_URL = 'https://api.musixmatch.com/ws/1.1/'
async function getLyrics(song, artist) {
try {
const searchUrl = `${BASE_URL}track.search?q_track=${encodeURIComponent(song)}&q_artist=${encodeURIComponent(artist)}&f_has_lyrics=1&apikey=${API_KEY}`
const searchData = await getJson(searchUrl)
const trackList = searchData.message.body.track_list
let trackId = null
if (trackList.length > 0) {
trackId = trackList[0].track.track_id
} else {
const allTracksUrl = `${BASE_URL}track.search?q_artist=${encodeURIComponent(artist)}&apikey=${API_KEY}`
const allTracksData = await getJson(allTracksUrl)
const allTracks = allTracksData.message.body.track_list
if (allTracks.length > 0) {
trackId = allTracks[0].track.track_id
}
}
if (trackId) {
const lyricsUrl = `${BASE_URL}track.lyrics.get?track_id=${trackId}&apikey=${API_KEY}`
const lyricsData = await getJson(lyricsUrl)
let lyrics = lyricsData.message.body.lyrics.lyrics_body
const disclaimer = '********************** This Lyrics is NOT for Commercial use **********************'
lyrics = lyrics.replace(disclaimer, '')
return {
artist_name: artist,
song,
lyrics: lyrics.replace(/\(\d+\)$/, ''),
}
}
} catch (error) {
console.error('Error:', error)
throw error
}
return null
}
module.exports = {
parseTimeToSeconds: (timeString) => {
const [minutes, seconds] = timeString.split(':').map(Number)
return minutes * 60 + seconds
},
toAudio,
toPTT,
toVideo,
ffmpeg,
removeBg,
FiletypeFromUrl,
removeCommand,
getBuffer,
extractUrlFromMessage,
decodeJid,
isAdmin: async (jid, user, client) => {
const groupMetadata = await client.groupMetadata(jid)
const groupAdmins = groupMetadata.participants.filter((participant) => participant.admin !== null).map((participant) => participant.id)
return groupAdmins.includes(decodeJid(user))
},
webp2mp4: async (source) => {
let form = new FormData()
let isUrl = typeof source === 'string' && /https?:\/\//.test(source)
form.append('new-image-url', isUrl ? source : '')
form.append('new-image', isUrl ? '' : source, 'image.webp')
let res = await fetch('https://ezgif.com/webp-to-mp4', {
method: 'POST',
body: form,
})
let html = await res.text()
let { document } = new JSDOM(html).window
let form2 = new FormData()
let obj = {}
for (let input of document.querySelectorAll('form input[name]')) {
obj[input.name] = input.value
form2.append(input.name, input.value)
}
let res2 = await fetch('https://ezgif.com/webp-to-mp4/' + obj.file, {
method: 'POST',
body: form2,
})
let html2 = await res2.text()
let { document: document2 } = new JSDOM(html2).window
return new URL(document2.querySelector('div#output > p.outfile > video > source').src, res2.url).toString()
},
validatAndSaveDeleted,
webp2png: async (source) => {
let form = new FormData()
let isUrl = typeof source === 'string' && /https?:\/\//.test(source)
form.append('new-image-url', isUrl ? source : '')
form.append('new-image', isUrl ? '' : source, 'image.webp')
let res = await fetch('https://s6.ezgif.com/webp-to-png', {
method: 'POST',
body: form,
})
let html = await res.text()
let { document } = new JSDOM(html).window
let form2 = new FormData()
let obj = {}
for (let input of document.querySelectorAll('form input[name]')) {
obj[input.name] = input.value
form2.append(input.name, input.value)
}
let res2 = await fetch('https://ezgif.com/webp-to-png/' + obj.file, {
method: 'POST',
body: form2,
})
let html2 = await res2.text()
console.log(html2)
let { document: document2 } = new JSDOM(html2).window
return new URL(document2.querySelector('div#output > p.outfile > img').src, res2.url).toString()
},
parseJid(text = '') {
return [...text.matchAll(/@([0-9]{5,16}|0)/g)].map((v) => v[1] + '@s.whatsapp.net')
},
parsedJid(text = '') {
return [...text.matchAll(/([0-9]{5,16}|0)/g)].map((v) => v[1] + '@s.whatsapp.net')
},
getLyrics,
getJson,
isIgUrl: (url) => {
return /(?:(?:http|https):\/\/)?(?:www.)?(?:instagram.com|instagr.am|instagr.com)\/(\w+)/gim.test(url)
},
isUrl: (isUrl = (url) => {
return new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)/, 'gi').test(url)
}),
getUrl: (getUrl = (url) => {
return url.match(new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)/, 'gi'))
}),
qrcode: async (string) => {
const { toBuffer } = require('qrcode')
let buff = await toBuffer(string)
return buff
},
aiImage,
secondsToDHMS: (seconds) => {
seconds = Number(seconds)
const days = Math.floor(seconds / (3600 * 24))
seconds %= 3600 * 24
const hours = Math.floor(seconds / 3600)
seconds %= 3600
const minutes = Math.floor(seconds / 60)
seconds %= 60
seconds = Math.floor(seconds)
const parts = []
if (days) parts.push(`${days} Days`)
if (hours) parts.push(`${hours} Hours`)
if (minutes) parts.push(`${minutes} Minutes`)
if (seconds) parts.push(`${seconds} Seconds`)
return parts.join(' ')
},
formatBytes: (bytes, decimals = 2) => {
if (!+bytes) return '0 Bytes'
const k = 1024
const dm = decimals < 0 ? 0 : decimals
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
const i = Math.floor(Math.log(bytes) / Math.log(k))
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`
},
sleep: delay,
clockString: (duration) => {
;(seconds = Math.floor((duration / 1000) % 60)), (minutes = Math.floor((duration / (1000 * 60)) % 60)), (hours = Math.floor((duration / (1000 * 60 * 60)) % 24))
hours = hours < 10 ? '0' + hours : hours
minutes = minutes < 10 ? '0' + minutes : minutes
seconds = seconds < 10 ? '0' + seconds : seconds
return hours + ':' + minutes + ':' + seconds
},
runtime: () => {
const duration = process.uptime()
const seconds = Math.floor(duration % 60)
const minutes = Math.floor((duration / 60) % 60)
const hours = Math.floor((duration / (60 * 60)) % 24)
const formattedTime = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`
return formattedTime
},
validateQuality: (quality) => {
let valid = ['144p', '240p', '360p', '480p', '720p', '1080p']
return valid.includes(quality)
},
AddMp3Meta: async (songbuffer, coverBuffer, options = { title: 'X-Asena Whatsapp bot', artist: ['Xasena'] }) => {
if (!Buffer.isBuffer(songbuffer)) {
songbuffer = await getBuffer(songbuffer)
}
if (!Buffer.isBuffer(coverBuffer)) {
coverBuffer = await getBuffer(coverBuffer)
}
const writer = new id3(songbuffer)
writer.setFrame('TIT2', options.title).setFrame('TPE1', ['X-Asena']).setFrame('APIC', {
type: 3,
data: coverBuffer,
description: 'Xasena',
})
writer.addTag()
return Buffer.from(writer.arrayBuffer)
},
Bitly: async (url) => {
return new Promise((resolve, reject) => {
const BitlyClient = require('bitly').BitlyClient
const bitly = new BitlyClient('6e7f70590d87253af9359ed38ef81b1e26af70fd')
bitly
.shorten(url)
.then((a) => {
resolve(a)
})
.catch((A) => reject(A))
return
})
},
isNumber: function isNumber() {
const int = parseInt(this)
return typeof int === 'number' && !isNaN(int)
},
getRandom: function getRandom() {
if (Array.isArray(this) || this instanceof String) return this[Math.floor(Math.random() * this.length)]
return Math.floor(Math.random() * this)
},
createInteractiveMessage,
igdl,
textToImg,
readQr,
m3u82Mp4,
captureScreenshot,
editAudio,
}
|