-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
41 lines (32 loc) · 1.06 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
import tmi from 'tmi.js'
import { askGPT } from './modules/gpt.js'
import { USER, PASSWORD, CHANNEL, IGNORED_USERS } from './constants/twitch.js';
const client = new tmi.Client({
options: { debug: false },
identity: {
username: USER,
password: PASSWORD
},
channels: [CHANNEL]
})
client.connect()
client.on('message', async (channel, tags, message, self) => {
if (self) return
const {username, ['display-name']: displayName } = tags
if (IGNORED_USERS.includes(username)) {
return
}
const isChosen = Math.floor(Math.random() * 3) === 0
const isLongMessage = message.length > 30
if (isChosen && isLongMessage) {
const { personality, total_tokens, content } = await askGPT(message)
if (personality === "error" || total_tokens === 0) {
return
}
client.say(channel, `@${username}: ` + personality + ' -> ' + content)
console.log(` ${displayName}: ${message}`)
console.log(`personalidad: ${personality} respuesta: ${content}`)
} else if (username === 'niv3k_el_pato') {
client.say(channel, '*quack*')
}
})