info-infobot.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import db from '../lib/database.js';
  2. import ws from 'ws';
  3. import { cpus as _cpus, totalmem, freemem, platform, hostname, version, release, arch } from 'os';
  4. import os from 'os';
  5. import moment from 'moment';
  6. import speed from 'performance-now';
  7. import { sizeFormatter } from 'human-readable';
  8. let format = sizeFormatter({std: 'JEDEC', decimalPlaces: 2, keepTrailingZeroes: false, render: (literal, symbol) => `${literal} ${symbol}B`,});
  9. const used = process.memoryUsage();
  10. async function getSystemInfo() {
  11. let cpuInfo = os.cpus();
  12. let modeloCPU = cpuInfo && cpuInfo.length > 0 ? cpuInfo[0].model : 'Modelo de CPU no disponible';
  13. let espacioTotalDisco = 'Información no disponible';
  14. const data = {
  15. latencia: 'No disponible',
  16. plataforma: os.platform(),
  17. núcleosCPU: cpuInfo ? cpuInfo.length : 'No disponible',
  18. modeloCPU: modeloCPU,
  19. arquitecturaSistema: os.arch(),
  20. versiónSistema: os.release(),
  21. procesosActivos: os.loadavg()[0],
  22. porcentajeCPUUsada: 'No disponible',
  23. memory: humanFileSize(used.free, true, 1) + ' libre de ' + humanFileSize(used.total, true, 1),
  24. ramUsada: 'No disponible',
  25. ramTotal: 'No disponible',
  26. ramLibre: 'No disponible',
  27. porcentajeRAMUsada: 'No disponible',
  28. espacioTotalDisco: espacioTotalDisco,
  29. tiempoActividad: 'No disponible',
  30. cargaPromedio: os.loadavg().map((avg, index) => `${index + 1} min: ${avg.toFixed(2)}.`).join('\n'),
  31. horaActual: new Date().toLocaleString(),
  32. };
  33. const startTime = Date.now();
  34. const endTime = Date.now();
  35. data.latencia = `${endTime - startTime} ms`;
  36. return data;
  37. }
  38. let handler = async (m, { conn, usedPrefix }) => {
  39. let bot = global.db.data.settings[conn.user.jid];
  40. let _uptime = process.uptime() * 1000;
  41. let uptime = new Date(_uptime).toISOString().substr(11, 8);
  42. let totalreg = Object.keys(global.db.data.users).length;
  43. let rtotalreg = Object.values(global.db.data.users).filter(user => user.registered == true).length;
  44. let totalbots = Object.keys(global.db.data.settings).length;
  45. let totalStats = Object.values(global.db.data.stats).reduce((total, stat) => total + stat.total, 0);
  46. const chats = Object.entries(conn.chats).filter(([id, data]) => id && data.isChats);
  47. let totalchats = Object.keys(global.db.data.chats).length;
  48. let totalf = Object.values(global.plugins).filter(v => v.help && v.tags).length;
  49. const groupsIn = chats.filter(([id]) => id.endsWith('@g.us'));
  50. let totaljadibot = [...new Set([...global.conns.filter((conn) => conn.user && conn.ws.socket && conn.ws.socket.readyState !== ws.CLOSED).map((conn) => conn)])];
  51. const totalUsers = totaljadibot.length;
  52. let timestamp = speed();
  53. let latensi = speed() - timestamp;
  54. const { restrict } = global.db.data.settings[conn.user.jid] || {}
  55. const { autoread } = global.opts
  56. getSystemInfo().then(async (data) => {
  57. let teks = `*≡ INFOBOT*
  58. *INFORMACIÓN*
  59. *▣ Grupos total:* ${groupsIn.length}
  60. *▣ Grupos unidos:* ${groupsIn.length}
  61. *▣ Grupo salidos:* ${groupsIn.length - groupsIn.length}
  62. *▣ Chats privado:* ${chats.length - groupsIn.length}
  63. *▣ Chats totales:* ${chats.length}
  64. *▣ Sub-Bots conectado:* ${totalUsers}
  65. *▣ Total plugins:* ${totalf}
  66. *▣ Velocidad:* ${latensi.toFixed(4)} ms
  67. *▣ Actividad:* ${uptime}
  68. *▣ Comando Ejecutando:* ${toNum(totalStats)}/${totalStats}
  69. *▣ Grupos registrado:* ${toNum(totalchats)}/${totalchats}
  70. *▣ Usuarios registrado:* ${toNum(rtotalreg)} de ${toNum(totalreg)} users totales
  71. *≡ S E R V E R*
  72. ▣ *Servidor:* ${hostname()}
  73. ▣ *Plataforma:* ${platform()}
  74. ▣ *Cpu:* ${data.núcleosCPU}
  75. ▣ *Ram usada:* ${format(totalmem() - freemem())} de ${format(totalmem())}
  76. ▣ *Uptime:* ${toTime(os.uptime() * 1000)}`;
  77. await conn.sendMessage(m.chat, {text: teks, contextInfo: { mentionedJid: null, forwardingScore: 1, isForwarded: true, forwardedNewsletterMessageInfo: { newsletterJid: '120363371008200788@newsletter', serverMessageId: '', newsletterName: 'Kantu - Bot ✨' }, externalAdReply : {mediaUrl: null, mediaType: 1, description: null, title: `INFO - BOT`, previewType: 0, thumbnailUrl: img1, sourceUrl: redes.getRandom()}}}, { quoted: m })
  78. //conn.sendMessage(m.chat, {image: { url: "https://telegra.ph/file/39fb047cdf23c790e0146.jpg" }, caption: teks, contextInfo: {externalAdReply: { title: `INFO - BOT`, sourceUrl: redes.getRandom(), mediaType: 1, renderLargerThumbnail: true, showAdAttribution: true, thumbnailUrl: img1}}}, { quoted: m })
  79. });
  80. }
  81. handler.help = ['infobot'];
  82. handler.tags = ['main'];
  83. handler.command = /^(infobot|informacionbot|infoKantu)$/i;
  84. handler.register = true;
  85. export default handler;
  86. function toNum(number) {
  87. if (number >= 1000 && number < 1000000) {
  88. return (number / 1000).toFixed(1) + 'k';
  89. } else if (number >= 1000000) {
  90. return (number / 1000000).toFixed(1) + 'M';
  91. } else if (number <= -1000 && number > -1000000) {
  92. return (number / 1000).toFixed(1) + 'k';
  93. } else if (number <= -1000000) {
  94. return (number / 1000000).toFixed(1) + 'M';
  95. } else {
  96. return number.toString();
  97. }
  98. }
  99. function humanFileSize(bytes) {
  100. const unidades = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
  101. const exponente = Math.floor(Math.log(bytes) / Math.log(1024));
  102. return `${(bytes / Math.pow(1024, exponente)).toFixed(2)} ${unidades[exponente]}`;
  103. }
  104. function toTime(milliseconds) {
  105. const seconds = Math.floor(milliseconds / 1000);
  106. const minutes = Math.floor(seconds / 60);
  107. const hours = Math.floor(minutes / 60);
  108. const days = Math.floor(hours / 24);
  109. return `${days} d, ${hours % 24} hs, ${minutes % 60} min, ${seconds % 60} seg`;
  110. }