info-dashboard.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. let handler = async (m, { conn }) => {
  2. let stats = Object.entries(db.data.stats).map(([key, val]) => {
  3. let name = Array.isArray(plugins[key]?.help) ? plugins[key]?.help?.join(' & ') : plugins[key]?.help || key
  4. if (/exec/.test(name)) return
  5. return { name, ...val }
  6. })
  7. stats = stats.sort((a, b) => b.total - a.total)
  8. let txt = stats.slice(0, 10).map(({ name, total, last }, idx) => {
  9. if (name.includes('-') && name.endsWith('.js')) name = name.split('-')[1].replace('.js', '')
  10. return `[ ${idx + 1} ] *COMANDO:*\n⮕ *${name}*\n*• USOS:*\n⮕ *${total}x*\n`
  11. }).join`\n\n`
  12. m.reply(`*「DASHBOARD」*\n\n*Total :* ${conn.user.name}\n\n${txt}`)
  13. }
  14. handler.help = ['dashboard']
  15. handler.tags = ['main']
  16. handler.command = /^dashboard$/i
  17. handler.register = true
  18. export default handler
  19. export function parseMs(ms) {
  20. if (typeof ms !== 'number') throw 'El parámetro debe rellenarse con un número'
  21. return {
  22. days: Math.trunc(ms / 86400000),
  23. hours: Math.trunc(ms / 3600000) % 24,
  24. minutes: Math.trunc(ms / 60000) % 60,
  25. seconds: Math.trunc(ms / 1000) % 60,
  26. milliseconds: Math.trunc(ms) % 1000,
  27. microseconds: Math.trunc(ms * 1000) % 1000,
  28. nanoseconds: Math.trunc(ms * 1e6) % 1000
  29. }}
  30. export function getTime(ms) {
  31. let now = parseMs(+new Date() - ms)
  32. if (now.days) return `Hace ${now.days} días`
  33. else if (now.hours) return `Hace ${now.hours} horas`
  34. else if (now.minutes) return `Hace ${now.minutes} minutos`
  35. else return `hace unos segundos`
  36. }