Reooiq commited on
Commit
05266b5
ยท
verified ยท
1 Parent(s): 5056028

Update bot.js

Browse files
Files changed (1) hide show
  1. bot.js +52 -88
bot.js CHANGED
@@ -1,9 +1,6 @@
1
  const http = require('http');
2
  const axios = require('axios');
3
 
4
- // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
5
- // 1. ุงู„ุณูŠุฑูุฑ ุฃูˆู„ุงู‹ - ูŠุฌุจ ุฃู† ูŠู‚ู„ุน ููˆุฑุงู‹
6
- // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
7
  const PORT = process.env.PORT || 7860;
8
 
9
  const CONFIG = {
@@ -12,18 +9,14 @@ const CONFIG = {
12
  TT_TARGET_IDC: (process.env.TT_TARGET_IDC || 'alisg').trim(),
13
  TELEGRAM_TOKEN: (process.env.TELEGRAM_TOKEN || '').trim(),
14
  TELEGRAM_CHAT_ID: (process.env.TELEGRAM_CHAT_ID || '').trim(),
 
15
  REPORT_INTERVAL: parseInt(process.env.REPORT_INTERVAL || '10'),
16
  GIFT_MIN_DIAMONDS: parseInt(process.env.GIFT_MIN_DIAMONDS || '1'),
17
  };
18
 
19
  let isConnected = false;
20
  let tiktokConnection = null;
21
- let totalGifts = 0;
22
- let totalLikes = 0;
23
- let totalComments = 0;
24
- let totalFollows = 0;
25
- let totalShares = 0;
26
- let maxViewers = 0;
27
  let startTime = null;
28
  let giftersMap = {};
29
  let reconnectTimer = null;
@@ -31,16 +24,13 @@ let reportInterval = null;
31
 
32
  const server = http.createServer((req, res) => {
33
  res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
34
- res.end(`
35
- <html>
36
- <body style="background:#111;color:#0f0;font-family:monospace;padding:40px;text-align:center">
37
- <h1>๐Ÿ“ก TikTok Radar Bot</h1>
38
- <p>ุงู„ุญุงู„ุฉ: ${isConnected ? '๐ŸŸข ู…ุชุตู„' : '๐Ÿ”ด ุบูŠุฑ ู…ุชุตู„'}</p>
39
- <p>ุงู„ู…ูุถูŠู: @${CONFIG.TIKTOK_USERNAME}</p>
40
- <p>ุงู„ูˆู‚ุช: ${new Date().toLocaleString('ar-IQ', {timeZone:'Asia/Baghdad'})}</p>
41
- </body>
42
- </html>
43
- `);
44
  });
45
 
46
  server.listen(PORT, '0.0.0.0', () => {
@@ -48,66 +38,56 @@ server.listen(PORT, '0.0.0.0', () => {
48
  console.log(`[Config] ุงู„ู…ูุถูŠู: @${CONFIG.TIKTOK_USERNAME}`);
49
  console.log(`[Config] ุชูŠู„ูŠุฌุฑุงู…: ${CONFIG.TELEGRAM_TOKEN ? 'โœ…' : 'โŒ'}`);
50
  console.log(`[Config] SessionID: ${CONFIG.SESSION_ID ? 'โœ…' : 'โš ๏ธ'}`);
51
- setTimeout(() => { startBot(); }, 2000);
 
52
  });
53
 
54
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
55
- // ุฏูˆุงู„ ู…ุณุงุนุฏุฉ
56
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
57
  async function sendTg(text, silent = false) {
58
  if (!CONFIG.TELEGRAM_TOKEN || !CONFIG.TELEGRAM_CHAT_ID) return;
59
- try {
60
- await axios.post(
61
- `https://api.telegram.org/bot${CONFIG.TELEGRAM_TOKEN}/sendMessage`,
62
- { chat_id: CONFIG.TELEGRAM_CHAT_ID, text, parse_mode: 'HTML', disable_notification: silent },
63
- { timeout: 30000 }
64
- );
65
- } catch (e) { console.error('[Telegram] โŒ', e.message); }
66
- }
67
-
68
- function esc(t) {
69
- if (!t) return '';
70
- return t.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
71
- }
72
 
73
- function formatK(n) {
74
- if (n >= 1000000) return (n/1000000).toFixed(1) + 'M';
75
- if (n >= 1000) return (n/1000).toFixed(1) + 'K';
76
- return n.toString();
77
- }
78
-
79
- function formatDuration(start) {
80
- if (!start) return '00:00:00';
81
- const d = Math.floor((Date.now() - start.getTime()) / 1000);
82
- return `${String(Math.floor(d/3600)).padStart(2,'0')}:${String(Math.floor((d%3600)/60)).padStart(2,'0')}:${String(d%60).padStart(2,'0')}`;
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  }
84
 
85
- function getTime() {
86
- return new Date().toLocaleString('ar-IQ', { timeZone:'Asia/Baghdad', hour:'2-digit', minute:'2-digit', second:'2-digit', hour12:true });
87
- }
 
88
 
89
- // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
90
- // ุงู„ุชู‚ุฑูŠุฑ ุงู„ุฏูˆุฑูŠ
91
- // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
92
  function startReports() {
93
  if (reportInterval) clearInterval(reportInterval);
94
  reportInterval = setInterval(() => {
95
  if (!isConnected) return;
96
  const topG = Object.values(giftersMap).sort((a,b)=>b.coins-a.coins).slice(0,5)
97
- .map((g,i)=>`${['๐Ÿฅ‡','๐Ÿฅˆ','๐Ÿฅ‰','๐Ÿ…','๐ŸŽ–'][i]} ${esc(g.name)}: ${formatK(g.coins)} ๐Ÿ’Ž`).join('\n') || 'ู„ุง ูŠูˆุฌุฏ';
98
- sendTg(
99
- `๐Ÿ“Š <b>ุชู‚ุฑูŠุฑ ุงู„ุจุซ</b>\nโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\n` +
100
- `โฑ ุงู„ู…ุฏุฉ: ${formatDuration(startTime)}\n๐Ÿ‘ ุฃุนู„ู‰ ู…ุดุงู‡ุฏุฉ: ${formatK(maxViewers)}\n` +
101
- `โค๏ธ ุฅุนุฌุงุจุงุช: ${formatK(totalLikes)}\n๐Ÿ’ฌ ุชุนู„ูŠู‚ุงุช: ${formatK(totalComments)}\n` +
102
- `๐ŸŽ ู‡ุฏุงูŠุง: ${formatK(totalGifts)}\nโž• ู…ุชุงุจุนูŠู†: ${formatK(totalFollows)}\n` +
103
- `โ†ช๏ธ ู…ุดุงุฑูƒุงุช: ${formatK(totalShares)}\n\n๐Ÿ† <b>ุฃูุถู„ ุงู„ุฏุงุนู…ูŠู†:</b>\n${topG}`
104
- );
105
  }, CONFIG.REPORT_INTERVAL * 60000);
106
  }
107
 
108
- // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
109
- // ุงู„ุงุชุตุงู„ ุจุชูŠูƒ ุชูˆูƒ
110
- // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
111
  async function startBot() {
112
  console.log(`\n[Bot] ๐Ÿ”Ž ุงู„ุจุญุซ ุนู† ุจุซ @${CONFIG.TIKTOK_USERNAME}...`);
113
 
@@ -119,7 +99,7 @@ async function startBot() {
119
  ControlEvent = lib.ControlEvent;
120
  console.log('[Bot] โœ… ุงู„ู…ูƒุชุจุฉ ุฌุงู‡ุฒุฉ');
121
  } catch (e) {
122
- console.error('[Bot] โŒ ูุดู„ ุชุญู…ูŠู„ ุงู„ู…ูƒุชุจุฉ:', e.message);
123
  setTimeout(startBot, 30000);
124
  return;
125
  }
@@ -145,61 +125,46 @@ async function startBot() {
145
  startTime = new Date();
146
  totalGifts=0; totalLikes=0; totalComments=0; totalFollows=0; totalShares=0; maxViewers=0; giftersMap={};
147
  console.log(`[Bot] โœ… ู…ุชุตู„! ุงู„ุบุฑูุฉ: ${state.roomId}`);
148
- sendTg(`๐Ÿ“ก <b>ุงู„ุจุซ ุจุฏุฃ!</b>\nโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\n๐Ÿ‘ค ุงู„ู…ูุถูŠู: @${CONFIG.TIKTOK_USERNAME}\nโฐ ${getTime()}\n๐ŸŽ‰ ุงู†ุถู… ูˆุงุฏุนู… ุงู„ุจุซ!`);
149
  startReports();
150
  });
151
 
152
- tiktokConnection.on(ControlEvent.DISCONNECTED, (data) => {
153
  isConnected = false;
154
- console.log(`[Bot] ๐Ÿ“ด ุงู†ู‚ุทุน (${data?.code || 0})`);
155
  if (reportInterval) clearInterval(reportInterval);
156
  scheduleReconnect(30000);
157
  });
158
 
159
  tiktokConnection.on(WebcastEvent.STREAM_END, () => {
160
  isConnected = false;
161
- console.log('[Bot] ๐Ÿ”ด ุงู†ุชู‡ู‰ ุงู„ุจุซ');
162
  if (reportInterval) clearInterval(reportInterval);
163
  const topG = Object.values(giftersMap).sort((a,b)=>b.coins-a.coins).slice(0,5)
164
- .map((g,i)=>`${['๐Ÿฅ‡','๐Ÿฅˆ','๐Ÿฅ‰','๐Ÿ…','๐ŸŽ–'][i]} ${esc(g.name)}: ${formatK(g.coins)} ๐Ÿ’Ž`).join('\n') || 'ู„ุง ูŠูˆุฌุฏ';
165
- sendTg(
166
- `๐Ÿ”ด <b>ุงู†ุชู‡ู‰ ุงู„ุจุซ</b>\nโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\nโฑ ${formatDuration(startTime)}\n๐Ÿ‘ ${formatK(maxViewers)}\n` +
167
- `โค๏ธ ${formatK(totalLikes)} | ๐Ÿ’ฌ ${formatK(totalComments)} | ๐ŸŽ ${formatK(totalGifts)}\n\n๐Ÿ† <b>ุงู„ุฏุงุนู…ูŠู†:</b>\n${topG}`
168
- );
169
  scheduleReconnect(60000);
170
  });
171
 
172
- tiktokConnection.on(ControlEvent.ERROR, (err) => {
173
- console.error('[Bot] โš ๏ธ', err?.info || err);
174
- });
175
-
176
- tiktokConnection.on(WebcastEvent.CHAT, (data) => {
177
- totalComments++;
178
- console.log(`[Chat] ๐Ÿ’ฌ ${data.user?.nickname || '?'}: ${data.comment || ''}`);
179
- });
180
 
181
  tiktokConnection.on(WebcastEvent.GIFT, (data) => {
182
  if (data.giftType === 1 && !data.repeatEnd) return;
183
  const uid = data.user?.userId || data.user?.uniqueId || 'x';
184
- const name = data.user?.nickname || data.user?.uniqueId || '?';
185
  const cost = (data.diamondCount||0) * (data.repeatCount||1);
186
  totalGifts++;
187
  if (!giftersMap[uid]) giftersMap[uid] = { name, coins: 0 };
188
  giftersMap[uid].coins += cost;
189
  if (cost >= CONFIG.GIFT_MIN_DIAMONDS) {
190
- let e = cost>=10000?'๐Ÿ’Ž๐Ÿ”ฅ':cost>=1000?'๐Ÿ’Žโœจ':cost>=100?'๐ŸŽโœจ':'๐ŸŽ';
191
- sendTg(`${e} <b>${esc(name)}</b> ุฃุฑุณู„ <b>${esc(data.giftName||'Gift')}</b> x${data.repeatCount||1}\n๐Ÿ’Ž ${formatK(cost)} ู…ุงุณุฉ`, cost<100);
192
  }
193
  });
194
 
195
  tiktokConnection.on(WebcastEvent.LIKE, (data) => { totalLikes += data.likeCount || 1; });
196
- tiktokConnection.on(WebcastEvent.FOLLOW, (data) => {
197
- totalFollows++;
198
- sendTg(`โž• <b>${esc(data.user?.nickname||'?')}</b> ุชุงุจุน ุงู„ุจุซ! ๐ŸŽ‰`, true);
199
- });
200
  tiktokConnection.on(WebcastEvent.SHARE, () => { totalShares++; });
201
  tiktokConnection.on(WebcastEvent.ROOM_USER, (data) => { if ((data.viewerCount||0) > maxViewers) maxViewers = data.viewerCount; });
202
- tiktokConnection.on(WebcastEvent.LINK_MIC_BATTLE, () => { sendTg(`โš”๏ธ <b>ุจุฏุฃุช ุฌูˆู„ุฉ PK!</b> ๐Ÿš€ ุงุฏุนู…ูˆุง ุงู„ุจุซ!`); });
203
 
204
  console.log('[Bot] ๐Ÿ”Œ ุฌุงุฑูŠ ุงู„ุงุชุตุงู„...');
205
  await tiktokConnection.connect();
@@ -207,7 +172,6 @@ async function startBot() {
207
  } catch (err) {
208
  console.error('[Bot] โŒ', err.message || err);
209
  isConnected = false;
210
- sendTg(`๐Ÿ”Ž ุงู„ุจุซ ุบูŠุฑ ู…ุชุงุญ ุญุงู„ูŠุงู‹\n๐Ÿ‘ค @${CONFIG.TIKTOK_USERNAME}\n๐Ÿ”„ ุณุฃุญุงูˆู„ ู…ุฑุฉ ุฃุฎุฑู‰...`, true);
211
  scheduleReconnect(60000);
212
  }
213
  }
 
1
  const http = require('http');
2
  const axios = require('axios');
3
 
 
 
 
4
  const PORT = process.env.PORT || 7860;
5
 
6
  const CONFIG = {
 
9
  TT_TARGET_IDC: (process.env.TT_TARGET_IDC || 'alisg').trim(),
10
  TELEGRAM_TOKEN: (process.env.TELEGRAM_TOKEN || '').trim(),
11
  TELEGRAM_CHAT_ID: (process.env.TELEGRAM_CHAT_ID || '').trim(),
12
+ PROXY_URL: (process.env.PROXY_URL || '').trim().replace(/\/$/, ''),
13
  REPORT_INTERVAL: parseInt(process.env.REPORT_INTERVAL || '10'),
14
  GIFT_MIN_DIAMONDS: parseInt(process.env.GIFT_MIN_DIAMONDS || '1'),
15
  };
16
 
17
  let isConnected = false;
18
  let tiktokConnection = null;
19
+ let totalGifts = 0, totalLikes = 0, totalComments = 0, totalFollows = 0, totalShares = 0, maxViewers = 0;
 
 
 
 
 
20
  let startTime = null;
21
  let giftersMap = {};
22
  let reconnectTimer = null;
 
24
 
25
  const server = http.createServer((req, res) => {
26
  res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
27
+ res.end(`<html><body style="background:#111;color:#0f0;font-family:monospace;padding:40px;text-align:center">
28
+ <h1>๐Ÿ“ก TikTok Radar Bot</h1>
29
+ <p>${isConnected ? '๐ŸŸข ู…ุชุตู„ ุจุงู„ุจุซ' : '๐Ÿ”ด ููŠ ุงู†ุชุธุงุฑ ุงู„ุจุซ'}</p>
30
+ <p>@${CONFIG.TIKTOK_USERNAME}</p>
31
+ <p>${new Date().toLocaleString('ar-IQ', {timeZone:'Asia/Baghdad'})}</p>
32
+ ${isConnected ? `<p>๐ŸŽ ${totalGifts} | โค๏ธ ${totalLikes} | ๐Ÿ’ฌ ${totalComments}</p>` : ''}
33
+ </body></html>`);
 
 
 
34
  });
35
 
36
  server.listen(PORT, '0.0.0.0', () => {
 
38
  console.log(`[Config] ุงู„ู…ูุถูŠู: @${CONFIG.TIKTOK_USERNAME}`);
39
  console.log(`[Config] ุชูŠู„ูŠุฌุฑุงู…: ${CONFIG.TELEGRAM_TOKEN ? 'โœ…' : 'โŒ'}`);
40
  console.log(`[Config] SessionID: ${CONFIG.SESSION_ID ? 'โœ…' : 'โš ๏ธ'}`);
41
+ console.log(`[Config] ุงู„ุฌุณุฑ: ${CONFIG.PROXY_URL || 'โŒ ุบูŠุฑ ู…ูˆุฌูˆุฏ'}`);
42
+ setTimeout(startBot, 2000);
43
  });
44
 
45
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
46
+ // Telegram ุนุจุฑ ุงู„ุฌุณุฑ (Proxy) ุฃูˆู„ุงู‹ ุซู… ุงู„ู…ุจุงุดุฑ
47
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
48
  async function sendTg(text, silent = false) {
49
  if (!CONFIG.TELEGRAM_TOKEN || !CONFIG.TELEGRAM_CHAT_ID) return;
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
+ const urls = [];
52
+ if (CONFIG.PROXY_URL && CONFIG.PROXY_URL.startsWith('http')) {
53
+ urls.push(`${CONFIG.PROXY_URL}/bot${CONFIG.TELEGRAM_TOKEN}`);
54
+ }
55
+ urls.push(`https://api.telegram.org/bot${CONFIG.TELEGRAM_TOKEN}`);
56
+
57
+ for (const baseUrl of urls) {
58
+ try {
59
+ const res = await axios.post(
60
+ `${baseUrl}/sendMessage`,
61
+ { chat_id: CONFIG.TELEGRAM_CHAT_ID, text, parse_mode: 'HTML', disable_notification: silent },
62
+ { timeout: 15000 }
63
+ );
64
+ if (res.data?.ok) {
65
+ console.log(`[Telegram] โœ… ุชู… ุงู„ุฅุฑุณุงู„`);
66
+ return true;
67
+ }
68
+ } catch (e) {
69
+ console.log(`[Telegram] โš ๏ฟฝ๏ฟฝ๏ฟฝ ูุดู„: ${baseUrl.substring(0, 30)}...`);
70
+ }
71
+ }
72
+ console.error('[Telegram] โŒ ุฌู…ูŠุน ุงู„ู…ุญุงูˆู„ุงุช ูุดู„ุช');
73
+ return false;
74
  }
75
 
76
+ function esc(t) { return t ? t.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;') : ''; }
77
+ function formatK(n) { return n >= 1000000 ? (n/1000000).toFixed(1)+'M' : n >= 1000 ? (n/1000).toFixed(1)+'K' : n.toString(); }
78
+ function formatDuration(s) { if (!s) return '00:00:00'; const d = Math.floor((Date.now()-s.getTime())/1000); return `${String(Math.floor(d/3600)).padStart(2,'0')}:${String(Math.floor((d%3600)/60)).padStart(2,'0')}:${String(d%60).padStart(2,'0')}`; }
79
+ function getTime() { return new Date().toLocaleString('ar-IQ', {timeZone:'Asia/Baghdad', hour:'2-digit', minute:'2-digit', hour12:true}); }
80
 
 
 
 
81
  function startReports() {
82
  if (reportInterval) clearInterval(reportInterval);
83
  reportInterval = setInterval(() => {
84
  if (!isConnected) return;
85
  const topG = Object.values(giftersMap).sort((a,b)=>b.coins-a.coins).slice(0,5)
86
+ .map((g,i)=>`${['๐Ÿฅ‡','๐Ÿฅˆ','๐Ÿฅ‰','๐Ÿ…','๐ŸŽ–'][i]} ${esc(g.name)}: ${formatK(g.coins)}๐Ÿ’Ž`).join('\n') || 'ู„ุง ูŠูˆุฌุฏ';
87
+ sendTg(`๐Ÿ“Š <b>ุชู‚ุฑูŠุฑ</b>\nโฑ${formatDuration(startTime)} | ๐Ÿ‘${formatK(maxViewers)}\nโค๏ธ${formatK(totalLikes)} | ๐Ÿ’ฌ${formatK(totalComments)} | ๐ŸŽ${formatK(totalGifts)}\n\n๐Ÿ†<b>ุงู„ุฏุงุนู…ูŠู†:</b>\n${topG}`);
 
 
 
 
 
 
88
  }, CONFIG.REPORT_INTERVAL * 60000);
89
  }
90
 
 
 
 
91
  async function startBot() {
92
  console.log(`\n[Bot] ๐Ÿ”Ž ุงู„ุจุญุซ ุนู† ุจุซ @${CONFIG.TIKTOK_USERNAME}...`);
93
 
 
99
  ControlEvent = lib.ControlEvent;
100
  console.log('[Bot] โœ… ุงู„ู…ูƒุชุจุฉ ุฌุงู‡ุฒุฉ');
101
  } catch (e) {
102
+ console.error('[Bot] โŒ ูุดู„ ุชุญู…ูŠู„ ุงู„ู…ูƒุชุจุฉ');
103
  setTimeout(startBot, 30000);
104
  return;
105
  }
 
125
  startTime = new Date();
126
  totalGifts=0; totalLikes=0; totalComments=0; totalFollows=0; totalShares=0; maxViewers=0; giftersMap={};
127
  console.log(`[Bot] โœ… ู…ุชุตู„! ุงู„ุบุฑูุฉ: ${state.roomId}`);
128
+ sendTg(`๐Ÿ“ก <b>ุงู„ุจุซ ุจุฏุฃ!</b>\n๐Ÿ‘ค @${CONFIG.TIKTOK_USERNAME}\nโฐ ${getTime()}`);
129
  startReports();
130
  });
131
 
132
+ tiktokConnection.on(ControlEvent.DISCONNECTED, () => {
133
  isConnected = false;
 
134
  if (reportInterval) clearInterval(reportInterval);
135
  scheduleReconnect(30000);
136
  });
137
 
138
  tiktokConnection.on(WebcastEvent.STREAM_END, () => {
139
  isConnected = false;
 
140
  if (reportInterval) clearInterval(reportInterval);
141
  const topG = Object.values(giftersMap).sort((a,b)=>b.coins-a.coins).slice(0,5)
142
+ .map((g,i)=>`${['๐Ÿฅ‡','๐Ÿฅˆ','๐Ÿฅ‰','๐Ÿ…','๐ŸŽ–'][i]} ${esc(g.name)}: ${formatK(g.coins)}๐Ÿ’Ž`).join('\n') || 'ู„ุง ูŠูˆุฌุฏ';
143
+ sendTg(`๐Ÿ”ด <b>ุงู†ุชู‡ู‰ ุงู„ุจุซ</b>\nโฑ${formatDuration(startTime)} | ๐Ÿ‘${formatK(maxViewers)}\n๐ŸŽ${formatK(totalGifts)} | โค๏ธ${formatK(totalLikes)}\n\n๐Ÿ†<b>ุงู„ุฏุงุนู…ูŠู†:</b>\n${topG}`);
 
 
 
144
  scheduleReconnect(60000);
145
  });
146
 
147
+ tiktokConnection.on(ControlEvent.ERROR, (err) => console.error('[Bot] โš ๏ธ', err?.info || err));
148
+ tiktokConnection.on(WebcastEvent.CHAT, (data) => { totalComments++; console.log(`[Chat] ๐Ÿ’ฌ ${data.user?.nickname}: ${data.comment}`); });
 
 
 
 
 
 
149
 
150
  tiktokConnection.on(WebcastEvent.GIFT, (data) => {
151
  if (data.giftType === 1 && !data.repeatEnd) return;
152
  const uid = data.user?.userId || data.user?.uniqueId || 'x';
153
+ const name = data.user?.nickname || '?';
154
  const cost = (data.diamondCount||0) * (data.repeatCount||1);
155
  totalGifts++;
156
  if (!giftersMap[uid]) giftersMap[uid] = { name, coins: 0 };
157
  giftersMap[uid].coins += cost;
158
  if (cost >= CONFIG.GIFT_MIN_DIAMONDS) {
159
+ sendTg(`๐ŸŽ <b>${esc(name)}</b> ุฃุฑุณู„ <b>${esc(data.giftName)}</b>\n๐Ÿ’Ž ${formatK(cost)} ู…ุงุณุฉ`, cost<100);
 
160
  }
161
  });
162
 
163
  tiktokConnection.on(WebcastEvent.LIKE, (data) => { totalLikes += data.likeCount || 1; });
164
+ tiktokConnection.on(WebcastEvent.FOLLOW, (data) => { totalFollows++; sendTg(`โž• <b>${esc(data.user?.nickname)}</b> ุชุงุจุน!`, true); });
 
 
 
165
  tiktokConnection.on(WebcastEvent.SHARE, () => { totalShares++; });
166
  tiktokConnection.on(WebcastEvent.ROOM_USER, (data) => { if ((data.viewerCount||0) > maxViewers) maxViewers = data.viewerCount; });
167
+ tiktokConnection.on(WebcastEvent.LINK_MIC_BATTLE, () => { sendTg(`โš”๏ธ <b>ุจุฏุฃุช ุฌูˆู„ุฉ PK!</b>`); });
168
 
169
  console.log('[Bot] ๐Ÿ”Œ ุฌุงุฑูŠ ุงู„ุงุชุตุงู„...');
170
  await tiktokConnection.connect();
 
172
  } catch (err) {
173
  console.error('[Bot] โŒ', err.message || err);
174
  isConnected = false;
 
175
  scheduleReconnect(60000);
176
  }
177
  }