Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major proxy #7

Open
painterzeou opened this issue Sep 15, 2024 · 0 comments
Open

Major proxy #7

painterzeou opened this issue Sep 15, 2024 · 0 comments

Comments

@painterzeou
Copy link

Major.js and major-proxy.js are same they require proxy

This is major.js without proxy

const fs = require('fs');
const axios = require('axios');
const colors = require('colors');
const { DateTime } = require('luxon');
const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');
const path = require('path');

const maxThreads = 10; // Maximum threads to run simultaneously

class GLaDOS {
constructor() {
this.authUrl = 'https://major.glados.app/api/auth/tg/';
this.userInfoUrl = 'https://major.glados.app/api/users/';
this.streakUrl = 'https://major.glados.app/api/user-visits/streak/';
this.visitUrl = 'https://major.glados.app/api/user-visits/visit/';
this.rouletteUrl = 'https://major.glados.app/api/roulette/';
this.holdCoinsUrl = 'https://major.glados.app/api/bonuses/coins/';
this.tasksUrl = 'https://major.glados.app/api/tasks/';
this.swipeCoinUrl = 'https://major.glados.app/api/swipe_coin/';
this.durovUrl = 'https://major.bot/api/durov/';
this.durovPayloadUrl = 'https://raw.githubusercontent.com/dancayairdrop/blum/main/durov.json';
this.accountIndex = 0;
}

headers(token = null) {
    const headers = {
        'Accept': 'application/json, text/plain, */*',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'vi-VN,vi;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6,en;q=0.5',
        'Content-Type': 'application/json',
        'Origin': 'https://major.glados.app/reward',
        'Referer': 'https://major.glados.app/',
        'Sec-Ch-Ua': '"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"',
        'Sec-Ch-Ua-Mobile': '?0',
        'Sec-Ch-Ua-Platform': '"Windows"',
        'Sec-Fetch-Dest': 'empty',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Site': 'same-origin',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36'
    };

    if (token) {
        headers['Authorization'] = `Bearer ${token}`;
    }

    return headers;
}

async randomDelay() {
    const delay = Math.floor(Math.random() * (1000 - 500 + 1)) + 500;
    await new Promise(resolve => setTimeout(resolve, delay));
}

async log(msg, type = 'info') {
    const timestamp = new Date().toLocaleTimeString();
    const accountPrefix = `[Tài khoản ${this.accountIndex + 1}]`;
    let logMessage = '';

    switch(type) {
        case 'success':
            logMessage = `${accountPrefix} ${msg}`.green;
            break;
        case 'error':
            logMessage = `${accountPrefix} ${msg}`.red;
            break;
        case 'warning':
            logMessage = `${accountPrefix} ${msg}`.yellow;
            break;
        default:
            logMessage = `${accountPrefix} ${msg}`.blue;
    }

    console.log(`${timestamp} ${logMessage}`);
    await this.randomDelay();
}

async waitWithCountdown(seconds) {
    for (let i = seconds; i >= 0; i--) {
        process.stdout.write(`\r[*] Chờ ${i} giây để tiếp tục...`);
        await new Promise(resolve => setTimeout(resolve, 1000));
    }
    console.log('');
}

async makeRequest(method, url, data = null, token = null) {
    const headers = this.headers(token);
    const config = {
        method,
        url,
        headers,
    };

    if (data) {
        config.data = data;
    }

    try {
        const response = await axios(config);
        return response.data;
    } catch (error) {
        if (error.response && error.response.data) {
            return error.response.data;
        }
        throw error;
    }
}

async authenticate(init_data) {
    const payload = { init_data };
    return this.makeRequest('post', this.authUrl, payload);
}

async getUserInfo(userId, token) {
    return this.makeRequest('get', `${this.userInfoUrl}${userId}/`, null, token);
}

async getStreak(token) {
    return this.makeRequest('get', this.streakUrl, null, token);
}

async postVisit(token) {
    return this.makeRequest('post', this.visitUrl, {}, token);
}

async spinRoulette(token) {
    return this.makeRequest('post', this.rouletteUrl, {}, token);
}

async holdCoins(token) {
    const coins = Math.floor(Math.random() * (950 - 900 + 1)) + 900;
    const payload = { coins };
    const result = await this.makeRequest('post', this.holdCoinsUrl, payload, token);
    if (result.success) {
        await this.log(`HOLD coin thành công, nhận ${coins} sao`, 'success');
    } else if (result.detail && result.detail.blocked_until) {
        const blockedTime = DateTime.fromSeconds(result.detail.blocked_until).setZone('system').toLocaleString(DateTime.DATETIME_MED);
        await this.log(`HOLD coin không thành công, cần mời thêm ${result.detail.need_invites} bạn hoặc chờ đến ${blockedTime}`, 'warning');
    } else {
        await this.log(`HOLD coin không thành công`, 'error');
    }
    return result;
}

async swipeCoin(token) {
    const getResponse = await this.makeRequest('get', this.swipeCoinUrl, null, token);
    if (getResponse.success) {
        const coins = Math.floor(Math.random() * (1300 - 1000 + 1)) + 1000;
        const payload = { coins };
        const result = await this.makeRequest('post', this.swipeCoinUrl, payload, token);
        if (result.success) {
            await this.log(`Swipe coin thành công, nhận ${coins} sao`, 'success');
        } else {
            await this.log(`Swipe coin không thành công`, 'error');
        }
        return result;
    } else if (getResponse.detail && getResponse.detail.blocked_until) {
        const blockedTime = DateTime.fromSeconds(getResponse.detail.blocked_until).setZone('system').toLocaleString(DateTime.DATETIME_MED);
        await this.log(`Swipe coin không thành công, cần mời thêm ${getResponse.detail.need_invites} bạn hoặc chờ đến ${blockedTime}`, 'warning');
    } else {
        await this.log(`Không thể lấy thông tin swipe coin`, 'error');
    }
    return getResponse;
}

async getDailyTasks(token) {
    const tasks = await this.makeRequest('get', `${this.tasksUrl}?is_daily=false`, null, token);
    if (Array.isArray(tasks)) {
        return tasks.map(task => ({ id: task.id, title: task.title }));
    } else {
        return null;
    }
}

async completeTask(token, task) {
    const payload = { task_id: task.id };
    const result = await this.makeRequest('post', this.tasksUrl, payload, token);
    if (result.is_completed) {
        await this.log(`Làm nhiệm vụ ${task.id}: ${task.title} .. trạng thái: thành công`, 'success');
    }
    return result;
}

async sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

async getDurovPayload() {
    try {
        const response = await axios.get(this.durovPayloadUrl);
        return response.data;
    } catch (error) {
        return null;
    }
}

async handleDurovTask(token) {
    try {
        const getResult = await this.makeRequest('get', this.durovUrl, null, token);

        if (getResult.detail && getResult.detail.blocked_until) {
            const blockedTime = DateTime.fromSeconds(getResult.detail.blocked_until).setZone('system').toLocaleString(DateTime.DATETIME_MED);
            await this.log(`Tìm câu đố Durov không thành công, cần mời thêm ${getResult.detail.need_invites} bạn hoặc chờ đến ${blockedTime}`, 'warning');
            return;
        }

        if (!getResult.success) {
            return;
        }

        const payloadData = await this.getDurovPayload();
        if (!payloadData) {
            return;
        }

        const today = DateTime.now().setZone('system');
        const payloadDate = DateTime.fromFormat(payloadData.date, 'dd/MM/yyyy');

        if (today.hasSame(payloadDate, 'day')) {
            const payload = payloadData.tasks[0];
            const postResult = await this.makeRequest('post', this.durovUrl, payload, token);

if (postResult.correct && JSON.stringify(postResult.correct) === JSON.stringify(Object.values(payload))) {
await this.log('Tìm câu đố Durov thành công', 'success');
} else {
await this.log('Tìm câu đố Durov không thành công', 'error');
}
} else if (today > payloadDate) {
await this.log('Chưa có combo Durov ngày mới, cần réo tên @hung96 để cập nhật combo', 'warning');
} else {
await this.log('Payload date is in the future. Please check the date format.', 'warning');
}
} catch (error) {
await this.log(Lỗi rồi: ${error.message}, 'error');
}
}

async processAccount(accountData) {
    const { init_data, index } = accountData;
    this.accountIndex = index;

    try {
        const authResult = await this.authenticate(init_data);
        if (authResult) {
            const { access_token, user } = authResult;
            const { id, first_name } = user;

            await this.log(`Tài khoản ${first_name}`, 'info');

            const userInfo = await this.getUserInfo(id, access_token);
            if (userInfo) {
                await this.log(`Số sao đang có: ${userInfo.rating}`, 'success');
            }

            const streakInfo = await this.getStreak(access_token);
            if (streakInfo) {
                await this.log(`Đã điểm danh ${streakInfo.streak} ngày!`, 'success');
            }

            const visitResult = await this.postVisit(access_token);
            if (visitResult) {
                if (visitResult.is_increased) {
                    await this.log(`Điểm danh thành công ngày ${visitResult.streak}`, 'success');
                } else {
                    await this.log(`Đã điểm danh trước đó. Streak hiện tại: ${visitResult.streak}`, 'warning');
                }
            }

            const rouletteResult = await this.spinRoulette(access_token);
            if (rouletteResult) {
                if (rouletteResult.rating_award > 0) {
                    await this.log(`Spin thành công, nhận được ${rouletteResult.rating_award} sao`, 'success');
                } else if (rouletteResult.detail && rouletteResult.detail.blocked_until) {
                    const blockedTime = DateTime.fromSeconds(rouletteResult.detail.blocked_until).setZone('system').toLocaleString(DateTime.DATETIME_MED);
                    await this.log(`Spin không thành công, cần mời thêm ${rouletteResult.detail.need_invites} bạn hoặc chờ đến ${blockedTime}`, 'warning');
                } else {
                    await this.log(`Kết quả spin không xác định`, 'error');
                }
            }

            await this.handleDurovTask(access_token);
            await this.holdCoins(access_token);
            await this.swipeCoin(access_token);

            const tasks = await this.getDailyTasks(access_token);
            if (tasks) {
                for (const task of tasks) {
                    await this.completeTask(access_token, task);
                    await this.sleep(1000);
                }
            }
        } else {
            await this.log(`Không đọc được dữ liệu tài khoản`, 'error');
        }
    } catch (error) {
        await this.log(`Lỗi xử lý tài khoản: ${error.message}`, 'error');
    }
}

async processBatch(batch) {
    return Promise.all(batch.map((account, index) => {
        return new Promise((resolve) => {
            const worker = new Worker(__filename, {
                workerData: { account, index: account.index }
            });

            const timeout = setTimeout(() => {
                worker.terminate();
                this.log(`Tài khoản ${account.index + 1} bị timeout sau 10 phút`, 'error');
                resolve();
            }, 10 * 60 * 1000);

            worker.on('message', (message) => {
                if (message === 'done') {
                    clearTimeout(timeout);
                    resolve();
                }
            });

            worker.on('error', (error) => {
                this.log(`Lỗi luồng cho tài khoản ${account.index + 1}: ${error.message}`, 'error');
                clearTimeout(timeout);
                resolve();
            });

            worker.on('exit', (code) => {
                if (code !== 0) {
                    this.log(`Luồng tài khoản ${account.index + 1} dừng với mã lỗi ${code}`, 'error');
                }
                clearTimeout(timeout);
                resolve();
            });
        });
    }));
}

async main() {
    const dataFile = './../data/major.txt';
    const data = fs.readFileSync(dataFile, 'utf8')
        .split('\n')
        .filter(Boolean)
        .map((line, index) => ({ init_data: line.trim(), index }));

    while (true) {
        for (let i = 0; i < data.length; i += maxThreads) {
            const batch = data.slice(i, i + maxThreads);
            await this.processBatch(batch);

            if (i + maxThreads < data.length) {
                await this.log('Đợi 3 giây trước khi xử lý luồng tiếp theo...', 'warning');
                await this.sleep(3000);
            }
        }

        console.log(`[*] Đã xử lý tất cả tài khoản. Nghỉ ${28850} giây trước khi bắt đầu lại...`);
        await this.waitWithCountdown(28850);
    }
}

}

if (isMainThread) {
const glados = new GLaDOS();
glados.main().catch(async (err) => {
await glados.log(Lỗi rồi: ${err.message}, 'error');
process.exit(1);
});
} else {
const glados = new GLaDOS();
glados.processAccount(workerData.account)
.then(() => {
parentPort.postMessage('done');
})
.catch(async (error) => {
await glados.log(Luồng bị lỗi: ${error.message}, 'error');
parentPort.postMessage('done');
});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant