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

Update bot.js

Browse files
Files changed (1) hide show
  1. bot.js +38 -26
bot.js CHANGED
@@ -10,37 +10,41 @@ ffmpeg.setFfmpegPath(ffmpegInstaller.path);
10
 
11
  const bot = new TelegramBot(TOKEN, { polling: true });
12
 
 
 
 
 
13
  const userStreams = {}; // { chatId: { streamId: { proc, timeout } } }
14
  const streamCounter = {}; // { chatId: number }
15
 
16
  function getSystemSettings() {
17
- return si.cpu()
18
- .then(cpu => si.mem()
19
- .then(mem => {
20
- const cores = cpu.cores || 1;
21
- const ramGB = mem.total / 1024 / 1024 / 1024;
22
-
23
- let preset = 'ultrafast';
24
- if (cores >= 8) preset = 'faster';
25
- else if (cores >= 4) preset = 'veryfast';
26
-
27
- let bitrate = '800k';
28
- let resolution = '640x360';
29
- if (ramGB >= 8) {
30
- bitrate = '3000k';
31
- resolution = '1280x720';
32
- } else if (ramGB >= 4) {
33
- bitrate = '1500k';
34
- resolution = '854x480';
35
- }
36
- return { preset, bitrate, resolution };
37
- })
38
- );
39
  }
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` +
@@ -83,16 +87,24 @@ bot.onText(/^\/stream(?:\s+(.+))?$/, async (msg, match) => {
83
  ])
84
  .size(resolution);
85
 
 
86
  if (ccText && ccText.trim() !== '') {
 
 
 
 
 
 
87
  const filter = `drawbox=x=(w-text_w)/2-10:y=h-text_h-40:w=text_w+20:h=text_h+30:color=black@0.5:t=max,` +
88
- `drawtext=text='${ccText}':fontcolor=white:fontsize=24:x=(w-text_w)/2:y=h-text_h-30`;
 
 
89
  command = command.videoFilters(filter);
90
  }
91
 
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] = {};
@@ -171,7 +183,7 @@ bot.onText(/\/check/, async (msg) => {
171
  }
172
  });
173
 
174
- // Default response
175
  bot.on('message', (msg) => {
176
  const chatId = msg.chat.id;
177
  const text = msg.text || "";
 
10
 
11
  const bot = new TelegramBot(TOKEN, { polling: true });
12
 
13
+ bot.on("polling_error", (error) => {
14
+ console.error("❌ polling error:", error.message);
15
+ });
16
+
17
  const userStreams = {}; // { chatId: { streamId: { proc, timeout } } }
18
  const streamCounter = {}; // { chatId: number }
19
 
20
  function getSystemSettings() {
21
+ return si.cpu().then(cpu =>
22
+ si.mem().then(mem => {
23
+ const cores = cpu.cores || 1;
24
+ const ramGB = mem.total / 1024 / 1024 / 1024;
25
+
26
+ let preset = 'ultrafast';
27
+ if (cores >= 8) preset = 'faster';
28
+ else if (cores >= 4) preset = 'veryfast';
29
+
30
+ let bitrate = '800k';
31
+ let resolution = '640x360';
32
+ if (ramGB >= 8) {
33
+ bitrate = '3000k';
34
+ resolution = '1280x720';
35
+ } else if (ramGB >= 4) {
36
+ bitrate = '1500k';
37
+ resolution = '854x480';
38
+ }
39
+
40
+ return { preset, bitrate, resolution };
41
+ })
42
+ );
43
  }
44
 
45
  function usageExample(chatId) {
46
  return bot.sendMessage(chatId,
47
+ `❌ الأمر غير صحيح أو غير مكتمل.\n\n` +
48
  `استخدم أحد الأوامر التالية:\n\n` +
49
  `/stream streamkey m3u8_url [cc_text]\n` +
50
  `مثال:\n` +
 
87
  ])
88
  .size(resolution);
89
 
90
+ // ✅ إذا تم إدخال نص للـ caption
91
  if (ccText && ccText.trim() !== '') {
92
+ const safeText = ccText
93
+ .replace(/\\/g, '\\\\')
94
+ .replace(/'/g, "\\'")
95
+ .replace(/:/g, '\\:')
96
+ .replace(/\n/g, '');
97
+
98
  const filter = `drawbox=x=(w-text_w)/2-10:y=h-text_h-40:w=text_w+20:h=text_h+30:color=black@0.5:t=max,` +
99
+ `drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf:` +
100
+ `text='${safeText}':fontcolor=white:fontsize=24:x=(w-text_w)/2:y=h-text_h-30`;
101
+
102
  command = command.videoFilters(filter);
103
  }
104
 
105
  const rtmpUrl = `rtmps://live-api-s.facebook.com:443/rtmp/${key}`;
106
  command = command.output(rtmpUrl);
107
 
 
108
  command.run();
109
 
110
  if (!userStreams[chatId]) userStreams[chatId] = {};
 
183
  }
184
  });
185
 
186
+ // أي رسالة لا تطابق الأوامر
187
  bot.on('message', (msg) => {
188
  const chatId = msg.chat.id;
189
  const text = msg.text || "";