Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
329 lines (293 loc) · 8.91 KB
/
Copy pathindex.js
File metadata and controls
329 lines (293 loc) · 8.91 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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*
Thanks TO
- Miftah
- User
Note: Please don't delete my name
*/
const TelegramBot = require('node-telegram-bot-api');
const axios = require('axios');
require('./config');
const bot = new TelegramBot(botToken, { polling: true });
let activeAiMode = '';
let activeAiStopButton = '';
function getUserName(msg) {
return msg.from.first_name;
}
function getGreetingMessage() {
const now = new Date().getHours() + 7;
if (now >= 0 && now < 6) {
return 'udah malam belum tidur?';
} else if (now >= 6 && now < 12) {
return 'Selamat Pagi!';
} else if (now >= 12 && now < 15) {
return 'Selamat Siang!';
} else if (now >= 15 && now < 18) {
return 'Selamat Sore!';
} else {
return 'Selamat Malam!';
}
}
bot.onText(/\/start/, (msg) => {
const chatId = msg.chat.id;
const options = {
reply_markup: {
keyboard: [
['Bing', 'Simi'],
['Gemini', 'Gptweb'],
['ITzpire', 'Llama2'],
['Mistral', 'Palm'],
['You', 'Toolbot'],
['Blackbox', 'Stop']
],
resize_keyboard: true,
one_time_keyboard: true
}
};
const userName = getUserName(msg);
const greetingMessage = getGreetingMessage();
bot.sendMessage(chatId, `Halo ${userName}! ${greetingMessage} Pilih salah satu opsi:`, options);
});
bot.onText(/Blackbox/, (msg) => {
const chatId = msg.chat.id;
activeAiMode = 'blackbox';
activeAiStopButton = '/stop_blackbox';
bot.sendMessage(chatId, 'Mode Blackbox AI telah dipilih.');
});
bot.onText(/Toolbot/, (msg) => {
const chatId = msg.chat.id;
activeAiMode = 'toolbot';
activeAiStopButton = '/stop_bing';
bot.sendMessage(chatId, 'Mode Toolbot AI telah dipilih.');
});
bot.onText(/You/, (msg) => {
const chatId = msg.chat.id;
activeAiMode = 'you';
activeAiStopButton = '/stop_you';
bot.sendMessage(chatId, 'Mode You AI telah dipilih.');
});
bot.onText(/Palm/, (msg) => {
const chatId = msg.chat.id;
activeAiMode = 'palm';
activeAiStopButton = '/stop_palm';
bot.sendMessage(chatId, 'Mode Palm AI telah dipilih.');
});
bot.onText(/Mistral/, (msg) => {
const chatId = msg.chat.id;
activeAiMode = 'mistral';
activeAiStopButton = '/stop_mistral';
bot.sendMessage(chatId, 'Mode Mistral AI telah dipilih.');
});
bot.onText(/Bing/, (msg) => {
const chatId = msg.chat.id;
activeAiMode = 'bing';
activeAiStopButton = '/stop_bing';
bot.sendMessage(chatId, 'Mode Bing AI telah dipilih.');
});
bot.onText(/Gemini/, (msg) => {
const chatId = msg.chat.id;
activeAiMode = 'gemini';
activeAiStopButton = '/stop_gemini';
bot.sendMessage(chatId, 'Mode Gemini AI telah dipilih.');
});
bot.onText(/Gptweb/, (msg) => {
const chatId = msg.chat.id;
activeAiMode = 'gptweb';
activeAiStopButton = '/stop_gptweb';
bot.sendMessage(chatId, 'Mode Gptweb AI telah dipilih.');
});
bot.onText(/ITzpire/, (msg) => {
const chatId = msg.chat.id;
activeAiMode = 'itzpire';
activeAiStopButton = '/stop_itzpire';
bot.sendMessage(chatId, 'Mode ITzpire AI telah dipilih.');
});
bot.onText(/Llama2/, (msg) => {
const chatId = msg.chat.id;
activeAiMode = 'llama2';
activeAiStopButton = '/stop_llama2';
bot.sendMessage(chatId, 'Mode Llama2 AI telah dipilih.');
});
bot.onText(/Simi/, (msg) => {
const chatId = msg.chat.id;
activeAiMode = 'simi';
activeAiStopButton = '/stop_simi';
bot.sendMessage(chatId, 'Mode Simi telah dipilih.');
});
bot.onText(/Stop/, (msg) => {
const chatId = msg.chat.id;
activeAiMode = '';
activeAiStopButton = '';
console.log(`[USER ${msg.from.first_name} ID:${chatId}] menghentikan AI.`);
bot.sendMessage(chatId, 'AI telah dihentikan.');
});
bot.onText(/\/owner/, (msg) => {
const chatId = msg.chat.id;
console.log(`[USER ${msg.from.first_name} ID:${chatId}] meminta informasi kontak owner.`);
bot.sendContact(chatId, ownerContact.phoneNumber, ownerContact.firstName, { last_name: ownerContact.lastName });
});
bot.onText(/\/donasi/, (msg) => {
const chatId = msg.chat.id;
console.log(`[USER ${msg.from.first_name} ID:${chatId}] meminta informasi donasi.`);
bot.sendPhoto(chatId, qrisImage, { caption: 'Terima kasih atas donasi Anda. Silakan scan QRIS di bawah ini untuk melakukan pembayaran.' });
});
bot.on('message', async (msg) => {
const chatId = msg.chat.id;
const text = msg.text;
if (activeAiMode === 'bing') {
try {
const response = await axios.get(api + '/ai/bing-ai', {
params: {
model: "Balanced",
q: text
},
});
const answer = response.data.result;
bot.sendMessage(chatId, answer);
} catch (error) {
console.error(error);
bot.sendMessage(chatId, 'Maaf, terjadi kesalahan saat memproses permintaan Anda.');
}
} else if (activeAiMode === 'palm') {
try {
const response = await axios.get(api + '/ai/palm-ai', {
params: {
q: text
},
});
const answer = response.data.result;
bot.sendMessage(chatId, answer);
} catch (error) {
console.error(error);
bot.sendMessage(chatId, 'Maaf, terjadi kesalahan saat memproses permintaan Anda.');
}
} else if (activeAiMode === 'you') {
try {
const response = await axios.get(api + '/ai/you', {
params: {
q: text
},
});
const answer = response.data.result.message;
bot.sendMessage(chatId, answer);
} catch (error) {
console.error(error);
bot.sendMessage(chatId, 'Maaf, terjadi kesalahan saat memproses permintaan Anda.');
}
} else if (activeAiMode === 'toolbot') {
try {
const response = await axios.get(api + '/ai/toolbot', {
params: {
q: text,
description: "You are a helpful assistant."
},
});
const answer = response.data.result;
bot.sendMessage(chatId, answer);
} catch (error) {
console.error(error);
bot.sendMessage(chatId, 'Maaf, terjadi kesalahan saat memproses permintaan Anda.');
}
} else if (activeAiMode === 'llama2') {
try {
const response = await axios.get(api + '/ai/llama2', {
params: {
q: text
},
});
const answer = response.data.result;
bot.sendMessage(chatId, answer);
} catch (error) {
console.error(error);
bot.sendMessage(chatId, 'Maaf, terjadi kesalahan saat memproses permintaan Anda.');
}
} else if (activeAiMode === 'gemini') {
try {
const response = await axios.get(api + '/ai/gemini-ai', {
params: {
q: text
},
});
const answer = response.data.result;
bot.sendMessage(chatId, answer);
} catch (error) {
console.error(error);
bot.sendMessage(chatId, 'Maaf, terjadi kesalahan saat memproses permintaan Anda.');
}
} else if (activeAiMode === 'simi') {
try {
const response = await axios.get(api + '/ai/simi-chat', {
params: {
text: text,
lang: "id",
toxic: toxic
},
});
const answer = response.data.result;
bot.sendMessage(chatId, answer);
} catch (error) {
console.error(error);
bot.sendMessage(chatId, 'Maaf, terjadi kesalahan saat memproses permintaan Anda.');
}
} else if (activeAiMode === 'blackbox') {
try {
const response = await axios.get(api + '/ai/blackbox-ai', {
params: {
q: text
},
});
const answer = response.data.result;
bot.sendMessage(chatId, answer);
} catch (error) {
console.error(error);
bot.sendMessage(chatId, 'Maaf, terjadi kesalahan saat memproses permintaan Anda.');
}
} else if (activeAiMode === 'mistral') {
try {
const response = await axios.get(api + '/ai/mistral', {
params: {
q: text
},
});
const answer = response.data.result;
bot.sendMessage(chatId, answer);
} catch (error) {
console.error(error);
bot.sendMessage(chatId, 'Maaf, terjadi kesalahan saat memproses permintaan Anda.');
}
} else if (activeAiMode === 'itzpire') {
try {
const response = await axios.get(api + '/ai/ITzpire', {
params: {
q: text
},
});
const answer = response.data.result;
bot.sendMessage(chatId, answer);
} catch (error) {
console.error(error);
bot.sendMessage(chatId, 'Maaf, terjadi kesalahan saat memproses permintaan Anda.');
}
} else if (activeAiMode === 'gptweb') {
try {
const response = await axios.get(api + '/ai/gptweb', {
params: {
q: text,
},
});
const answer = response.data.result;
bot.sendMessage(chatId, answer);
} catch (error) {
console.error(error);
bot.sendMessage(chatId, 'Maaf, terjadi kesalahan saat memproses permintaan Anda.');
}
}
});
bot.on('message', async (msg) => {
const chatId = msg.chat.id;
const text = msg.text;
console.log(`[USER ${msg.from.first_name} ID:${chatId}] send text: ${text}`);
});
bot.on('polling_error', (error) => {
console.error(error);
});
console.log('Bot sedang berjalan...');