-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tpp-inputcheck.js
46 lines (35 loc) · 1.3 KB
/
tpp-inputcheck.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
// define configuration options
const tmi = require('tmi.js')
const cache = {}
const focus = process.argv.slice(2)
// create a client with our options
const client = new tmi.Client({
identity: { username: "justinfan1986", password: "kappa" },
channels: [ "twitchplayspokemon" ],
})
// our pretty printer
function printMessage(message) {
console.log(new Date().toLocaleTimeString(), message)
}
// event handlers
function onMessageHandler(channel, userdata, message, self) {
const name = userdata.username
if (name === "tpp" || name === "tppsimulator") return
if (focus.length > 0 && !focus.includes(name)) return
const currTime = new Date().getTime()
if (cache[name]) {
const prevTime = cache[name]
const millis = currTime - prevTime
const minutes = Math.floor((millis / 60000))
const seconds = ((millis % 60000) / 1000)
if (minutes > 0) {
printMessage(`${name}'s last message was ${minutes} minutes and ${seconds} seconds ago.`)
} else {
printMessage(`${name}'s last message was ${seconds} seconds ago.`)
}
}
cache[name] = currTime
}
// engage
client.on('message', onMessageHandler)
client.connect().catch(() => printMessage(`Unable to connect to chat. Please confirm your oauth token is correct.`))