File size: 1,513 Bytes
f071343
 
2feb1a6
 
 
 
 
 
 
 
 
 
 
f071343
2feb1a6
 
f071343
 
2feb1a6
 
f071343
 
 
 
 
 
 
 
 
 
 
 
2feb1a6
 
 
 
 
 
d71e088
 
 
 
 
 
2feb1a6
f071343
 
 
 
2feb1a6
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 { ChatClient } from "@kararty/dank-twitch-irc"

const promptQueue: string[] = []

const lowerCaseName = process.env.WEBTV_TWITCH_BOT_USERNAME
const username = lowerCaseName
const channel = lowerCaseName

const fullCaseName = "AI_WebTV"

// https://dev.twitch.tv/docs/irc/authenticate-bot/
// ex to generate a token:
// https://id.twitch.tv/oauth2/authorize?response_type=token&client_id=<CLIENTID>&redirect_uri=http://localhost&scope=chat%3Aread+chat%3Aedit
const client = new ChatClient({
  username,
  password: `oauth:${process.env.WEBTV_TWITCH_BOT_TOKEN}`,
})



client.on("ready", () => {
  console.log("Successfully connected to chat")
})

client.on("close", (error) => {
  if (error != null) {
    console.error("Client closed due to error", error)
  }
})

client.on("PRIVMSG", (msg) => {
  console.log(`[#${msg.channelName}] ${msg.displayName}: ${msg.messageText}`)
  const words = msg.messageText.split(" ")
  const [command, ...rest] = words

  if (msg.channelName === channel && words.includes(`@${fullCaseName}`)) {
    console.log("We have been directly mentioned")

    client.say(channel, "yes, my lord?")
    // TODO: we should use a chatbot eg. HuggingChat to add prompts to the queue
  } else if (command === "!queue") {
    client.say(channel, `there are ${promptQueue.length} prompts in the queue`)
  } else if (command === "!add") {
    client.say(channel, "adding prompts to the queue isn't supported yet")
  }
})

// See below for more events
client.connect()
client.join("ai_webtv")