Update index.js
Browse files
index.js
CHANGED
|
@@ -1,37 +1,38 @@
|
|
| 1 |
const { WebcastPushConnection } = require('tiktok-live-connector');
|
| 2 |
const axios = require('axios');
|
| 3 |
const dns = require('dns');
|
|
|
|
| 4 |
|
| 5 |
-
// --- الإعدادات
|
| 6 |
const TIKTOK_USERNAME = "ah_md107";
|
| 7 |
const TELEGRAM_TOKEN = "8576498050:AAHB51H9vLwFhDUFqYWttPaSa5qhPLzQVWE";
|
| 8 |
const TELEGRAM_CHAT_ID = "-1003584586221";
|
| 9 |
const SESSION_ID = "b00764f9693c9ee7482fea8d005837a8";
|
|
|
|
| 10 |
|
| 11 |
-
//
|
| 12 |
dns.setServers(['8.8.8.8']);
|
| 13 |
|
| 14 |
-
// --- المتغيرات العامة
|
| 15 |
let highestHundred = 0;
|
| 16 |
let maxViewers = 0;
|
| 17 |
let totalLikes = 0;
|
| 18 |
-
let totalShares = 0;
|
| 19 |
-
let totalGiftsCount = 0;
|
| 20 |
-
let giftersMap = {}; // ل
|
| 21 |
-
let bestGift = { name: "لا يوجد", cost: 0, sender: "" };
|
| 22 |
-
let startTime = null;
|
| 23 |
-
const FIXED_COUNTRY = "العراق 🇮🇶";
|
| 24 |
|
| 25 |
-
// --- دوال مساعدة
|
| 26 |
|
| 27 |
-
//
|
| 28 |
function formatK(num) {
|
| 29 |
if (num >= 1000000) return (num / 1000000).toFixed(1) + 'M';
|
| 30 |
if (num >= 1000) return (num / 1000).toFixed(1) + 'K';
|
| 31 |
return num.toString();
|
| 32 |
}
|
| 33 |
|
| 34 |
-
//
|
| 35 |
function getBaghdadTime() {
|
| 36 |
return new Intl.DateTimeFormat('ar-IQ', {
|
| 37 |
timeZone: 'Asia/Baghdad',
|
|
@@ -41,7 +42,7 @@ function getBaghdadTime() {
|
|
| 41 |
}).format(new Date());
|
| 42 |
}
|
| 43 |
|
| 44 |
-
//
|
| 45 |
async function sendToTelegram(text) {
|
| 46 |
try {
|
| 47 |
const addrs = await new Promise(r => dns.resolve4('api.telegram.org', (e, a) => r(a)));
|
|
@@ -49,12 +50,12 @@ async function sendToTelegram(text) {
|
|
| 49 |
chat_id: TELEGRAM_CHAT_ID,
|
| 50 |
text: text,
|
| 51 |
parse_mode: 'HTML',
|
| 52 |
-
disable_web_page_preview:
|
| 53 |
}, { headers: { 'Host': 'api.telegram.org' } });
|
| 54 |
-
} catch (e) { console.log("⚠️ خطأ في
|
| 55 |
}
|
| 56 |
|
| 57 |
-
// إعداد ا
|
| 58 |
let tiktokConnection = new WebcastPushConnection(TIKTOK_USERNAME, {
|
| 59 |
processInitialData: true,
|
| 60 |
enableWebsocketUpgrade: true,
|
|
@@ -66,25 +67,27 @@ let tiktokConnection = new WebcastPushConnection(TIKTOK_USERNAME, {
|
|
| 66 |
});
|
| 67 |
|
| 68 |
// ==========================================
|
| 69 |
-
// 🚀 1. عند بداية البث
|
| 70 |
// ==========================================
|
| 71 |
tiktokConnection.connect().then(state => {
|
| 72 |
-
// تصفير العدادات
|
| 73 |
highestHundred = 0; maxViewers = 0; totalLikes = 0;
|
| 74 |
totalShares = 0; totalGiftsCount = 0;
|
| 75 |
giftersMap = {};
|
| 76 |
bestGift = { name: "لا يوجد", cost: 0, sender: "" };
|
| 77 |
-
startTime = new Date();
|
| 78 |
|
| 79 |
const liveLink = `https://www.tiktok.com/@${TIKTOK_USERNAME}/live`;
|
| 80 |
const userImage = state.roomInfo?.owner?.avatar_thumb?.url_list[0] || "";
|
| 81 |
const startStr = getBaghdadTime();
|
| 82 |
|
| 83 |
-
const msg = `
|
| 84 |
-
`
|
| 85 |
-
`
|
| 86 |
-
`
|
| 87 |
-
`
|
|
|
|
|
|
|
| 88 |
|
| 89 |
sendToTelegram(msg);
|
| 90 |
console.log(`✅ تم الاتصال بحساب ${TIKTOK_USERNAME}.`);
|
|
@@ -93,7 +96,7 @@ tiktokConnection.connect().then(state => {
|
|
| 93 |
});
|
| 94 |
|
| 95 |
// ==========================================
|
| 96 |
-
// 🏔️ 2. مراقبة المشاهدين
|
| 97 |
// ==========================================
|
| 98 |
tiktokConnection.on('roomUser', (data) => {
|
| 99 |
const viewers = data.viewerCount;
|
|
@@ -104,10 +107,10 @@ tiktokConnection.on('roomUser', (data) => {
|
|
| 104 |
highestHundred = currentHundred;
|
| 105 |
const liveLink = `https://www.tiktok.com/@${TIKTOK_USERNAME}/live`;
|
| 106 |
|
| 107 |
-
const msg = `
|
| 108 |
-
`
|
| 109 |
-
`
|
| 110 |
-
`🔗
|
| 111 |
sendToTelegram(msg);
|
| 112 |
}
|
| 113 |
});
|
|
@@ -120,35 +123,29 @@ tiktokConnection.on('like', (data) => {
|
|
| 120 |
});
|
| 121 |
|
| 122 |
tiktokConnection.on('social', (data) => {
|
| 123 |
-
// social type 1 means share
|
| 124 |
if (data.displayType === 'pm_mt_guidance_share') {
|
| 125 |
totalShares++;
|
| 126 |
}
|
| 127 |
});
|
| 128 |
|
| 129 |
// ==========================================
|
| 130 |
-
// 🎁 4. الهدايا والداعمين
|
| 131 |
// ==========================================
|
| 132 |
tiktokConnection.on('gift', (data) => {
|
| 133 |
-
|
|
|
|
| 134 |
|
| 135 |
-
// تحديث إجمالي الهدايا
|
| 136 |
totalGiftsCount += 1;
|
| 137 |
-
|
| 138 |
-
// حساب تكلفة الهدية (عدد الماسات * التكرار)
|
| 139 |
let giftCost = data.diamondCount * data.repeatCount;
|
| 140 |
|
| 141 |
-
//
|
| 142 |
let userId = data.userId;
|
| 143 |
if (!giftersMap[userId]) {
|
| 144 |
-
giftersMap[userId] = {
|
| 145 |
-
name: data.nickname,
|
| 146 |
-
coins: 0
|
| 147 |
-
};
|
| 148 |
}
|
| 149 |
giftersMap[userId].coins += giftCost;
|
| 150 |
|
| 151 |
-
//
|
| 152 |
if (giftCost > bestGift.cost) {
|
| 153 |
bestGift = {
|
| 154 |
name: data.giftName,
|
|
@@ -159,12 +156,12 @@ tiktokConnection.on('gift', (data) => {
|
|
| 159 |
});
|
| 160 |
|
| 161 |
// ==========================================
|
| 162 |
-
// 🏁 5.
|
| 163 |
// ==========================================
|
| 164 |
tiktokConnection.on('disconnected', () => {
|
| 165 |
const endTimeStr = getBaghdadTime();
|
| 166 |
|
| 167 |
-
// حساب مدة
|
| 168 |
let durationStr = "غير محدد";
|
| 169 |
if (startTime) {
|
| 170 |
const diffMs = new Date() - startTime;
|
|
@@ -172,36 +169,55 @@ tiktokConnection.on('disconnected', () => {
|
|
| 172 |
durationStr = `${diffMins} دقيقة`;
|
| 173 |
}
|
| 174 |
|
| 175 |
-
//
|
| 176 |
let sortedGifters = Object.values(giftersMap).sort((a, b) => b.coins - a.coins);
|
|
|
|
|
|
|
| 177 |
let top3Msg = "";
|
| 178 |
if (sortedGifters.length > 0) {
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
| 182 |
} else {
|
| 183 |
-
top3Msg = "لا يوجد داعمين";
|
| 184 |
}
|
| 185 |
|
| 186 |
-
const endMsg = `🏁 <b>ملخص نهاية البث</b>\n
|
| 187 |
-
`
|
| 188 |
-
`
|
| 189 |
-
`⏱️ المدة: ${durationStr}\n
|
| 190 |
-
`
|
| 191 |
-
`
|
| 192 |
-
`
|
| 193 |
-
`
|
| 194 |
-
`
|
| 195 |
-
`
|
| 196 |
-
`
|
| 197 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
sendToTelegram(endMsg);
|
| 200 |
|
| 201 |
-
|
| 202 |
-
console.log("⚠️ تم قطع الاتصال، سيتم المحاولة مرة أخرى خلال 30 ثانية...");
|
| 203 |
setTimeout(() => tiktokConnection.connect(), 30000);
|
| 204 |
});
|
| 205 |
|
| 206 |
-
//
|
| 207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
const { WebcastPushConnection } = require('tiktok-live-connector');
|
| 2 |
const axios = require('axios');
|
| 3 |
const dns = require('dns');
|
| 4 |
+
const http = require('http');
|
| 5 |
|
| 6 |
+
// ⚙️ --- الإعدادات ---
|
| 7 |
const TIKTOK_USERNAME = "ah_md107";
|
| 8 |
const TELEGRAM_TOKEN = "8576498050:AAHB51H9vLwFhDUFqYWttPaSa5qhPLzQVWE";
|
| 9 |
const TELEGRAM_CHAT_ID = "-1003584586221";
|
| 10 |
const SESSION_ID = "b00764f9693c9ee7482fea8d005837a8";
|
| 11 |
+
const FIXED_COUNTRY = "العراق 🇮🇶";
|
| 12 |
|
| 13 |
+
// تحسين الاتصال بالسيرفرات
|
| 14 |
dns.setServers(['8.8.8.8']);
|
| 15 |
|
| 16 |
+
// 📊 --- المتغيرات العامة ---
|
| 17 |
let highestHundred = 0;
|
| 18 |
let maxViewers = 0;
|
| 19 |
let totalLikes = 0;
|
| 20 |
+
let totalShares = 0;
|
| 21 |
+
let totalGiftsCount = 0;
|
| 22 |
+
let giftersMap = {}; // سجل الداعمين
|
| 23 |
+
let bestGift = { name: "لا يوجد", cost: 0, sender: "" };
|
| 24 |
+
let startTime = null;
|
|
|
|
| 25 |
|
| 26 |
+
// 🛠️ --- دوال مساعدة ---
|
| 27 |
|
| 28 |
+
// تنسيق الأرقام (1000 => 1K)
|
| 29 |
function formatK(num) {
|
| 30 |
if (num >= 1000000) return (num / 1000000).toFixed(1) + 'M';
|
| 31 |
if (num >= 1000) return (num / 1000).toFixed(1) + 'K';
|
| 32 |
return num.toString();
|
| 33 |
}
|
| 34 |
|
| 35 |
+
// توقيت بغداد
|
| 36 |
function getBaghdadTime() {
|
| 37 |
return new Intl.DateTimeFormat('ar-IQ', {
|
| 38 |
timeZone: 'Asia/Baghdad',
|
|
|
|
| 42 |
}).format(new Date());
|
| 43 |
}
|
| 44 |
|
| 45 |
+
// إرسال للتلجرام
|
| 46 |
async function sendToTelegram(text) {
|
| 47 |
try {
|
| 48 |
const addrs = await new Promise(r => dns.resolve4('api.telegram.org', (e, a) => r(a)));
|
|
|
|
| 50 |
chat_id: TELEGRAM_CHAT_ID,
|
| 51 |
text: text,
|
| 52 |
parse_mode: 'HTML',
|
| 53 |
+
disable_web_page_preview: true // منع ظهور معاينة الرابط لجعل الرسالة أنظف
|
| 54 |
}, { headers: { 'Host': 'api.telegram.org' } });
|
| 55 |
+
} catch (e) { console.log("⚠️ خطأ في التلجرام:", e.message); }
|
| 56 |
}
|
| 57 |
|
| 58 |
+
// إعداد اتصال التيك توك
|
| 59 |
let tiktokConnection = new WebcastPushConnection(TIKTOK_USERNAME, {
|
| 60 |
processInitialData: true,
|
| 61 |
enableWebsocketUpgrade: true,
|
|
|
|
| 67 |
});
|
| 68 |
|
| 69 |
// ==========================================
|
| 70 |
+
// 🚀 1. عند بداية البث
|
| 71 |
// ==========================================
|
| 72 |
tiktokConnection.connect().then(state => {
|
| 73 |
+
// تصفير جميع العدادات
|
| 74 |
highestHundred = 0; maxViewers = 0; totalLikes = 0;
|
| 75 |
totalShares = 0; totalGiftsCount = 0;
|
| 76 |
giftersMap = {};
|
| 77 |
bestGift = { name: "لا يوجد", cost: 0, sender: "" };
|
| 78 |
+
startTime = new Date();
|
| 79 |
|
| 80 |
const liveLink = `https://www.tiktok.com/@${TIKTOK_USERNAME}/live`;
|
| 81 |
const userImage = state.roomInfo?.owner?.avatar_thumb?.url_list[0] || "";
|
| 82 |
const startStr = getBaghdadTime();
|
| 83 |
|
| 84 |
+
const msg = `🔴 <b>انطلاق البث المباشر</b>\n` +
|
| 85 |
+
`─────────────────\n` +
|
| 86 |
+
`👤 <b>الحساب:</b> <code>${TIKTOK_USERNAME}</code>\n` +
|
| 87 |
+
`🌍 <b>الدولة:</b> ${FIXED_COUNTRY}\n` +
|
| 88 |
+
`📅 <b>الوقت :</b> <code>${startStr}</code>\n` +
|
| 89 |
+
`─────────────────\n` +
|
| 90 |
+
`🔗 <a href="${liveLink}"><b>اضغط هنا للدخول للبث</b></a>`;
|
| 91 |
|
| 92 |
sendToTelegram(msg);
|
| 93 |
console.log(`✅ تم الاتصال بحساب ${TIKTOK_USERNAME}.`);
|
|
|
|
| 96 |
});
|
| 97 |
|
| 98 |
// ==========================================
|
| 99 |
+
// 🏔️ 2. مراقبة المشاهدين (تنبيه كل 100)
|
| 100 |
// ==========================================
|
| 101 |
tiktokConnection.on('roomUser', (data) => {
|
| 102 |
const viewers = data.viewerCount;
|
|
|
|
| 107 |
highestHundred = currentHundred;
|
| 108 |
const liveLink = `https://www.tiktok.com/@${TIKTOK_USERNAME}/live`;
|
| 109 |
|
| 110 |
+
const msg = `🚀 <b>إنجاز جديد في المشاهدات!</b>\n\n` +
|
| 111 |
+
`🔢 <b>العدد الحالي:</b> <code>${formatK(viewers)}</code> 👀\n` +
|
| 112 |
+
`🔝 <b>تجاوزنا رقم:</b> <code>${formatK(currentHundred)}</code> 🔥\n` +
|
| 113 |
+
`🔗 <a href="${liveLink}">شاهد البث الآن</a>`;
|
| 114 |
sendToTelegram(msg);
|
| 115 |
}
|
| 116 |
});
|
|
|
|
| 123 |
});
|
| 124 |
|
| 125 |
tiktokConnection.on('social', (data) => {
|
|
|
|
| 126 |
if (data.displayType === 'pm_mt_guidance_share') {
|
| 127 |
totalShares++;
|
| 128 |
}
|
| 129 |
});
|
| 130 |
|
| 131 |
// ==========================================
|
| 132 |
+
// 🎁 4. معالجة الهدايا والداعمين
|
| 133 |
// ==========================================
|
| 134 |
tiktokConnection.on('gift', (data) => {
|
| 135 |
+
// تجاهل الهدية إذا كانت مجرد تكرار لنفس الهدية السابقة (لعدم تكرار الحساب)
|
| 136 |
+
if (data.giftType === 1 && !data.repeatEnd) return;
|
| 137 |
|
|
|
|
| 138 |
totalGiftsCount += 1;
|
|
|
|
|
|
|
| 139 |
let giftCost = data.diamondCount * data.repeatCount;
|
| 140 |
|
| 141 |
+
// تسجيل الداعم (Top 3)
|
| 142 |
let userId = data.userId;
|
| 143 |
if (!giftersMap[userId]) {
|
| 144 |
+
giftersMap[userId] = { name: data.nickname, coins: 0 };
|
|
|
|
|
|
|
|
|
|
| 145 |
}
|
| 146 |
giftersMap[userId].coins += giftCost;
|
| 147 |
|
| 148 |
+
// تسجيل أقوى هدية (Best Gift)
|
| 149 |
if (giftCost > bestGift.cost) {
|
| 150 |
bestGift = {
|
| 151 |
name: data.giftName,
|
|
|
|
| 156 |
});
|
| 157 |
|
| 158 |
// ==========================================
|
| 159 |
+
// 🏁 5. نهاية البث والتقرير الشامل
|
| 160 |
// ==========================================
|
| 161 |
tiktokConnection.on('disconnected', () => {
|
| 162 |
const endTimeStr = getBaghdadTime();
|
| 163 |
|
| 164 |
+
// حساب المدة
|
| 165 |
let durationStr = "غير محدد";
|
| 166 |
if (startTime) {
|
| 167 |
const diffMs = new Date() - startTime;
|
|
|
|
| 169 |
durationStr = `${diffMins} دقيقة`;
|
| 170 |
}
|
| 171 |
|
| 172 |
+
// ترتيب أفضل 3 داعمين
|
| 173 |
let sortedGifters = Object.values(giftersMap).sort((a, b) => b.coins - a.coins);
|
| 174 |
+
|
| 175 |
+
// تجهيز نص الداعمين
|
| 176 |
let top3Msg = "";
|
| 177 |
if (sortedGifters.length > 0) {
|
| 178 |
+
// الأول
|
| 179 |
+
top3Msg += `🥇 <code>${sortedGifters[0].name}</code> : <b>${formatK(sortedGifters[0].coins)}</b>\n`;
|
| 180 |
+
// الثاني
|
| 181 |
+
if (sortedGifters[1]) top3Msg += `🥈 <code>${sortedGifters[1].name}</code> : <b>${formatK(sortedGifters[1].coins)}</b>\n`;
|
| 182 |
+
// الثالث
|
| 183 |
+
if (sortedGifters[2]) top3Msg += `🥉 <code>${sortedGifters[2].name}</code> : <b>${formatK(sortedGifters[2].coins)}</b>\n`;
|
| 184 |
} else {
|
| 185 |
+
top3Msg = "<i>لا يوجد داعمين في هذا البث</i>";
|
| 186 |
}
|
| 187 |
|
| 188 |
+
const endMsg = `🏁 <b>ملخص نهاية البث</b>\n` +
|
| 189 |
+
`─────────────────\n` +
|
| 190 |
+
`👤 <b>المستخدم:</b> <code>${TIKTOK_USERNAME}</code>\n` +
|
| 191 |
+
`⏱️ <b>المدة :</b> ${durationStr}\n` +
|
| 192 |
+
`📅 <b>انتهى في:</b> ${endTimeStr}\n` +
|
| 193 |
+
`─────────────────\n` +
|
| 194 |
+
`📊 <b>الإحصائيات العامة:</b>\n` +
|
| 195 |
+
`👁️ <code>${formatK(maxViewers)}</code> مشاهدة\n` +
|
| 196 |
+
`❤️ <code>${formatK(totalLikes)}</code> إعجاب\n` +
|
| 197 |
+
`🔄 <code>${formatK(totalShares)}</code> مشاركة\n\n` +
|
| 198 |
+
`💎 <b>أقوى هدية وصلت:</b>\n` +
|
| 199 |
+
`🎁 الهدية: <b>${bestGift.name}</b>\n` +
|
| 200 |
+
`💰 القيمة: <code>${formatK(bestGift.cost)}</code>\n` +
|
| 201 |
+
`👤 المرسل: <code>${bestGift.sender}</code>\n\n` +
|
| 202 |
+
`🏆 <b>أفضل 3 داعمين:</b>\n` +
|
| 203 |
+
`${top3Msg}`;
|
| 204 |
|
| 205 |
sendToTelegram(endMsg);
|
| 206 |
|
| 207 |
+
console.log("⚠️ انتهى البث. إعادة الاتصال خلال 30 ثانية...");
|
|
|
|
| 208 |
setTimeout(() => tiktokConnection.connect(), 30000);
|
| 209 |
});
|
| 210 |
|
| 211 |
+
// معالجة الأخطاء العامة
|
| 212 |
+
tiktokConnection.on('error', err => {
|
| 213 |
+
console.error('Error:', err);
|
| 214 |
+
});
|
| 215 |
+
|
| 216 |
+
// سيرفر ويب بسيط (لإبقاء البوت يعمل 24/7)
|
| 217 |
+
const server = http.createServer((req, res) => {
|
| 218 |
+
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
| 219 |
+
res.end('TikTok Radar is Active 24/7');
|
| 220 |
+
});
|
| 221 |
+
server.listen(7860, () => {
|
| 222 |
+
console.log("🌐 السيرفر يعمل على المنفذ 7860");
|
| 223 |
+
});
|