-
Notifications
You must be signed in to change notification settings - Fork 12
/
chatgpt-twitch-bot.ts
50 lines (40 loc) · 1.16 KB
/
chatgpt-twitch-bot.ts
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
import { ChatGPTAPI, getOpenAIAuth } from "chatgpt";
import tmi from "tmi.js";
import dotenv from "dotenv";
dotenv.config();
const client = new tmi.Client({
options: { debug: true },
connection: {
secure: true,
reconnect: true,
},
identity: {
username: process.env.TWITCH_NAME,
password: process.env.TWITCH_TOKEN,
},
channels: [process.env.TWITCH_CHANNEL as string],
});
let chatGPTAPI: ChatGPTAPI;
(async () => {
const openAIAuth = await getOpenAIAuth({
email: process.env.OPENAI_EMAIL,
password: process.env.OPENAI_PASSWORD,
});
chatGPTAPI = new ChatGPTAPI({ ...openAIAuth });
await chatGPTAPI.ensureAuth();
})();
client.connect();
client.on("message", async (channel, tags, message, self) => {
if (self || !message.startsWith("!")) {
return;
}
const args = message.slice(1).split(" ");
const command = args.shift()?.toLowerCase();
if (command === "chatgpt test") {
client.say(channel, `@${tags.username}, test`);
} else if (command === "chatgpt") {
const prompt = args.join(" ");
const response = await chatGPTAPI.sendMessage(prompt);
client.say(channel, `@${tags.username}, ${response}`);
}
});