// Telegram bot simulation functions class ImageGateBot { constructor() { this.isRunning = false; this.intervalId = null; } startBot() { if (this.isRunning) return; this.isRunning = true; document.dispatchEvent(new CustomEvent('bot-status-change', { detail: { status: 'running' } })); // Simulate bot scanning every 10 seconds this.intervalId = setInterval(() => { this.scanDirectories(); }, 10000); // Initial scan this.scanDirectories(); } stopBot() { if (!this.isRunning) return; clearInterval(this.intervalId); this.isRunning = false; document.dispatchEvent(new CustomEvent('bot-status-change', { detail: { status: 'stopped' } })); } scanDirectories() { console.log('Scanning for image directories...'); // Simulate finding images setTimeout(() => { document.dispatchEvent(new CustomEvent('images-found', { detail: { count: Math.floor(Math.random() * 10) + 1, directory: `/images/gallery_${Math.floor(Math.random() * 1000)}` } })); }, 2000); } checkUserPoints() { return new Promise((resolve) => { // Simulate API call to check points setTimeout(() => { const hasEnoughPoints = Math.random() > 0.5; // 50% chance for demo document.dispatchEvent(new CustomEvent('points-checked', { detail: { hasEnoughPoints, points: hasEnoughPoints ? 765 : Math.floor(Math.random() * 500) } })); resolve(hasEnoughPoints); }, 1000); }); } async sendImagesToChat() { const hasAccess = await this.checkUserPoints(); if (!hasAccess) return; console.log('Sending images to Telegram chat...'); document.dispatchEvent(new CustomEvent('images-sent', { detail: { success: true } })); } async saveToUserMessages() { const hasAccess = await this.checkUserPoints(); if (!hasAccess) return; console.log('Saving images to user messages...'); document.dispatchEvent(new CustomEvent('images-saved', { detail: { success: true } })); } } // Initialize bot const bot = new ImageGateBot(); // Event listeners for UI updates document.addEventListener('DOMContentLoaded', () => { // Update UI based on bot status document.addEventListener('bot-status-change', (e) => { const statusElement = document.getElementById('bot-status'); const startBtn = document.getElementById('start-bot'); const stopBtn = document.getElementById('stop-bot'); if (e.detail.status === 'running') { statusElement.textContent = 'Running'; statusElement.className = 'bg-green-500 text-white px-3 py-1 rounded-full text-sm'; startBtn.disabled = true; stopBtn.disabled = false; } else { statusElement.textContent = 'Stopped'; statusElement.className = 'bg-red-500 text-white px-3 py-1 rounded-full text-sm'; startBtn.disabled = false; stopBtn.disabled = true; } }); // Handle images found event document.addEventListener('images-found', (e) => { const logElement = document.getElementById('bot-logs'); const entry = document.createElement('div'); entry.className = 'text-sm text-gray-300 border-b border-gray-700 py-2'; entry.innerHTML = ` [${new Date().toLocaleTimeString()}] Found ${e.detail.count} images in ${e.detail.directory} `; logElement.prepend(entry); }); // Handle button clicks document.getElementById('start-bot').addEventListener('click', () => bot.startBot()); document.getElementById('stop-bot').addEventListener('click', () => bot.stopBot()); document.getElementById('check-points').addEventListener('click', () => bot.checkUserPoints()); document.getElementById('send-images').addEventListener('click', () => bot.sendImagesToChat()); document.getElementById('save-images').addEventListener('click', () => bot.saveToUserMessages()); // Handle points checked event document.addEventListener('points-checked', (e) => { const sendBtn = document.getElementById('send-images'); const saveBtn = document.getElementById('save-images'); const logElement = document.getElementById('bot-logs'); const entry = document.createElement('div'); entry.className = 'text-sm text-gray-300 border-b border-gray-700 py-2'; if (e.detail.hasEnoughPoints) { entry.innerHTML = ` [${new Date().toLocaleTimeString()}] Points verified (${e.detail.points}/765) - Access granted `; sendBtn.disabled = false; saveBtn.disabled = false; } else { entry.innerHTML = ` [${new Date().toLocaleTimeString()}] Points verification failed (${e.detail.points}/765) - Need more points `; sendBtn.disabled = true; saveBtn.disabled = true; } logElement.prepend(entry); }); });