mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-08 08:10:08 +00:00
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package plugins
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/Luzifer/go_helpers/v2/fieldcollection"
|
|
)
|
|
|
|
// DefaultConfigName is the name the default configuration must have
|
|
// when defined
|
|
const DefaultConfigName = "default"
|
|
|
|
type (
|
|
// ModuleConfig represents a mapping of configurations per channel
|
|
// and module
|
|
ModuleConfig map[string]map[string]*fieldcollection.FieldCollection
|
|
)
|
|
|
|
// GetChannelConfig reads the channel specific configuration for the
|
|
// given module. This is created by taking an empty FieldCollection,
|
|
// merging in the default configuration and finally overwriting all
|
|
// existing channel configurations.
|
|
func (m ModuleConfig) GetChannelConfig(module, channel string) *fieldcollection.FieldCollection {
|
|
channel = strings.TrimLeft(channel, "#@")
|
|
composed := fieldcollection.NewFieldCollection()
|
|
|
|
for _, i := range []string{DefaultConfigName, channel} {
|
|
f := m[module][i]
|
|
if f == nil {
|
|
// That config does not exist, don't apply
|
|
continue
|
|
}
|
|
|
|
for k, v := range f.Data() {
|
|
// Overwrite all keys defined in this config
|
|
composed.Set(k, v)
|
|
}
|
|
}
|
|
|
|
return composed
|
|
}
|