Update index.js
Browse files
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 |
-
|
|
|
|
|
|
|
| 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
|
| 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
|
| 38 |
-
let formattedText = targetLink
|
| 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 |
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 &&
|
| 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 &&
|
| 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 &&
|
| 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
|
| 158 |
-
const durationStr = startTime
|
| 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
|
| 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 |
|
|
|
|
|
|
|
| 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();
|