TheFirstOython commited on
Commit
b09e481
·
verified ·
1 Parent(s): 4273b2e

Update bot.js

Browse files
Files changed (1) hide show
  1. bot.js +28 -18
bot.js CHANGED
@@ -2,8 +2,9 @@ const TelegramBot = require('node-telegram-bot-api');
2
  const ffmpegInstaller = require('@ffmpeg-installer/ffmpeg');
3
  const ffmpeg = require('fluent-ffmpeg');
4
  const si = require('systeminformation');
 
5
 
6
- const TOKEN = '7963845783:AAGxfbwOCDwAgs_HMy0l0RDVbDVGLe1-Luc';
7
  const ADMIN_ID = 7708913693;
8
 
9
  ffmpeg.setFfmpegPath(ffmpegInstaller.path);
@@ -14,8 +15,8 @@ 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 =>
@@ -57,7 +58,6 @@ function usageExample(chatId) {
57
  );
58
  }
59
 
60
- // /stream
61
  bot.onText(/^\/stream(?:\s+(.+))?$/, async (msg, match) => {
62
  const chatId = msg.chat.id;
63
  const argsText = match[1];
@@ -87,24 +87,37 @@ bot.onText(/^\/stream(?:\s+(.+))?$/, async (msg, match) => {
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] = {};
@@ -146,7 +159,6 @@ bot.onText(/^\/stream(?:\s+(.+))?$/, async (msg, match) => {
146
  }
147
  });
148
 
149
- // /stop
150
  bot.onText(/^\/stop(?:\s+(\d+))?$/, (msg, match) => {
151
  const chatId = msg.chat.id;
152
  const streamId = match[1] ? Number(match[1]) : null;
@@ -163,7 +175,6 @@ bot.onText(/^\/stop(?:\s+(\d+))?$/, (msg, match) => {
163
  delete userStreams[chatId][streamId];
164
  });
165
 
166
- // /check
167
  bot.onText(/\/check/, async (msg) => {
168
  const chatId = msg.chat.id;
169
  try {
@@ -183,7 +194,6 @@ bot.onText(/\/check/, async (msg) => {
183
  }
184
  });
185
 
186
- // أي رسالة لا تطابق الأوامر
187
  bot.on('message', (msg) => {
188
  const chatId = msg.chat.id;
189
  const text = msg.text || "";
 
2
  const ffmpegInstaller = require('@ffmpeg-installer/ffmpeg');
3
  const ffmpeg = require('fluent-ffmpeg');
4
  const si = require('systeminformation');
5
+ const fs = require('fs');
6
 
7
+ const TOKEN = '7963845783:AAG_6-x0GTpKqNWLSlOVFGloSnZftA_K5Qo';
8
  const ADMIN_ID = 7708913693;
9
 
10
  ffmpeg.setFfmpegPath(ffmpegInstaller.path);
 
15
  console.error("❌ polling error:", error.message);
16
  });
17
 
18
+ const userStreams = {};
19
+ const streamCounter = {};
20
 
21
  function getSystemSettings() {
22
  return si.cpu().then(cpu =>
 
58
  );
59
  }
60
 
 
61
  bot.onText(/^\/stream(?:\s+(.+))?$/, async (msg, match) => {
62
  const chatId = msg.chat.id;
63
  const argsText = match[1];
 
87
  ])
88
  .size(resolution);
89
 
90
+ // ✅ معالجة نص الفلاتر بأمان
91
  if (ccText && ccText.trim() !== '') {
92
  const safeText = ccText
93
+ .replace(/\\/g, '\\\\') // Backslash
94
+ .replace(/'/g, "\\\\'") // Single quote
95
+ .replace(/:/g, '\\:') // Colon
96
+ .replace(/\n/g, ' ') // Newlines
97
+ .replace(/[\u0000-\u001F\u007F]/g, ''); // غير القابلة للطباعة
98
+
99
+ const fontPath = '/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf';
100
+ if (fs.existsSync(fontPath)) {
101
+ 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,` +
102
+ `drawtext=fontfile=${fontPath}:text='${safeText}':fontcolor=white:fontsize=24:x=(w-text_w)/2:y=h-text_h-30`;
103
+ command = command.videoFilters(filter);
104
+ } else {
105
+ bot.sendMessage(chatId, `⚠️ لا يمكن عرض النص لأن الخط غير موجود: ${fontPath}`);
106
+ }
107
  }
108
 
109
  const rtmpUrl = `rtmps://live-api-s.facebook.com:443/rtmp/${key}`;
110
  command = command.output(rtmpUrl);
111
 
112
+ // ✅ تسجيل FFmpeg في console
113
+ command
114
+ .on('start', (cmdLine) => {
115
+ console.log(`🎬 FFmpeg بدأ:\n${cmdLine}`);
116
+ })
117
+ .on('stderr', (stderrLine) => {
118
+ console.log(`🪵 FFmpeg: ${stderrLine}`);
119
+ });
120
+
121
  command.run();
122
 
123
  if (!userStreams[chatId]) userStreams[chatId] = {};
 
159
  }
160
  });
161
 
 
162
  bot.onText(/^\/stop(?:\s+(\d+))?$/, (msg, match) => {
163
  const chatId = msg.chat.id;
164
  const streamId = match[1] ? Number(match[1]) : null;
 
175
  delete userStreams[chatId][streamId];
176
  });
177
 
 
178
  bot.onText(/\/check/, async (msg) => {
179
  const chatId = msg.chat.id;
180
  try {
 
194
  }
195
  });
196
 
 
197
  bot.on('message', (msg) => {
198
  const chatId = msg.chat.id;
199
  const text = msg.text || "";