-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathappV2.js
185 lines (169 loc) · 6.88 KB
/
appV2.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
require('dotenv').config();
const {
Client,
Events,
SectionsBuilder
} = require("@mengkodingan/ckptw");
const {
S_WHATSAPP_NET
} = require("@whiskeysockets/baileys");
const {
createSSHAccount,
createVlessAccount,
createTrojanAccount,
createVmessAccount,
createShadowsocksAccount
} = require('@fightertunnel/createft');
let config = {
admin: {
id: process.env.ADMIN_ID,
number: process.env.ADMIN_NUMBER
},
bot: {}
};
const usePairingCode = true;
const phoneNumber = process.env.PHONE_NUMBER;
const defaultServer = process.env.DEFAULT_SERVER;
const bot = new Client({
prefix: "!",
phoneNumber: phoneNumber,
usePairingCode: usePairingCode,
printQRInTerminal: !usePairingCode,
WAVersion: [2, 3000, 1015901307],
selfReply: true
});
bot.ev.once(Events.ClientReady, async (m) => {
console.log(`[fightertunnel-bot] Bot ready at ${m.user.id}`);
config.bot.number = m.user.id.split(/[:@]/)[0];
config.bot.id = config.bot.number + S_WHATSAPP_NET;
});
bot.ev.on(Events.MessagesUpsert, async (m, ctx) => {});
bot.command("create", async (ctx) => {
const senderId = ctx._sender.jid;
if (senderId !== config.admin.id) {
await ctx.reply("Maaf, hanya admin yang dapat menggunakan perintah ini.");
return;
}
let sectionBuilder = new SectionsBuilder();
sectionBuilder.setDisplayText("Pilih layanan");
["SSH", "VMESS", "TROJAN", "VLESS", "SHADOWSOCKS"].forEach((service) => {
sectionBuilder.addSection({
title: "Layanan",
rows: [{
title: `${service}`,
id: service
}]
});
});
await ctx.sendInteractiveMessage(ctx.id, {
body: "Silakan pilih layanan",
footer: "Pilih layanan untuk melanjutkan",
nativeFlowMessage: {
buttons: [sectionBuilder.build()]
}
});
let promptsSSH = [
"Masukkan nama pengguna (tanpa spasi):",
"Masukkan kata sandi (min 6 karakter):",
"Masukkan masa berlaku (format angka):",
"Masukkan batasan IP (format angka):"
];
let promptsOther = [
"Masukkan nama pengguna (tanpa spasi):",
"Masukkan masa berlaku (format angka):",
"Masukkan kuota (format angka):",
"Masukkan batasan IP (format angka):"
];
let data = {};
let currentStep = 0;
let selectedService;
let col = ctx.MessageCollector({
time: 60000
});
col.on("collect", async (m) => {
const content = m.content;
if (!selectedService) {
const validServices = ["SSH", "VMESS", "TROJAN", "VLESS", "SHADOWSOCKS"];
if (validServices.includes(content.toUpperCase())) {
selectedService = content.toUpperCase();
await ctx.reply(`${selectedService} dipilih. Silakan masukkan detail berikut.`);
await ctx.reply(selectedService === "SSH" ? promptsSSH[currentStep] : promptsOther[currentStep]);
} else {
await ctx.reply("Layanan tidak valid. Pilih salah satu dari: SSH, VMESS, TROJAN, VLESS, SHADOWSOCKS.");
}
} else {
if (selectedService === "SSH") {
switch (currentStep) {
case 0:
if (/\s/.test(content)) return await ctx.reply("Nama pengguna tidak boleh mengandung spasi.");
data.username = content;
break;
case 1:
if (content.length < 6) return await ctx.reply("Password minimal harus 6 karakter.");
data.password = content;
break;
case 2:
if (!/^\d+$/.test(content)) return await ctx.reply("Masa berlaku harus berupa angka.");
if (parseInt(content, 10) > 30) return await ctx.reply("Masa berlaku tidak boleh lebih dari 30 hari.");
data.expiry = content;
break;
case 3:
if (!/^\d+$/.test(content)) return await ctx.reply("Batasan IP harus berupa angka.");
data.iplimit = content;
break;
}
} else {
switch (currentStep) {
case 0:
if (/\s/.test(content)) return await ctx.reply("Nama pengguna tidak boleh mengandung spasi.");
data.username = content;
break;
case 1:
if (!/^\d+$/.test(content)) return await ctx.reply("Masa berlaku harus berupa angka.");
if (parseInt(content, 10) > 30) return await ctx.reply("Masa berlaku tidak boleh lebih dari 30 hari.");
data.expiry = content;
break;
case 2:
if (!/^\d+$/.test(content)) return await ctx.reply("Kuota harus berupa angka.");
data.quota = content;
break;
case 3:
if (!/^\d+$/.test(content)) return await ctx.reply("Batasan IP harus berupa angka.");
data.iplimit = content;
break;
}
}
currentStep++;
if (currentStep < (selectedService === "SSH" ? promptsSSH.length : promptsOther.length)) {
await ctx.reply(selectedService === "SSH" ? promptsSSH[currentStep] : promptsOther[currentStep]);
} else {
col.stop();
}
}
});
let interactionEnded = false;
col.on("end", async () => {
if (!interactionEnded) {
interactionEnded = true;
if (!selectedService) {
await ctx.reply("Proses dihentikan. Layanan tidak dipilih.");
} else if (currentStep < (selectedService === "SSH" ? promptsSSH.length : promptsOther.length)) {
await ctx.reply("Proses dihentikan sebelum semua data terkumpul.");
} else {
if (selectedService === "VMESS") {
await createVmessAccount(defaultServer, data, ctx);
} else if (selectedService === "TROJAN") {
await createTrojanAccount(defaultServer, data, ctx);
} else if (selectedService === "VLESS") {
await createVlessAccount(defaultServer, data, ctx);
} else if (selectedService === "SHADOWSOCKS") {
await createShadowsocksAccount(defaultServer, data, ctx);
} else if (selectedService === "SSH") {
await createSSHAccount(defaultServer, data, ctx);
}
}
console.log(`[fightertunnel-bot] Interaction ended.`);
}
});
});
bot.launch().catch((error) => console.error("[fightertunnel-bot] Error:", error));