File size: 5,626 Bytes
1c60365
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b038003
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c60365
 
 
 
 
b038003
 
 
 
1c60365
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b038003
1c60365
 
b038003
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c60365
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// 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 = `
            <span class="text-purple-400">[${new Date().toLocaleTimeString()}]</span>
            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 = `
                <span class="text-purple-400">[${new Date().toLocaleTimeString()}]</span>
                Points verified (${e.detail.points}/765) - Access granted
            `;
            sendBtn.disabled = false;
            saveBtn.disabled = false;
        } else {
            entry.innerHTML = `
                <span class="text-purple-400">[${new Date().toLocaleTimeString()}]</span>
                Points verification failed (${e.detail.points}/765) - Need more points
            `;
            sendBtn.disabled = true;
            saveBtn.disabled = true;
        }
        logElement.prepend(entry);
    });
});