-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
52 lines (43 loc) · 1.16 KB
/
app.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
// Imports
import dotenv from 'dotenv'
import http from 'http'
import express from 'express'
import socketIo from 'socket.io'
import tmi from 'tmi.js'
// Set dotenv
dotenv.config()
// Express.js + Socket.IO
const app = express()
const server = http.createServer(app)
const io = socketIo(server)
const port = process.env.PORT
app.use(express.static('overlay'))
app.get('/', (req, res) => res.sendFile(__dirname + '/overlay/overlay.html'))
server.listen(port, () => console.log(`Your overlay URL: http://localhost:${port}`))
// tmi.js
const client = new tmi.Client({
options: {
debug: true
},
connection: {
secure: true,
reconnect: true
},
identity: {
username: process.env.TWITCH_USERNAME,
password: process.env.TWITCH_PASSWORD
},
channels: [process.env.TWITCH_CHANNEL]
})
client.connect()
// Message received
client.on('message', (channel, tags, message, self) => {
if (self) return
// Detect !train
if (message.toLowerCase() === '!train' || message.startsWith('!train')) {
// Emit train key
io.emit('train')
// Say in chat
client.say(process.env.TWITCH_CHANNEL, `@${tags.username}, hop on! Train is about to leave!`)
}
})