zona-bot 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of zona-bot might be problematic. Click here for more details.
- package/README.md +1 -0
- package/config.json +0 -0
- package/main.js +84 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# zona-bot
|
package/config.json
ADDED
|
File without changes
|
package/main.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const TelegramBot = require('node-telegram-bot-api');
|
|
2
|
+
const { exec } = require('child_process');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
|
|
5
|
+
// Ganti 'YOUR_TELEGRAM_BOT_TOKEN' dengan token API bot Telegram Anda
|
|
6
|
+
const bot = new TelegramBot('7038055889:AAHvrOI4I12ZZgqRHRoZdoRz6mShurQROGE', { polling: true });
|
|
7
|
+
|
|
8
|
+
// Tanggapi pesan yang diterima oleh bot
|
|
9
|
+
bot.on('message', (msg) => {
|
|
10
|
+
const chatId = msg.chat.id;
|
|
11
|
+
const message = msg.text;
|
|
12
|
+
|
|
13
|
+
if (message === '/start') {
|
|
14
|
+
// Membuat keyboard inline saat pengguna memulai bot
|
|
15
|
+
bot.sendMessage(chatId, 'Selamat datang! Silakan pilih opsi:', {
|
|
16
|
+
reply_markup: {
|
|
17
|
+
inline_keyboard: [
|
|
18
|
+
[{ text: 'Setel Token NPM', callback_data: 'setToken' }]
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Tanggapi callback dari tombol menu
|
|
26
|
+
bot.on('callback_query', (callbackQuery) => {
|
|
27
|
+
const chatId = callbackQuery.message.chat.id;
|
|
28
|
+
const action = callbackQuery.data;
|
|
29
|
+
|
|
30
|
+
if (action === 'setToken') {
|
|
31
|
+
bot.sendMessage(chatId, 'Silakan masukkan token NPM Anda:');
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Tanggapi pesan yang diterima oleh bot
|
|
36
|
+
bot.on('message', (msg) => {
|
|
37
|
+
const chatId = msg.chat.id;
|
|
38
|
+
const message = msg.text;
|
|
39
|
+
|
|
40
|
+
// Jika pengguna mengirimkan pesan "/settoken <npmToken>"
|
|
41
|
+
if (message.startsWith('/settoken')) {
|
|
42
|
+
const npmToken = message.split(' ')[1];
|
|
43
|
+
// Simpan token npm di berkas konfigurasi
|
|
44
|
+
saveNpmToken(msg.from.id, npmToken);
|
|
45
|
+
bot.sendMessage(chatId, 'Token npm telah disimpan!');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Jika pengguna mengirimkan pesan "/create <nama_package>"
|
|
49
|
+
if (message.startsWith('/create')) {
|
|
50
|
+
const packageName = message.split(' ')[1];
|
|
51
|
+
// Membuat package npm baru
|
|
52
|
+
createNpmPackage(packageName, chatId, msg.from.id);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Fungsi untuk menyimpan token npm klasik untuk setiap pengguna
|
|
57
|
+
function saveNpmToken(userId, npmToken) {
|
|
58
|
+
const config = JSON.parse(fs.readFileSync('config.json'));
|
|
59
|
+
config[userId] = npmToken;
|
|
60
|
+
fs.writeFileSync('config.json', JSON.stringify(config, null, 2));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Fungsi untuk membuat package npm baru
|
|
64
|
+
function createNpmPackage(packageName, chatId, userId) {
|
|
65
|
+
const config = JSON.parse(fs.readFileSync('config.json'));
|
|
66
|
+
const npmToken = config[userId];
|
|
67
|
+
if (!npmToken) {
|
|
68
|
+
bot.sendMessage(chatId, 'Mohon setel token npm terlebih dahulu menggunakan perintah /settoken <npmToken>');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Menjalankan perintah npm publish menggunakan token klasik npmjs
|
|
73
|
+
exec(`npm publish --access public --registry https://registry.npmjs.org --npm-auth-token ${npmToken}`, (error, stdout, stderr) => {
|
|
74
|
+
if (error) {
|
|
75
|
+
bot.sendMessage(chatId, `Gagal membuat package npm: ${error.message}`);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (stderr) {
|
|
79
|
+
bot.sendMessage(chatId, `Gagal membuat package npm: ${stderr}`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
bot.sendMessage(chatId, `Package npm ${packageName} berhasil dibuat dan dipublikasikan!`);
|
|
83
|
+
});
|
|
84
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"dependencies": {
|
|
3
|
+
"fs": "^0.0.1-security",
|
|
4
|
+
"nanoid": "^5.0.7",
|
|
5
|
+
"node": "^20.13.1",
|
|
6
|
+
"node-telegram-bot-api": "^0.65.1"
|
|
7
|
+
},
|
|
8
|
+
"name": "zona-bot",
|
|
9
|
+
"version": "1.0.1",
|
|
10
|
+
"description": "Zona BOT",
|
|
11
|
+
"main": "mian.js",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "start"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/zoonai/zona-bot.git"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"Zona",
|
|
21
|
+
"BOT"
|
|
22
|
+
],
|
|
23
|
+
"author": "Zona",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/zoonai/zona-bot/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/zoonai/zona-bot#readme"
|
|
29
|
+
}
|