Reooiq96 commited on
Commit
101925f
ยท
verified ยท
1 Parent(s): 608dba2

Update index.js

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