Spaces:
Paused
Paused
Update bot.js
Browse files
bot.js
CHANGED
|
@@ -3,7 +3,7 @@ const ffmpegInstaller = require('@ffmpeg-installer/ffmpeg');
|
|
| 3 |
const ffmpeg = require('fluent-ffmpeg');
|
| 4 |
const si = require('systeminformation');
|
| 5 |
|
| 6 |
-
const TOKEN = '7963845783:AAG_6-
|
| 7 |
const ADMIN_ID = 7708913693;
|
| 8 |
|
| 9 |
ffmpeg.setFfmpegPath(ffmpegInstaller.path);
|
|
@@ -40,7 +40,7 @@ function getSystemSettings() {
|
|
| 40 |
|
| 41 |
function usageExample(chatId) {
|
| 42 |
return bot.sendMessage(chatId,
|
| 43 |
-
`❌ الأمر غير صحيح أو
|
| 44 |
`استخدم أحد الأوامر التالية:\n\n` +
|
| 45 |
`/stream streamkey m3u8_url [cc_text]\n` +
|
| 46 |
`مثال:\n` +
|
|
@@ -92,14 +92,15 @@ bot.onText(/^\/stream(?:\s+(.+))?$/, async (msg, match) => {
|
|
| 92 |
const rtmpUrl = `rtmps://live-api-s.facebook.com:443/rtmp/${key}`;
|
| 93 |
command = command.output(rtmpUrl);
|
| 94 |
|
| 95 |
-
|
|
|
|
| 96 |
|
| 97 |
if (!userStreams[chatId]) userStreams[chatId] = {};
|
| 98 |
-
userStreams[chatId][streamId] = { proc };
|
| 99 |
|
| 100 |
const timeout = setTimeout(() => {
|
| 101 |
-
if (
|
| 102 |
-
|
| 103 |
bot.sendMessage(chatId, `⏹️ تم إيقاف البث معرف ${streamId} تلقائياً بعد 4 ساعات.`);
|
| 104 |
delete userStreams[chatId][streamId];
|
| 105 |
}
|
|
@@ -116,20 +117,16 @@ bot.onText(/^\/stream(?:\s+(.+))?$/, async (msg, match) => {
|
|
| 116 |
`⏳ سيتم إيقاف البث تلقائياً بعد 4 ساعات`
|
| 117 |
);
|
| 118 |
|
| 119 |
-
|
| 120 |
bot.sendMessage(chatId, `❌ حدث خطأ في البث معرف ${streamId}:\n${err.message}`);
|
| 121 |
clearTimeout(timeout);
|
| 122 |
-
delete userStreams[chatId][streamId];
|
| 123 |
});
|
| 124 |
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
bot.sendMessage(chatId, `⏹️ تم إيقاف البث معرف ${streamId}.`);
|
| 128 |
-
} else if (code !== 0) {
|
| 129 |
-
bot.sendMessage(chatId, `⚠️ البث معرف ${streamId} انتهى برمز خروج ${code}.`);
|
| 130 |
-
}
|
| 131 |
clearTimeout(timeout);
|
| 132 |
-
delete userStreams[chatId][streamId];
|
| 133 |
});
|
| 134 |
|
| 135 |
} catch (e) {
|
|
@@ -148,14 +145,10 @@ bot.onText(/^\/stop(?:\s+(\d+))?$/, (msg, match) => {
|
|
| 148 |
}
|
| 149 |
|
| 150 |
const { proc, timeout } = userStreams[chatId][streamId];
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
delete userStreams[chatId][streamId];
|
| 156 |
-
} else {
|
| 157 |
-
bot.sendMessage(chatId, `⚠️ البث معرف ${streamId} متوقف بالفعل.`);
|
| 158 |
-
}
|
| 159 |
});
|
| 160 |
|
| 161 |
// /check
|
|
@@ -178,7 +171,7 @@ bot.onText(/\/check/, async (msg) => {
|
|
| 178 |
}
|
| 179 |
});
|
| 180 |
|
| 181 |
-
//
|
| 182 |
bot.on('message', (msg) => {
|
| 183 |
const chatId = msg.chat.id;
|
| 184 |
const text = msg.text || "";
|
|
|
|
| 3 |
const ffmpeg = require('fluent-ffmpeg');
|
| 4 |
const si = require('systeminformation');
|
| 5 |
|
| 6 |
+
const TOKEN = '7963845783:AAG_6-x0GTpKqNWLSlOVFGloSnZftA_K5Qo';
|
| 7 |
const ADMIN_ID = 7708913693;
|
| 8 |
|
| 9 |
ffmpeg.setFfmpegPath(ffmpegInstaller.path);
|
|
|
|
| 40 |
|
| 41 |
function usageExample(chatId) {
|
| 42 |
return bot.sendMessage(chatId,
|
| 43 |
+
`❌ الأمر غير صحيح أو gير مكتمل.\n\n` +
|
| 44 |
`استخدم أحد الأوامر التالية:\n\n` +
|
| 45 |
`/stream streamkey m3u8_url [cc_text]\n` +
|
| 46 |
`مثال:\n` +
|
|
|
|
| 92 |
const rtmpUrl = `rtmps://live-api-s.facebook.com:443/rtmp/${key}`;
|
| 93 |
command = command.output(rtmpUrl);
|
| 94 |
|
| 95 |
+
// Use run() instead of spawn()
|
| 96 |
+
command.run();
|
| 97 |
|
| 98 |
if (!userStreams[chatId]) userStreams[chatId] = {};
|
| 99 |
+
userStreams[chatId][streamId] = { proc: command };
|
| 100 |
|
| 101 |
const timeout = setTimeout(() => {
|
| 102 |
+
if (userStreams[chatId] && userStreams[chatId][streamId]) {
|
| 103 |
+
command.kill('SIGTERM');
|
| 104 |
bot.sendMessage(chatId, `⏹️ تم إيقاف البث معرف ${streamId} تلقائياً بعد 4 ساعات.`);
|
| 105 |
delete userStreams[chatId][streamId];
|
| 106 |
}
|
|
|
|
| 117 |
`⏳ سيتم إيقاف البث تلقائياً بعد 4 ساعات`
|
| 118 |
);
|
| 119 |
|
| 120 |
+
command.on('error', err => {
|
| 121 |
bot.sendMessage(chatId, `❌ حدث خطأ في البث معرف ${streamId}:\n${err.message}`);
|
| 122 |
clearTimeout(timeout);
|
| 123 |
+
if (userStreams[chatId]) delete userStreams[chatId][streamId];
|
| 124 |
});
|
| 125 |
|
| 126 |
+
command.on('end', () => {
|
| 127 |
+
bot.sendMessage(chatId, `⏹️ تم إيقاف البث معرف ${streamId}.`);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
clearTimeout(timeout);
|
| 129 |
+
if (userStreams[chatId]) delete userStreams[chatId][streamId];
|
| 130 |
});
|
| 131 |
|
| 132 |
} catch (e) {
|
|
|
|
| 145 |
}
|
| 146 |
|
| 147 |
const { proc, timeout } = userStreams[chatId][streamId];
|
| 148 |
+
proc.kill('SIGTERM');
|
| 149 |
+
clearTimeout(timeout);
|
| 150 |
+
bot.sendMessage(chatId, `⏹️ تم إيقاف البث معرف ${streamId} من قبلك.`);
|
| 151 |
+
delete userStreams[chatId][streamId];
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
});
|
| 153 |
|
| 154 |
// /check
|
|
|
|
| 171 |
}
|
| 172 |
});
|
| 173 |
|
| 174 |
+
// Default response
|
| 175 |
bot.on('message', (msg) => {
|
| 176 |
const chatId = msg.chat.id;
|
| 177 |
const text = msg.text || "";
|