🦈드림 걸 Gemoy ~ Info AraBotz
🦈드림 걸 Gemoy ~ Info AraBotz
May 23, 2025 at 02:05 PM
/* Fitur TopCmd ~Req: Anomani~ © Icihibos */ // taruh di sebelum switch command // topcmd const fs = require('fs') const moment = require('moment') const dirPath = './database' const logPath = `${dirPath}/command-logs.json` if (!fs.existsSync(dirPath)) { fs.mkdirSync(dirPath) } if (!fs.existsSync(logPath)) { fs.writeFileSync(logPath, JSON.stringify([])) } function logCommand(cmd) { let logs = JSON.parse(fs.readFileSync(logPath)) logs.push({ cmd, time: Date.now() }) fs.writeFileSync(logPath, JSON.stringify(logs)) } if (command) logCommand(command) // case case 'topcmd': { let logs = JSON.parse(fs.readFileSync(logPath)) let todayStart = moment().startOf('day').valueOf() let todayLogs = logs.filter(log => log.time >= todayStart) let freq = {} for (let log of todayLogs) { freq[log.cmd] = (freq[log.cmd] || 0) + 1 } let sorted = Object.entries(freq).sort((a, b) => b[1] - a[1]) if (!sorted.length) return m.reply('Belum ada command yang digunakan hari ini.') let teks = '*Top 10 Command Hari Ini:*\n\n' sorted.slice(0, 10).forEach(([cmd, total], i) => { teks += `${i + 1}. *${cmd}* → ${total}x\n` }) m.reply(teks) } break

Comments