Reooiq commited on
Commit
1cff3ed
·
verified ·
1 Parent(s): 6c39021

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +22 -12
index.js CHANGED
@@ -3,12 +3,15 @@ const axios = require('axios');
3
  const dns = require('dns');
4
  const http = require('http');
5
 
6
- // --- الإعدادات الآمنة (تأكد من ضبطها في Environment Variables) ---
7
  const TIKTOK_USERNAME = process.env.TIKTOK_USERNAME;
8
  const TELEGRAM_TOKEN = process.env.TELEGRAM_TOKEN;
9
  const TELEGRAM_CHAT_ID = process.env.TELEGRAM_CHAT_ID;
10
  const SESSION_ID = process.env.SESSION_ID;
11
 
 
 
 
12
  dns.setServers(['8.8.8.8']);
13
 
14
  // --- المتغيرات العامة ---
@@ -45,7 +48,6 @@ function getBaghdadTime() {
45
  }).format(new Date());
46
  }
47
 
48
- // دالة صنع شريط التقدم للبث (PK)
49
  function generateProgressBar(ourScore, theirScore, length = 10) {
50
  const total = ourScore + theirScore;
51
  if (total === 0) return "⬜".repeat(length);
@@ -53,12 +55,13 @@ function generateProgressBar(ourScore, theirScore, length = 10) {
53
  return "🟦".repeat(ourPercent) + "🟥".repeat(length - ourPercent);
54
  }
55
 
 
 
 
56
  async function sendToTelegram(text, photoUrl = null, buttons = null) {
57
  try {
58
- const addrs = await new Promise((resolve) =>
59
- dns.resolve4('api.telegram.org', (err, addresses) => err ? resolve(['api.telegram.org']) : resolve(addresses))
60
- );
61
- const baseUrl = `https://${addrs[0]}/bot${TELEGRAM_TOKEN}`;
62
 
63
  let payload = {
64
  chat_id: TELEGRAM_CHAT_ID,
@@ -71,13 +74,13 @@ async function sendToTelegram(text, photoUrl = null, buttons = null) {
71
  if (photoUrl) {
72
  payload.photo = photoUrl;
73
  payload.caption = text;
74
- await axios.post(`${baseUrl}/sendPhoto`, payload, { headers: { Host: 'api.telegram.org' } });
75
  } else {
76
  payload.text = text;
77
- await axios.post(`${baseUrl}/sendMessage`, payload, { headers: { Host: 'api.telegram.org' } });
78
  }
79
  } catch (e) {
80
- console.log("⚠️ تليجرام:", e.message);
81
  }
82
  }
83
 
@@ -191,14 +194,21 @@ tiktokConnection.on('streamEnd', () => {
191
  setTimeout(startRadar, 60000);
192
  });
193
 
194
- // --- Server & Self-Ping ---
195
  const server = http.createServer((req, res) => {
196
  res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
197
  res.end('رادار تيك توك الاحترافي يعمل! 🚀');
198
  });
199
 
200
  server.listen(7860, '0.0.0.0', () => {
201
- console.log("✅ السيرفر جاهز");
202
- setInterval(() => { http.get('http://localhost:7860').on('error', () => {}); }, 240000);
 
 
 
 
 
 
 
203
  startRadar();
204
  });
 
3
  const dns = require('dns');
4
  const http = require('http');
5
 
6
+ // --- الإعدادات الآمنة ---
7
  const TIKTOK_USERNAME = process.env.TIKTOK_USERNAME;
8
  const TELEGRAM_TOKEN = process.env.TELEGRAM_TOKEN;
9
  const TELEGRAM_CHAT_ID = process.env.TELEGRAM_CHAT_ID;
10
  const SESSION_ID = process.env.SESSION_ID;
11
 
12
+ // رابط الجسر الخاص بك في Cloudflare
13
+ const MY_PROXY_URL = "https://tg-proxy.dr-toktok00.workers.dev";
14
+
15
  dns.setServers(['8.8.8.8']);
16
 
17
  // --- المتغيرات العامة ---
 
48
  }).format(new Date());
49
  }
50
 
 
51
  function generateProgressBar(ourScore, theirScore, length = 10) {
52
  const total = ourScore + theirScore;
53
  if (total === 0) return "⬜".repeat(length);
 
55
  return "🟦".repeat(ourPercent) + "🟥".repeat(length - ourPercent);
56
  }
57
 
58
+ /**
59
+ * دالة الإرسال المعدلة لتعمل عبر الجسر الشخصي (Cloudflare)
60
+ */
61
  async function sendToTelegram(text, photoUrl = null, buttons = null) {
62
  try {
63
+ // تم استبدال الرابط المباشر برابط الجسر الخاص بك
64
+ const baseUrl = `${MY_PROXY_URL}/bot${TELEGRAM_TOKEN}`;
 
 
65
 
66
  let payload = {
67
  chat_id: TELEGRAM_CHAT_ID,
 
74
  if (photoUrl) {
75
  payload.photo = photoUrl;
76
  payload.caption = text;
77
+ await axios.post(`${baseUrl}/sendPhoto`, payload, { timeout: 15000 });
78
  } else {
79
  payload.text = text;
80
+ await axios.post(`${baseUrl}/sendMessage`, payload, { timeout: 15000 });
81
  }
82
  } catch (e) {
83
+ console.log("⚠️ فشل الإرسال عبر الجسر:", e.message);
84
  }
85
  }
86
 
 
194
  setTimeout(startRadar, 60000);
195
  });
196
 
197
+ // --- Server & Self-Ping (المطور) ---
198
  const server = http.createServer((req, res) => {
199
  res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
200
  res.end('رادار تيك توك الاحترافي يعمل! 🚀');
201
  });
202
 
203
  server.listen(7860, '0.0.0.0', () => {
204
+ console.log("✅ خادم النبض نشط");
205
+
206
+ // نظام نبض داخلي محسّن لمنع النوم وتراكم الاتصالات
207
+ setInterval(() => {
208
+ http.get('http://localhost:7860', (res) => {
209
+ res.resume(); // استهلاك الاستجابة لتحرير الذاكرة
210
+ }).on('error', () => {});
211
+ }, 120000); // كل دقيقتين
212
+
213
  startRadar();
214
  });