Add configurable dwell delay to Twitch bot

This commit is contained in:
Max Goodhart
2020-07-02 21:41:04 -07:00
parent e71d54b1b0
commit ca038a2cf6
3 changed files with 15 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ export default class TwitchBot extends EventEmitter {
this.streams = null
this.listeningURL = null
this.dwellTimeout = null
this.announceTimeouts = new Map()
client.on('ready', () => {
@@ -70,10 +71,14 @@ export default class TwitchBot extends EventEmitter {
this.onListeningURLChange(listeningURL)
}
async onListeningURLChange(listeningURL) {
if (!this.announceTimeouts.has(listeningURL)) {
await this.announce()
}
onListeningURLChange(listeningURL) {
const { announce } = this.config
clearTimeout(this.dwellTimeout)
this.dwellTimeout = setTimeout(() => {
if (!this.announceTimeouts.has(listeningURL)) {
this.announce()
}
}, announce.delay * 1000)
}
async announce() {