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

@@ -46,6 +46,7 @@ json-url = ["https://woke.net/api/streams.json"]
[twitch.announce]
#template = "SingsMic <%- stream.source %> <%- stream.city && stream.state ? `(${stream.city} ${stream.state})` : '' %> <%- stream.link %>"
#interval = 60
#delay = 30
[cert]
# SSL certificates (optional)

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() {

View File

@@ -110,6 +110,11 @@ function parseArgs() {
number: true,
default: 60,
})
.option('twitch.announce.delay', {
describe: 'Time to dwell on a stream before its details are announced',
number: true,
default: 30,
})
.group(
[
'control.username',