Reooiq96 commited on
Commit
8854f46
ยท
verified ยท
1 Parent(s): cc2ba3c

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +18 -25
index.js CHANGED
@@ -8,7 +8,7 @@ const TELEGRAM_TOKEN = process.env.TELEGRAM_TOKEN;
8
  const TELEGRAM_CHAT_ID = process.env.TELEGRAM_CHAT_ID;
9
  const SESSION_ID = process.env.SESSION_ID;
10
  const FIXED_COUNTRY = "ุงู„ุนุฑุงู‚ ๐Ÿ‡ฎ๐Ÿ‡ถ";
11
- const ACCOUNTS_TO_WATCH = process.env.ACCOUNTS_LIST? process.env.ACCOUNTS_LIST.split(',') :;
12
 
13
  dns.setServers(['8.8.8.8']);
14
 
@@ -28,14 +28,14 @@ function formatDuration(totalMinutes) {
28
  if (totalMinutes < 60) return `${totalMinutes} ุฏู‚ูŠู‚ุฉ`;
29
  const hours = Math.floor(totalMinutes / 60);
30
  const minutes = totalMinutes % 60;
31
- return minutes > 0? `${hours} ุณุงุนุฉ ูˆ ${minutes} ุฏู‚ูŠู‚ุฉ` : `${hours} ุณุงุนุฉ`;
32
  }
33
 
34
  async function sendToTelegram(text, photoUrl = null, targetLink = null) {
35
  try {
36
  const addrs = await new Promise(r => dns.resolve4('api.telegram.org', (e, a) => r(a)));
37
- const baseUrl = `https://${addrs}/bot${TELEGRAM_TOKEN}`;
38
- let formattedText = targetLink? `<a href="${targetLink}">โ€โ€โ€Ž โ€Ž</a>` + text : text;
39
  const payload = { chat_id: TELEGRAM_CHAT_ID, parse_mode: 'HTML', disable_web_page_preview: false };
40
 
41
  if (photoUrl) {
@@ -82,8 +82,8 @@ async function startRadar(username) {
82
 
83
  function handleConnectionSuccess(state) {
84
  startTime = new Date();
85
- let statusEmoji = state.roomInfo.live_room_mode === 4? "๐ŸŽค" : "๐Ÿ”ด";
86
- let statusText = state.roomInfo.live_room_mode === 4? "ุชู†ุจูŠู‡: ุตุงุนุฏ ุฌูŠุณุช ุงู„ุขู†!" : "ุงู†ุทู„ุงู‚ ุงู„ุจุซ ุงู„ู…ุจุงุดุฑ";
87
  let liveLink = `https://www.tiktok.com/@${user}/live`;
88
  if (state.roomInfo.live_room_mode === 4 && state.roomInfo.owner) {
89
  liveLink = `https://www.tiktok.com/@${state.roomInfo.owner.uniqueId}/live`;
@@ -96,15 +96,8 @@ async function startRadar(username) {
96
  connection.on('social', (data) => { if (data.displayType && data.displayType.includes('share')) totalShares++; });
97
 
98
  const handleBox = (data, type) => {
99
- let coins = data.coins |
100
-
101
- | data.diamonds |
102
- | data.amount |
103
- | "ุบูŠุฑ ู…ุญุฏุฏ";
104
- let sender = data.nickname |
105
-
106
- | (data.user && data.user.nickname) |
107
- | 'ู…ุฌู‡ูˆู„';
108
  sendToTelegram(`๐Ÿ’ฐ <b>ุชู†ุจูŠู‡ ${type}!</b>\n๐Ÿ‘ค ููŠ ุจุซ: @${user}\n๐ŸŽ ู…ู†: <b>${sender}</b>\n๐Ÿ’Ž ุงู„ู‚ูŠู…ุฉ: <b>${coins} ุนู…ู„ุฉ</b>`);
109
  };
110
 
@@ -119,10 +112,10 @@ async function startRadar(username) {
119
  if (!commentersMap[data.userId]) commentersMap[data.userId] = { name: data.nickname, count: 0 };
120
  commentersMap[data.userId].count++;
121
  if (text.length > 1) {
122
- if (!fastCommentCounter[text]) fastCommentCounter[text] =;
123
  fastCommentCounter[text].push(now);
124
  fastCommentCounter[text] = fastCommentCounter[text].filter(ts => now - ts < 60000);
125
- if (fastCommentCounter[text].length >= 100 &&!alertedComments.has(text)) {
126
  alertedComments.add(text);
127
  sendToTelegram(`โš ๏ธ <b>ุณุจุงู… ุณุฑูŠุน @${user}!</b>\n๐Ÿ’ฌ "<code>${text}</code>"\n๐Ÿ”ฅ ุชูƒุฑุฑ 100 ู…ุฑุฉ ููŠ ุฏู‚ูŠู‚ุฉ!`);
128
  setTimeout(() => alertedComments.delete(text), 300000);
@@ -142,15 +135,16 @@ async function startRadar(username) {
142
  });
143
 
144
  connection.on('member', (data) => {
145
- if (data.isModerator &&!adminsSeen.has(data.uniqueId)) {
146
  adminsSeen.add(data.uniqueId);
147
  sendToTelegram(`๐Ÿ›ก๏ธ <b>ู…ุดุฑู ุฏุฎู„ ุจุซ @${user}:</b>\n๐Ÿ‘ค <code>@${data.uniqueId}</code>`);
148
  }
 
149
  if (data.userLevel >= 30) sendToTelegram(`๐Ÿ‘‘ <b>ุฏุฎูˆู„ VIP (Lvl ${data.userLevel})</b>\n๐Ÿ‘ค ุจุซ @${user}: <code>@${data.uniqueId}</code>`);
150
  });
151
 
152
  connection.on('gift', (data) => {
153
- if (data.giftType === 1 &&!data.repeatEnd) return;
154
  let giftCost = data.diamondCount * data.repeatCount;
155
  if (!giftersMap[data.userId]) giftersMap[data.userId] = { name: data.nickname, coins: 0 };
156
  giftersMap[data.userId].coins += giftCost;
@@ -158,16 +152,17 @@ async function startRadar(username) {
158
  });
159
 
160
  connection.on('disconnected', () => {
 
161
  const diffMs = new Date() - startTime;
162
- const totalMinutes = startTime? Math.floor(diffMs / 60000) : 0;
163
- const durationStr = startTime? formatDuration(totalMinutes) : "ุบูŠุฑ ู…ุญุฏุฏ";
164
 
165
  let sortedGifters = Object.values(giftersMap).sort((a, b) => b.coins - a.coins).slice(0, 3);
166
  let sortedCommenters = Object.values(commentersMap).sort((a, b) => b.count - a.count).slice(0, 5);
167
  let endMsg = `๐Ÿ <b>ู…ู„ุฎุต ุงู„ู†ู‡ุงูŠุฉ (@${user})</b>\nโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\nโฑ๏ธ <b>ุงู„ู…ุฏุฉ:</b> ${durationStr} | ๐Ÿ“… <b>ุงู„ูˆู‚ุช:</b> ${getBaghdadTime()}\n๐Ÿ“Š ๐Ÿ‘๏ธ ${formatK(maxViewers)} | โค๏ธ ${formatK(totalLikes)} | ๐Ÿ”„ ${totalShares}\nโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\n๐Ÿ† <b>ุฃูุถู„ 3 ุฏุงุนู…ูŠู†:</b>\n`;
168
 
169
  sortedGifters.forEach((g, i) => {
170
- endMsg += `${i === 0? '๐Ÿฅ‡' : i === 1? '๐Ÿฅˆ' : '๐Ÿฅ‰'} <code>${g.name}</code> : <b>${formatK(g.coins)}</b>\n`;
171
  });
172
 
173
  endMsg += `\n๐Ÿ’ฌ <b>ุฃูƒุซุฑ 5 ู…ุนู„ู‚ูŠู† ุชูุงุนู„ุงู‹:</b>\n`;
@@ -176,9 +171,7 @@ async function startRadar(username) {
176
  });
177
 
178
  if (bestGift.cost > 0) endMsg += `\n๐Ÿ’Ž <b>ุฃู‚ูˆู‰ ู‡ุฏูŠุฉ:</b> ${bestGift.name} ู…ู† <b>${bestGift.sender}</b>`;
179
- sendToTelegram(endMsg, bestGift.icon |
180
-
181
- | null, `https://www.tiktok.com/@${user}/live`);
182
 
183
  fastCommentCounter = {};
184
  alertedComments = new Set();
 
8
  const TELEGRAM_CHAT_ID = process.env.TELEGRAM_CHAT_ID;
9
  const SESSION_ID = process.env.SESSION_ID;
10
  const FIXED_COUNTRY = "ุงู„ุนุฑุงู‚ ๐Ÿ‡ฎ๐Ÿ‡ถ";
11
+ const ACCOUNTS_TO_WATCH = process.env.ACCOUNTS_LIST ? process.env.ACCOUNTS_LIST.split(',') : [];
12
 
13
  dns.setServers(['8.8.8.8']);
14
 
 
28
  if (totalMinutes < 60) return `${totalMinutes} ุฏู‚ูŠู‚ุฉ`;
29
  const hours = Math.floor(totalMinutes / 60);
30
  const minutes = totalMinutes % 60;
31
+ return minutes > 0 ? `${hours} ุณุงุนุฉ ูˆ ${minutes} ุฏู‚ูŠู‚ุฉ` : `${hours} ุณุงุนุฉ`;
32
  }
33
 
34
  async function sendToTelegram(text, photoUrl = null, targetLink = null) {
35
  try {
36
  const addrs = await new Promise(r => dns.resolve4('api.telegram.org', (e, a) => r(a)));
37
+ const baseUrl = `https://${addrs[0]}/bot${TELEGRAM_TOKEN}`;
38
+ let formattedText = targetLink ? `<a href="${targetLink}">โ€โ€โ€Ž โ€Ž</a>` + text : text;
39
  const payload = { chat_id: TELEGRAM_CHAT_ID, parse_mode: 'HTML', disable_web_page_preview: false };
40
 
41
  if (photoUrl) {
 
82
 
83
  function handleConnectionSuccess(state) {
84
  startTime = new Date();
85
+ let statusEmoji = state.roomInfo.live_room_mode === 4 ? "๐ŸŽค" : "๐Ÿ”ด";
86
+ let statusText = state.roomInfo.live_room_mode === 4 ? "ุชู†ุจูŠู‡: ุตุงุนุฏ ุฌูŠุณุช ุงู„ุขู†!" : "ุงู†ุทู„ุงู‚ ุงู„ุจุซ ุงู„ู…ุจุงุดุฑ";
87
  let liveLink = `https://www.tiktok.com/@${user}/live`;
88
  if (state.roomInfo.live_room_mode === 4 && state.roomInfo.owner) {
89
  liveLink = `https://www.tiktok.com/@${state.roomInfo.owner.uniqueId}/live`;
 
96
  connection.on('social', (data) => { if (data.displayType && data.displayType.includes('share')) totalShares++; });
97
 
98
  const handleBox = (data, type) => {
99
+ let coins = data.coins || data.diamonds || data.amount || "ุบูŠุฑ ู…ุญุฏุฏ";
100
+ let sender = data.nickname || (data.user && data.user.nickname) || 'ู…ุฌู‡ูˆู„';
 
 
 
 
 
 
 
101
  sendToTelegram(`๐Ÿ’ฐ <b>ุชู†ุจูŠู‡ ${type}!</b>\n๐Ÿ‘ค ููŠ ุจุซ: @${user}\n๐ŸŽ ู…ู†: <b>${sender}</b>\n๐Ÿ’Ž ุงู„ู‚ูŠู…ุฉ: <b>${coins} ุนู…ู„ุฉ</b>`);
102
  };
103
 
 
112
  if (!commentersMap[data.userId]) commentersMap[data.userId] = { name: data.nickname, count: 0 };
113
  commentersMap[data.userId].count++;
114
  if (text.length > 1) {
115
+ if (!fastCommentCounter[text]) fastCommentCounter[text] = [];
116
  fastCommentCounter[text].push(now);
117
  fastCommentCounter[text] = fastCommentCounter[text].filter(ts => now - ts < 60000);
118
+ if (fastCommentCounter[text].length >= 100 && !alertedComments.has(text)) {
119
  alertedComments.add(text);
120
  sendToTelegram(`โš ๏ธ <b>ุณุจุงู… ุณุฑูŠุน @${user}!</b>\n๐Ÿ’ฌ "<code>${text}</code>"\n๐Ÿ”ฅ ุชูƒุฑุฑ 100 ู…ุฑุฉ ููŠ ุฏู‚ูŠู‚ุฉ!`);
121
  setTimeout(() => alertedComments.delete(text), 300000);
 
135
  });
136
 
137
  connection.on('member', (data) => {
138
+ if (data.isModerator && !adminsSeen.has(data.uniqueId)) {
139
  adminsSeen.add(data.uniqueId);
140
  sendToTelegram(`๐Ÿ›ก๏ธ <b>ู…ุดุฑู ุฏุฎู„ ุจุซ @${user}:</b>\n๐Ÿ‘ค <code>@${data.uniqueId}</code>`);
141
  }
142
+ // ุงู„ุชุนุฏูŠู„: ุชุฑุญูŠุจ VIP ู…ู† ู„ูู„ 30 ูˆููˆู‚
143
  if (data.userLevel >= 30) sendToTelegram(`๐Ÿ‘‘ <b>ุฏุฎูˆู„ VIP (Lvl ${data.userLevel})</b>\n๐Ÿ‘ค ุจุซ @${user}: <code>@${data.uniqueId}</code>`);
144
  });
145
 
146
  connection.on('gift', (data) => {
147
+ if (data.giftType === 1 && !data.repeatEnd) return;
148
  let giftCost = data.diamondCount * data.repeatCount;
149
  if (!giftersMap[data.userId]) giftersMap[data.userId] = { name: data.nickname, coins: 0 };
150
  giftersMap[data.userId].coins += giftCost;
 
152
  });
153
 
154
  connection.on('disconnected', () => {
155
+ // ุงู„ุชุนุฏูŠู„: ุญุณุงุจ ุงู„ู…ุฏู‡ ูˆุชุญูˆูŠู„ู‡ุง ู„ุณุงุนุงุช ุฅุฐุง ุชุฌุงูˆุฒุช 60 ุฏู‚๏ฟฝ๏ฟฝู‚ุฉ
156
  const diffMs = new Date() - startTime;
157
+ const totalMinutes = startTime ? Math.floor(diffMs / 60000) : 0;
158
+ const durationStr = startTime ? formatDuration(totalMinutes) : "ุบูŠุฑ ู…ุญุฏุฏ";
159
 
160
  let sortedGifters = Object.values(giftersMap).sort((a, b) => b.coins - a.coins).slice(0, 3);
161
  let sortedCommenters = Object.values(commentersMap).sort((a, b) => b.count - a.count).slice(0, 5);
162
  let endMsg = `๐Ÿ <b>ู…ู„ุฎุต ุงู„ู†ู‡ุงูŠุฉ (@${user})</b>\nโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\nโฑ๏ธ <b>ุงู„ู…ุฏุฉ:</b> ${durationStr} | ๐Ÿ“… <b>ุงู„ูˆู‚ุช:</b> ${getBaghdadTime()}\n๐Ÿ“Š ๐Ÿ‘๏ธ ${formatK(maxViewers)} | โค๏ธ ${formatK(totalLikes)} | ๐Ÿ”„ ${totalShares}\nโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\n๐Ÿ† <b>ุฃูุถู„ 3 ุฏุงุนู…ูŠู†:</b>\n`;
163
 
164
  sortedGifters.forEach((g, i) => {
165
+ endMsg += `${i === 0 ? '๐Ÿฅ‡' : i === 1 ? '๐Ÿฅˆ' : '๐Ÿฅ‰'} <code>${g.name}</code> : <b>${formatK(g.coins)}</b>\n`;
166
  });
167
 
168
  endMsg += `\n๐Ÿ’ฌ <b>ุฃูƒุซุฑ 5 ู…ุนู„ู‚ูŠู† ุชูุงุนู„ุงู‹:</b>\n`;
 
171
  });
172
 
173
  if (bestGift.cost > 0) endMsg += `\n๐Ÿ’Ž <b>ุฃู‚ูˆู‰ ู‡ุฏูŠุฉ:</b> ${bestGift.name} ู…ู† <b>${bestGift.sender}</b>`;
174
+ sendToTelegram(endMsg, bestGift.icon || null, `https://www.tiktok.com/@${user}/live`);
 
 
175
 
176
  fastCommentCounter = {};
177
  alertedComments = new Set();