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] [twitch.announce]
#template = "SingsMic <%- stream.source %> <%- stream.city && stream.state ? `(${stream.city} ${stream.state})` : '' %> <%- stream.link %>" #template = "SingsMic <%- stream.source %> <%- stream.city && stream.state ? `(${stream.city} ${stream.state})` : '' %> <%- stream.link %>"
#interval = 60 #interval = 60
#delay = 30
[cert] [cert]
# SSL certificates (optional) # SSL certificates (optional)

View File

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

View File

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