themasterofficial3/sahistavaloraXbotPublic · Bot Template

AIMulti-file sharing bot that lets users start an upload session with /upload, collect photos, videos, documents, audio, stickers and animations, then package them into a shareable start-link using Bot storage. The wildcard command watches for upload-mode messages and the finish action, /start with a hash param retrieves and sends stored files, /cancel aborts sessions, and /stats tracks user and command counters. Callback handling supports help/upload buttons, and the error command logs exceptions.

Utilityfile-sharinguploaddownloadshare-linkmediainline-keyboard
ProfileTelegram
7 commands0 envUpdated 23d agoCreated Aug 14, 2026
Back to folder

commands/_stats.js

javascript · 65 lines

Raw
1/**#command2name: /stats3answer: 4keyboard: 5parse_mode: 6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12/*command: @*/13// Initialize bot statistics if not exists14if (!Bot.get("bot_stats")) {15    Bot.set("bot_stats", {16        total_users: 0,17        active_users: [],18        total_commands: 0,19        daily_commands: 0,20        monthly_commands: 0,21        user_join_dates: {},22        command_usage: {},23        last_reset: Date.now(),24        created_at: Date.now()25    }, "json")26}27 28// Track user activity29let stats = Bot.get("bot_stats")30let currentDate = new Date().toDateString()31 32// Initialize daily counters if new day33if (!Bot.get("last_tracked_date") || Bot.get("last_tracked_date") !== currentDate) {34    Bot.set("last_tracked_date", currentDate)35    stats.daily_commands = 036}37 38// Track user if new39if (!stats.user_join_dates[user.id]) {40    stats.user_join_dates[user.id] = Date.now()41    stats.total_users++42    43    // Add to active users (last 30 days)44    if (!stats.active_users.includes(user.id)) {45        stats.active_users.push(user.id)46    }47}48 49// Increment command counters50stats.total_commands++51stats.daily_commands++52stats.monthly_commands++53 54// Track command usage55let command_name = update.message?.text?.split(' ')[0] || "unknown"56stats.command_usage[command_name] = (stats.command_usage[command_name] || 0) + 157 58// Clean up old active users (older than 30 days)59let thirtyDaysAgo = Date.now() - (30 * 24 * 60 * 60 * 1000)60stats.active_users = stats.active_users.filter(userId => {61    return stats.user_join_dates[userId] > thirtyDaysAgo62})63 64// Save updated stats65Bot.set("bot_stats", stats, "json")