-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (55 loc) · 2.05 KB
/
Copy pathindex.js
File metadata and controls
63 lines (55 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const TelegramBot = require('node-telegram-bot-api');
const { exec } = require('child_process');
// Ganti dengan token bot Telegram Anda
const token = '5880279021:AAG_m5WGwA1U-g03Hbe5GMBVzcj5rFD_SLA';
// Inisialisasi bot dengan token
const bot = new TelegramBot(token, { polling: true });
// Fungsi untuk mencatat aktivitas penggunaan bot di console log
function logActivity(msg) {
const user = msg.from;
const chat = msg.chat;
const command = msg.text.toLowerCase();
console.log(`Aktivitas Penggunaan Bot Telegram`);
console.log(`• User ID: ${user.id}`);
console.log(`• Username: ${user.username || 'Tidak ada'}`);
console.log(`• Chat ID: ${chat.id}`);
console.log(`• Perintah: ${command}`);
}
// Event listener untuk pesan dari pengguna
bot.on('message', (msg) => {
const chatId = msg.chat.id;
const command = msg.text.toLowerCase();
// Mencatat aktivitas penggunaan bot di console log
logActivity(msg);
// Menanggapi perintah /mix
if (command.startsWith('/mix')) {
// Mengekstrak argumen dari pesan
const args = command.split(' ');
const url = args[1];
const time = args[2];
const thread = args[3];
const rate = args[4];
// Memeriksa apakah format pesan benar
if (args.length === 5 && url && time && thread && rate) {
// Menjalankan file mix.js dengan argumen yang diberikan
exec(`node mix.js ${url} ${time} ${thread} ${rate}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
bot.sendMessage(chatId, 'Successful');
return;
}
if (stderr) {
console.error(`stderr: ${stderr}`);
bot.sendMessage(chatId, 'Successful');
return;
}
// Menampilkan output stdout jika berhasil
console.log(`stdout: ${stdout}`);
bot.sendMessage(chatId, 'Proses telah dimulai.');
});
} else {
// Memberi tahu pengguna bahwa format pesan tidak benar
bot.sendMessage(chatId, 'Format pesan tidak benar. Gunakan format: /mix [url] [time] [thread] [rate]');
}
}
});