Reoo88 commited on
Commit
ea23513
·
verified ·
1 Parent(s): 3552a72

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +30 -27
index.js CHANGED
@@ -2,11 +2,11 @@ const WebSocket = require('ws');
2
  const axios = require('axios');
3
  const dns = require('dns');
4
 
5
- // --- بياناتك الأساسية ---
6
  const EULER_API_KEY = "Euler_Y2FlYTIyODYzNDQ0OTcxZjYyNGExZTkyMDM2NTMwZWE1ZjUzYmZmMDVmMGNlYjg0YzkzY2Vk";
7
  const TELEGRAM_TOKEN = "8576498050:AAHB51H9vLwFhDUFqYWttPaSa5qhPLzQVWE";
8
  const TELEGRAM_CHAT_ID = "-1002856018359";
9
- const TIKTOK_USERNAME = "talalmsa455"; // اليوزر الجديد الذي جربته
10
 
11
  dns.setServers(['8.8.8.8']);
12
 
@@ -23,47 +23,50 @@ async function sendToTelegram(text) {
23
  text: text,
24
  parse_mode: 'HTML'
25
  }, { headers: { 'Host': 'api.telegram.org' }, timeout: 10000 });
26
- } catch (e) { console.log("Telegram Send Error"); }
27
  }
28
 
29
  function connect() {
30
- // أضفنا &msToken=1 للحصول على صلاحيات أعلى في استلام البيانات
31
- const wsUrl = `wss://ws.eulerstream.com/v1/webcast?uniqueId=${TIKTOK_USERNAME}&apiKey=${EULER_API_KEY}&msToken=1`;
32
 
33
- console.log(`📡 جاري مراقبة بث: ${TIKTOK_USERNAME}...`);
34
  const ws = new WebSocket(wsUrl);
35
 
36
  ws.on('open', () => {
37
- console.log("✅ متصل بـ EulerStream");
38
- sendToTelegram(`🔔 <b>بدأ البوت بمراقبة بث:</b> ${TIKTOK_USERNAME}\nانتظر وصول التعليقات...`);
39
  });
40
 
41
  ws.on('message', (data) => {
42
- const msg = JSON.parse(data);
43
-
44
- // طباعة الحدث في الـ Logs للتأكد من وصوله
45
- console.log(`📩 حدث جديد: ${msg.type}`);
 
 
 
 
46
 
47
- if (msg.type === 'comment') {
48
- sendToTelegram(`💬 <b>${msg.nickname}:</b>\n${msg.comment}`);
49
- }
50
- else if (msg.type === 'gift') {
51
- sendToTelegram(`🎁 <b>${msg.nickname}</b> أرسل هدية: <b>${msg.giftName}</b>`);
52
- }
53
- else if (msg.type === 'social') { // متابعة أو مشاركة
54
- sendToTelegram(`👤 <b>${msg.nickname}</b> قام بمتابعة البث!`);
 
 
 
55
  }
56
  });
57
 
58
  ws.on('close', (code) => {
59
- console.log(`❌ انقطع الاتصال، الكود: ${code}`);
60
- // إذا كان الكود 4556، سنحاول إعادة الاتصال بعد فترة وجيزة
61
- let delay = (code === 4556) ? 10000 : 5000;
62
- setTimeout(connect, delay);
63
  });
64
-
65
- ws.on('error', (err) => console.log("Socket Error:", err.message));
66
  }
67
 
68
  connect();
69
- require('http').createServer((r, s) => s.end('OK')).listen(7860);
 
2
  const axios = require('axios');
3
  const dns = require('dns');
4
 
5
+ // --- بياناتك ---
6
  const EULER_API_KEY = "Euler_Y2FlYTIyODYzNDQ0OTcxZjYyNGExZTkyMDM2NTMwZWE1ZjUzYmZmMDVmMGNlYjg0YzkzY2Vk";
7
  const TELEGRAM_TOKEN = "8576498050:AAHB51H9vLwFhDUFqYWttPaSa5qhPLzQVWE";
8
  const TELEGRAM_CHAT_ID = "-1002856018359";
9
+ const TIKTOK_USERNAME = "talalmsa455";
10
 
11
  dns.setServers(['8.8.8.8']);
12
 
 
23
  text: text,
24
  parse_mode: 'HTML'
25
  }, { headers: { 'Host': 'api.telegram.org' }, timeout: 10000 });
26
+ } catch (e) { console.log("Telegram Error"); }
27
  }
28
 
29
  function connect() {
30
+ // استخدمنا رابطاً يجلب معلومات الغرفة (Room) لمراقبة العدد
31
+ const wsUrl = `wss://ws.eulerstream.com/v1/webcast?uniqueId=${TIKTOK_USERNAME}&apiKey=${EULER_API_KEY}`;
32
 
33
+ console.log(`🔎 مراقبة حالة بث: ${TIKTOK_USERNAME}`);
34
  const ws = new WebSocket(wsUrl);
35
 
36
  ws.on('open', () => {
37
+ console.log("✅ متصل بنظام التنبيهات");
38
+ sendToTelegram(`📡 <b>بدأت مراقبة البث لـ:</b> ${TIKTOK_USERNAME}\nسأخطرك عند وجود تحديثات.`);
39
  });
40
 
41
  ws.on('message', (data) => {
42
+ try {
43
+ const msg = JSON.parse(data);
44
+
45
+ // 1. مراقبة عدد المشاهدين (تحديث كلما تغير الرقم)
46
+ if (msg.viewerCount !== undefined) {
47
+ console.log(`📈 عدد المشاهدين الحالي: ${msg.viewerCount}`);
48
+ // يمكنك تفعيل الإرسال لتلجرام هنا إذا أردت تحديثاً مستمراً للعدد
49
+ }
50
 
51
+ // 2. تنبيه عند بدء البث أو تغير حالته
52
+ if (msg.type === 'roomUser' || msg.type === 'member') {
53
+ // هذه الأحداث تشير إلى نشاط المشاهدين داخل الغرفة
54
+ console.log("👤 نشاط جديد في الغرفة");
55
+ }
56
+
57
+ // لتصحيح الـ undefined ومعرفة الأنواع المتاحة
58
+ console.log("📥 نوع الحدث المستلم:", msg.type || "غير معروف");
59
+
60
+ } catch (e) {
61
+ console.log("❌ خطأ في تحليل البيانات");
62
  }
63
  });
64
 
65
  ws.on('close', (code) => {
66
+ console.log(`❌ انقطع الاتصال (${code})، إعادة المحاولة...`);
67
+ setTimeout(connect, 10000);
 
 
68
  });
 
 
69
  }
70
 
71
  connect();
72
+ require('http').createServer((req, res) => res.end('Monitor Active')).listen(7860);