-
Notifications
You must be signed in to change notification settings - Fork 43
/
index.js
66 lines (58 loc) · 2.11 KB
/
index.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
import axios from "axios";
import { Client } from "fca-utils";
import { Configuration, OpenAIApi } from "openai";
const config = new Configuration({
apiKey: process.env.OPENAI_KEY
})
const openai = new OpenAIApi(config);
const client = new Client({
prefix: process.env.PREFIX,
ignoreMessageInCommandEvent: true
})
client.openServer(process.env.PORT);
client.loginWithAppState(process.env.APPSTATE);
client.on('ready', (_, bid) => console.log("Logged in as", bid, `[${process.env.PREFIX}]`));
client.on('command', (command) => {
if (command.name === "ai") {
openai.createChatCompletion({
model: "gpt-3.5-turbo",
max_tokens: 1000,
n: 1,
messages: [{
role: "user",
content: command.commandArgs.join(" ")
}]
}).then(async res => {
try {
const parsedContent = (await axios.get(`https://xva-api.up.railway.app/api/extractgpt?content=${encodeURIComponent(res.data.choices[0].message.content)}&maxCharacterPerLine=6000`)).data;
const result = parsedContent.data.result;
for (let i = 0; i < result.length; i++) {
await command.message[i === 0 ? "reply" : "send"](result[i])
await new Promise(resolve => setTimeout(resolve, 500));
}
} catch (e) {
console.error(e.response.data);
command.message.reply("An error occurred!")
}
}).catch(e => {
console.error(e.response.data);
command.message.reply("An error occurred!")
})
}
if (command.name === "create") {
openai.createImage({
prompt: command.commandArgs.join(" "),
size: "512x512",
response_format: "url"
}).then(res => {
command.message.sendAttachment(res.data.data[0].url);
}).catch(e => {
console.error(e.response.data);
command.message.reply("An error occurred!")
})
}
})
client.on('error', (e) => {
console.error("login error");
console.error(e);
})