mirror of
https://git.sr.ht/~ashkeel/strimertul
synced 2024-09-18 01:50:50 +00:00
Tentative fix for mutex killing strimertul
This commit is contained in:
parent
8ba3c3fbc0
commit
f3f85622bd
2 changed files with 62 additions and 57 deletions
|
@ -117,7 +117,8 @@ func Register(manager *modules.Manager) error {
|
|||
}
|
||||
|
||||
func (m *Manager) Status() modules.ModuleStatus {
|
||||
if !m.config.Enabled {
|
||||
config := m.Config()
|
||||
if !config.Enabled {
|
||||
return modules.ModuleStatus{
|
||||
Enabled: false,
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ import (
|
|||
)
|
||||
|
||||
func (b *Bot) SetupLoyalty(loyalty *loyalty.Manager) {
|
||||
config := loyalty.Config()
|
||||
b.Loyalty = loyalty
|
||||
config := loyalty.Config()
|
||||
b.SetBanList(config.BanList)
|
||||
|
||||
// Add loyalty-based commands
|
||||
|
@ -55,13 +55,14 @@ func (b *Bot) SetupLoyalty(loyalty *loyalty.Manager) {
|
|||
var statusMux sync.Mutex
|
||||
streamOnline := true
|
||||
go func() {
|
||||
defer statusMux.Unlock()
|
||||
for {
|
||||
// Wait for next poll
|
||||
time.Sleep(60 * time.Second)
|
||||
|
||||
// Check if streamer is online, if possible
|
||||
func() {
|
||||
statusMux.Lock()
|
||||
defer statusMux.Unlock()
|
||||
streamOnline = true
|
||||
status, err := b.api.API.GetStreams(&helix.StreamsParams{
|
||||
UserLogins: []string{b.config.Channel},
|
||||
|
@ -71,17 +72,20 @@ func (b *Bot) SetupLoyalty(loyalty *loyalty.Manager) {
|
|||
} else {
|
||||
streamOnline = len(status.Data.Streams) > 0
|
||||
}
|
||||
statusMux.Unlock()
|
||||
|
||||
err = b.api.db.PutJSON(StreamInfoKey, status.Data.Streams)
|
||||
if err != nil {
|
||||
b.logger.Warn("Error saving stream info", zap.Error(err))
|
||||
}
|
||||
}()
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
defer statusMux.Unlock()
|
||||
for {
|
||||
status := loyalty.Status()
|
||||
if status.Enabled {
|
||||
config := loyalty.Config()
|
||||
if config.Points.Interval > 0 {
|
||||
// Wait for next poll
|
||||
time.Sleep(time.Duration(config.Points.Interval) * time.Second)
|
||||
|
||||
|
@ -93,7 +97,6 @@ func (b *Bot) SetupLoyalty(loyalty *loyalty.Manager) {
|
|||
continue
|
||||
}
|
||||
|
||||
if config.Points.Interval > 0 {
|
||||
b.logger.Debug("awarding points")
|
||||
|
||||
// Get user list
|
||||
|
@ -132,6 +135,7 @@ func (b *Bot) SetupLoyalty(loyalty *loyalty.Manager) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue