Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (58 loc) · 2.13 KB
/
Copy pathindex.js
File metadata and controls
60 lines (58 loc) · 2.13 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
const qrcode = require('qrcode-terminal')
const { Client, LocalAuth } = require('whatsapp-web.js')
const { Configuration, OpenAIApi } = require("openai")
const keynya = "Insert Your apikey" //Input your OpenAI api-Key -> https://beta.openai.com/account/api-keys
const configuration = new Configuration({
apiKey: keynya,
});
const openai = new OpenAIApi(configuration);
let { ucaphalo } = require('./lib')
const client = new Client({
puppeteer: {
args: ['--no-sandbox'],
},
authStrategy: new LocalAuth()
});
client.on('qr', qr => {
qrcode.generate(qr, {small: true});
});
client.on('message', async (message) => {
let chat = await message.getChat();
let {from} = message
try {
const body = message.body.toLowerCase()
const prefix = /^[./~!#%^&=\,;:()]/.test(body) ? body.match(/^[./~!#%^&=\,;:()]/gi) : '#'
const isCmd = body.startsWith(prefix);
const args = body.trim().split(/ +/).slice(1);
const ishalo = await ucaphalo(body)
let contact = await message.getContact();
await client.sendSeen(from)
//if (Spamchat) {.... this is Premium features (contact owner)
if (isCmd) {
console.log(`[CMD] From (${contact.pushname}) ~> ${message.body}`)
} else if (ishalo) {
message.reply("hai, ada yang bisa bot bantu?");
} else if (args.length < 2) {
message.reply("Maaf, tolong kasih bot pertanyaan lebih detail & spesifik lagi :)");
} else if (!chat.isGroup) {
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: body,
temperature: 0,
max_tokens: 1000,
top_p: 1,
frequency_penalty: 0.2,
presence_penalty: 0,
});
const resultnya = response.data.choices[0].text;
client.sendMessage(from ,"*OpenAI BOT*" + resultnya);
console.log(`[!] Message From (${contact.pushname}) ~> ${message.body}`)
}
} catch (err) {
console.log(err)
}
});
client.on('ready', () => {
console.log('Client is ready!');
});
client.initialize();