TheFirstOython commited on
Commit
c424cef
·
verified ·
1 Parent(s): 44ca9c8

Update bot.js

Browse files
Files changed (1) hide show
  1. bot.js +17 -24
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-x0GTpKqNWLSlOVFgloSnZftA_K5Qo';
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
- `❌ الأمر غير صحيح أو غير مكتمل.\n\n` +
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
- const proc = command.spawn();
 
96
 
97
  if (!userStreams[chatId]) userStreams[chatId] = {};
98
- userStreams[chatId][streamId] = { proc };
99
 
100
  const timeout = setTimeout(() => {
101
- if (proc && !proc.killed) {
102
- proc.kill('SIGTERM');
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
- proc.on('error', err => {
120
  bot.sendMessage(chatId, `❌ حدث خطأ في البث معرف ${streamId}:\n${err.message}`);
121
  clearTimeout(timeout);
122
- delete userStreams[chatId][streamId];
123
  });
124
 
125
- proc.on('exit', (code, signal) => {
126
- if (signal === 'SIGTERM') {
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
- if (proc && !proc.killed) {
152
- proc.kill('SIGTERM');
153
- clearTimeout(timeout);
154
- bot.sendMessage(chatId, `⏹️ تم إيقاف البث معرف ${streamId} من قبلك.`);
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 || "";