info-rapidez.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import { cpus as _cpus, totalmem, freemem } from 'os'
  2. import util from 'util'
  3. import os from 'os'
  4. import moment from 'moment';
  5. import fetch from 'node-fetch'
  6. import osu from 'node-os-utils'
  7. import { performance } from 'perf_hooks'
  8. import { sizeFormatter } from 'human-readable'
  9. import si from 'systeminformation';
  10. let format = sizeFormatter({
  11. std: 'JEDEC', // 'SI' (default) | 'IEC' | 'JEDEC'
  12. decimalPlaces: 2,
  13. keepTrailingZeroes: false,
  14. render: (literal, symbol) => `${literal} ${symbol}B`,
  15. })
  16. async function getSystemInfo() {
  17. let disk = await si.fsSize();
  18. const memInfo = await si.mem();
  19. const load = await si.currentLoad();
  20. let cpuInfo = os.cpus();
  21. let modeloCPU = cpuInfo && cpuInfo.length > 0 ? cpuInfo[0].model : 'Modelo de CPU no disponible';
  22. let espacioTotalDisco = 'Información no disponible';
  23. if (disk && disk.length > 0) {
  24. espacioTotalDisco = humanFileSize(disk[0].available, true, 1) + ' libre de ' + humanFileSize(disk[0].size, true, 1);
  25. }
  26. const data = {
  27. latencia: 'No disponible',
  28. plataforma: os.platform(),
  29. núcleosCPU: cpuInfo ? cpuInfo.length : 'No disponible',
  30. modeloCPU: modeloCPU,
  31. arquitecturaSistema: os.arch(),
  32. versiónSistema: os.release(),
  33. procesosActivos: os.loadavg()[0],
  34. porcentajeCPUUsada: load.currentLoad.toFixed(2) + '%',
  35. //memory: humanFileSize(ram.free, true, 1) + ' libre de ' + humanFileSize(ram.total, true, 1),
  36. ramUsada: (memInfo.used / (1024 * 1024 * 1024)).toFixed(2) + ' GB',
  37. ramTotal: (memInfo.total / (1024 * 1024 * 1024)).toFixed(2) + ' GB',
  38. ramLibre: (memInfo.free / (1024 * 1024 * 1024)).toFixed(2) + ' GB',
  39. porcentajeRAMUsada: ((memInfo.used / memInfo.total) * 100).toFixed(2) + '%',
  40. espacioTotalDisco: espacioTotalDisco,
  41. tiempoActividad: 'No disponible',
  42. cargaPromedio: os.loadavg().map((avg, index) => `${index + 1} min: ${avg.toFixed(2)}.`).join('\n'),
  43. horaActual: new Date().toLocaleString(),
  44. detallesCPUNúcleo: load.cpus.map(cpu => cpu.load.toFixed(2) + '%')
  45. };
  46. //Calcula la latencia (tiempo de respuesta)
  47. const startTime = Date.now();
  48. await si.currentLoad();
  49. const endTime = Date.now();
  50. data.latencia = `${endTime - startTime} ms`;
  51. //Calcula el tiempo de actividad
  52. const uptimeSeconds = await si.time().uptime;
  53. const days = Math.floor(uptimeSeconds / 60 / 60 / 24);
  54. const hours = Math.floor((uptimeSeconds / 60 / 60) % 24);
  55. const minutes = Math.floor((uptimeSeconds / 60) % 60);
  56. data.tiempoActividad = `${days}d ${hours}h ${minutes}m`;
  57. return data;
  58. }
  59. let handler = async (m, { conn, usedPrefix, command, isRowner}) => {
  60. try {
  61. let fkontak = { "key": { "participants":"[email protected]", "remoteJid": "status@broadcast", "fromMe": false, "id": "Halo" }, "message": { "contactMessage": { "vcard": `BEGIN:VCARD\nVERSION:3.0\nN:Sy;Bot;;;\nFN:y\nitem1.TEL;waid=${m.sender.split('@')[0]}:${m.sender.split('@')[0]}\nitem1.X-ABLabel:Ponsel\nEND:VCARD` }}, "participant": "[email protected]" }
  62. let _muptime
  63. if (process.send) {
  64. process.send('uptime')
  65. _muptime = await new Promise(resolve => {
  66. process.once('message', resolve)
  67. setTimeout(resolve, 1000)
  68. }) * 1000 }
  69. let muptime = clockString(_muptime)
  70. const chats = Object.entries(conn.chats).filter(([id, data]) => id && data.isChats)
  71. const groupsIn = chats.filter(([id]) => id.endsWith('@g.us')) //groups.filter(v => !v.read_only)
  72. const used = process.memoryUsage()
  73. const cpus = _cpus().map(cpu => {
  74. cpu.total = Object.keys(cpu.times).reduce((last, type) => last + cpu.times[type], 0)
  75. return cpu
  76. })
  77. const cpu = cpus.reduce((last, cpu, _, { length }) => {
  78. last.total += cpu.total
  79. last.speed += cpu.speed / length
  80. last.times.user += cpu.times.user
  81. last.times.nice += cpu.times.nice
  82. last.times.sys += cpu.times.sys
  83. last.times.idle += cpu.times.idle
  84. last.times.irq += cpu.times.irq
  85. return last
  86. }, {
  87. speed: 0,
  88. total: 0,
  89. times: {
  90. user: 0,
  91. nice: 0,
  92. sys: 0,
  93. idle: 0,
  94. irq: 0
  95. }})
  96. let old = performance.now()
  97. const { key } = await conn.sendMessage(m.chat, {text: `𝘾𝙤𝙢𝙚𝙣𝙯𝙖𝙣𝙙𝙤 𝙥𝙧𝙪𝙚𝙗𝙖 𝙙𝙚𝙡 𝙫𝙚𝙡𝙤𝙘𝙞𝙙𝙖𝙙 🚀...`}, {quoted: fkontak});
  98. // await delay(1000 * 2);
  99. //await conn.reply(m.chat, `𝘾𝙤𝙢𝙚𝙣𝙯𝙖𝙣𝙙𝙤 𝙥𝙧𝙪𝙚𝙗𝙖 𝙙𝙚𝙡 𝙫𝙚𝙡𝙤𝙘𝙞𝙙𝙖𝙙 🚀...`, fkontak, m)
  100. let neww = performance.now()
  101. let speed = neww - old
  102. getSystemInfo().then(async (data) => {
  103. let caption = `*🚀 Velocidad 🚀*
  104. 🚄 *${Math.round(neww - old)}* ms
  105. 🚄 *${speed}* ms
  106. *🕕 TIEMPO ACTIVOS*
  107. ${muptime}
  108. ${readMore}
  109. *🟢 C H A T S*
  110. ▢ *${groupsIn.length}* _Chats de grupo_
  111. ▢ *${groupsIn.length}* _Grupos unidos_
  112. ▢ *${groupsIn.length - groupsIn.length}* _Grupos abandonados_
  113. ▢ *${chats.length - groupsIn.length}* _Chats Privados_
  114. ▢ *${chats.length}* _Total Chats_
  115. *🔰 S E R V I D O R : S E R V E R*
  116. *💻 Plataforma :* \`\`\`${os.platform()}\`\`\`
  117. *📡 Servidor :* _${os.hostname()}_
  118. *🔢 Núcleos de CPU :* _${data.núcleosCPU}_
  119. *📡 Modelo de CPU :* _${data.modeloCPU}_
  120. *🏗️ Arquitectura del Sistema :* _${data.arquitecturaSistema}_
  121. *🔢 Versión del Sistema :* _${data.versiónSistema}_
  122. *📈 Procesos Activos :* _${data.procesosActivos}_
  123. *🔳 CPU Usada :* _${data.porcentajeCPUUsada}_
  124. *🟢 RAM:* ${format(totalmem() - freemem())} / ${format(totalmem())}
  125. *🔵 RAM Libre:* ${format(freemem())}
  126. *💾 Porcentaje de RAM Usada :* _${data.porcentajeRAMUsada}_
  127. *📦 Espacio Total en Disco :* _${data.espacioTotalDisco}_
  128. *⏳ Uptime :* _${data.tiempoActividad}_
  129. ${readMore}
  130. *NodeJS Uso de memoria : Memory Usage*
  131. ${'```' + Object.keys(used).map((key, _, arr) => `${key.padEnd(Math.max(...arr.map(v => v.length)), ' ')}: ${format(used[key])}`).join('\n') + '```'}
  132. ${cpus[0] ? `*Uso total de la CPU*
  133. ${cpus[0].model.trim()} (${cpu.speed} MHZ)\n${Object.keys(cpu.times).map(type => `- *${(type + '*').padEnd(6)}: ${(100 * cpu.times[type] / cpu.total).toFixed(2)}%`).join('\n')}
  134. *CPU Core(s) Uso (${cpus.length} Core CPU)*
  135. ${cpus.map((cpu, i) => `${i + 1}. ${cpu.model.trim()} (${cpu.speed} MHZ)\n${Object.keys(cpu.times).map(type => `- *${(type + '*').padEnd(6)}: ${(100 * cpu.times[type] / cpu.total).toFixed(2)}%`).join('\n')}`).join('\n\n')}` : ''}
  136. `
  137. await conn.sendMessage(m.chat, {text: caption, edit: key})});
  138. //await conn.sendFile(m.chat, gataImg.getRandom(), 'gata.jpg', caption, fkontak)
  139. ///await conn.sendButton(m.chat, wm, caption, gata.getRandom(), [['𝗠 𝗘 𝗡 𝗨 ☘️', '/menu']], m, dos.getRandom())
  140. } catch (e) {
  141. await conn.reply(m.chat, `${fg}*ALGO SALIÓ MAL.*\n\n\`\`\`REPORTE ESTE COMANDO ${usedPrefix + command} CON EL COMANDO ${usedPrefix}reporte\`\`\``, m)
  142. console.log(e)
  143. }}
  144. handler.help = ['ping', 'speed']
  145. handler.tags = ['main']
  146. handler.command = /^(ping|speed|velocidad|rapidez|velocity)$/i
  147. handler.register = true
  148. export default handler
  149. const more = String.fromCharCode(8206)
  150. const readMore = more.repeat(4001)
  151. function clockString(ms) {
  152. let d = isNaN(ms) ? '--' : Math.floor(ms / 86400000)
  153. let h = isNaN(ms) ? '--' : Math.floor(ms / 3600000) % 24
  154. let m = isNaN(ms) ? '--' : Math.floor(ms / 60000) % 60
  155. let s = isNaN(ms) ? '--' : Math.floor(ms / 1000) % 60
  156. return [' ' + d, ' dias, ', h, ' hs, ', m, ' min, ', s, ' seg '].map(v => v.toString().padStart(2, 0)).join('')
  157. }
  158. function humanFileSize(bytes) {
  159. const unidades = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
  160. const exponente = Math.floor(Math.log(bytes) / Math.log(1024));
  161. return `${(bytes / Math.pow(1024, exponente)).toFixed(2)} ${unidades[exponente]}`;
  162. }