File size: 4,754 Bytes
398f616
d21c0e9
6a44895
d21c0e9
6dfdd73
33e44f7
d21c0e9
 
6a44895
3552a72
d21c0e9
0607b39
 
 
 
 
 
 
33e44f7
d21c0e9
7ef86d3
289d00e
 
7ef86d3
 
01d4ebd
0607b39
289d00e
6dfdd73
d21c0e9
 
114f709
398f616
 
 
 
 
 
 
 
6dfdd73
114f709
0607b39
 
 
 
114f709
6dfdd73
0607b39
398f616
0607b39
114f709
6dfdd73
33e44f7
01d4ebd
0607b39
 
 
 
 
6dfdd73
 
0607b39
e3e1b13
01d4ebd
398f616
 
0607b39
 
 
 
 
 
 
 
 
 
 
 
 
114f709
6dfdd73
0607b39
6dfdd73
 
 
 
 
 
 
 
 
0607b39
 
 
 
 
6dfdd73
 
 
398f616
 
01d4ebd
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
const { WebcastPushConnection } = require('tiktok-live-connector');
const axios = require('axios');
const dns = require('dns');

// --- الإعدادات ⚙️ ---
const TIKTOK_USERNAME = "ah_md107"; 
const TELEGRAM_TOKEN = "8576498050:AAHB51H9vLwFhDUFqYWttPaSa5qhPLzQVWE"; 
const TELEGRAM_CHAT_ID = "-1002856018359"; 

dns.setServers(['8.8.8.8']);

// --- المتغيرات الحسابية 📊 ---
let highestHundred = 0; // لتتبع إشعارات الصعود
let maxViewers = 0;     // لأعلى رقم حقيقي
let totalLikes = 0;     // إجمالي الإعجابات
let totalGifts = 0;     // إجمالي عدد الهدايا
let topGifterName = "لا يوجد";
let maxGiftCoins = 0;   // لتحديد أكبر داعم

async function sendToTelegram(text) {
    try {
        const addrs = await new Promise(r => dns.resolve4('api.telegram.org', (e, a) => r(a)));
        await axios.post(`https://${addrs[0]}/bot${TELEGRAM_TOKEN}/sendMessage`, {
            chat_id: TELEGRAM_CHAT_ID,
            text: text,
            parse_mode: 'HTML',
            disable_web_page_preview: false 
        }, { headers: { 'Host': 'api.telegram.org' } });
    } catch (e) { console.log("خطأ في التلجرام"); }
}

let tiktokConnection = new WebcastPushConnection(TIKTOK_USERNAME, {
    processInitialData: true,
    enableWebsocketUpgrade: true,
    clientParams: {
        "app_language": "en-US",
        "apiKey": "Euler_Y2FlYTIyODYzNDQ0OTcxZjYyNGExZTkyMDM2NTMwZWE1ZjUzYmZmMDVmMGNlYjg0YzkzY2Vk"
    }
});

// 1. إشعار بداية البث 🚀
tiktokConnection.connect().then(state => {
    // تصفير البيانات لكل بث جديد
    highestHundred = 0; maxViewers = 0; totalLikes = 0; totalGifts = 0;
    topGifterName = "لا يوجد"; maxGiftCoins = 0;

    const liveLink = `https://www.tiktok.com/@${TIKTOK_USERNAME}/live`;
    sendToTelegram(`🚀 <b>بدأ البث المباشر الآن!</b>\n👤 الحساب: <code>${TIKTOK_USERNAME}</code>\n🔗 الرابط: ${liveLink}`);
}).catch(err => console.log("بحث..."));

// 2. مراقبة المشاهدين والصعود 🏔️
tiktokConnection.on('roomUser', (data) => {
    const viewers = data.viewerCount;
    const liveLink = `https://www.tiktok.com/@${TIKTOK_USERNAME}/live`;

    // تحديث أعلى رقم حقيقي
    if (viewers > maxViewers) maxViewers = viewers;

    // منطق إشعارات المئات (صعود فقط)
    let currentHundred = Math.floor(viewers / 100) * 100;
    if (currentHundred >= 100 && currentHundred > highestHundred) {
        highestHundred = currentHundred;
        const msg = `🎊 <b>إنجاز جديد في البث!</b>\n\n👁️ المشاهدين: <b>${viewers}</b>\n📈 تجاوزنا عتبة: <b>${currentHundred}</b>\n🔗 الرابط: ${liveLink}`;
        sendToTelegram(msg);
    }
});

// 3. مراقبة الإعجابات والهدايا 💖🎁
tiktokConnection.on('like', (data) => { totalLikes = data.totalLikeCount; });

tiktokConnection.on('gift', (data) => {
    totalGifts += data.repeatCount;
    // تحديد أكبر داعم بناءً على قيمة الهدايا
    if (data.diamondCount > maxGiftCoins) {
        maxGiftCoins = data.diamondCount;
        topGifterName = data.nickname;
    }
});

// 4. إشعار النهاية (توقيت بغداد 🇮🇶) 🏁
tiktokConnection.on('disconnected', () => {
    const now = new Date();
    const options = { timeZone: 'Asia/Baghdad', year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit', hour12: true };
    const formatter = new Intl.DateTimeFormat('ar-IQ', options);
    const parts = formatter.formatToParts(now);
    
    const dateStr = `${parts.find(p => p.type === 'day').value}/${parts.find(p => p.type === 'month').value}/${parts.find(p => p.type === 'year').value}`;
    const timeStr = `${parts.find(p => p.type === 'hour').value}:${parts.find(p => p.type === 'minute').value} ${parts.find(p => p.type === 'dayPeriod').value}`;

    const endMsg = `🏁 <b>انتهى البث المباشر</b>\n\n` +
                   `👤 الحساب: <code>${TIKTOK_USERNAME}</code>\n` +
                   `📅 التاريخ: ${dateStr}\n` +
                   `⏰ الوقت: ${timeStr}\n` +
                   `🏆 أعلى مشاهدات: <b>${maxViewers}</b>\n` +
                   `💖 الإعجابات: <b>${totalLikes}</b>\n` +
                   `🎁 عدد الهدايا: <b>${totalGifts}</b>\n` +
                   `🌟 أكبر داعم: <b>${topGifterName}</b>`;
    
    sendToTelegram(endMsg);
    setTimeout(() => tiktokConnection.connect(), 30000);
});

require('http').createServer((req, res) => res.end('Radar Active')).listen(7860);