birdbot/core/configuration.go

56 lines
2.0 KiB
Go
Raw Normal View History

package core
2022-10-27 03:55:23 +02:00
2023-03-31 22:21:49 +02:00
import "strings"
2023-03-31 22:49:50 +02:00
// Config is used to modify the behavior of birdbot externally
2022-10-27 03:55:23 +02:00
type Config struct {
2022-11-04 07:45:20 +01:00
Discord DiscordConfig `yaml:"discord"`
Mastodon MastodonConfig `yaml:"mastodon"`
2023-03-31 05:51:05 +02:00
Features Features `yaml:"features"`
2022-10-27 03:55:23 +02:00
}
2023-03-31 22:49:50 +02:00
// DiscordConfig contains discord specific configuration
2022-10-27 03:55:23 +02:00
type DiscordConfig struct {
Token string `yaml:"token" env:"DISCORD_TOKEN"`
GuildID string `yaml:"guild_id" env:"DISCORD_GUILD_ID"`
2022-10-27 04:34:13 +02:00
EventCategory string `yaml:"event_category" env:"DISCORD_EVENT_CATEGORY"`
ArchiveCategory string `yaml:"archive_category" env:"DISCORD_ARCHIVE_CATEGORY"`
2022-10-27 04:35:32 +02:00
NotificationChannel string `yaml:"notification_channel" env:"DISCORD_NOTIFICATION_CHANNEL"`
2022-10-27 03:55:23 +02:00
}
2022-11-04 07:45:20 +01:00
2023-03-31 22:49:50 +02:00
// MastodonConfig contains mastodon specific configuration
2022-11-04 07:45:20 +01:00
type MastodonConfig struct {
Server string `yaml:"server" env:"MASTODON_SERVER"`
Username string `yaml:"user" env:"MASTODON_USER"`
Password string `yaml:"password" env:"MASTODON_PASSWORD"`
ClientID string `yaml:"client_id" env:"MASTODON_CLIENT_ID"`
ClientSecret string `yaml:"client_secret" env:"MASTODON_CLIENT_SECRET"`
}
2023-03-31 05:51:05 +02:00
2023-03-31 22:49:50 +02:00
// Features contains all features flags that can be used to modify functionality
2023-03-31 05:51:05 +02:00
type Features struct {
2023-03-31 22:21:49 +02:00
ManageEventChannels Feature `yaml:"manage_event_channels" env:"BIRD_EVENT_CHANNELS"`
AnnounceEvents Feature `yaml:"announce_events" env:"BIRD_ANNOUNCE_EVENTS"`
ReccurringEvents Feature `yaml:"recurring_events" env:"BIRD_RECURRING_EVENTS"`
LoadGamePlugins Feature `yaml:"load_game_plugins" env:"BIRD_LOAD_GAME_PLUGINS"`
}
2023-03-31 22:49:50 +02:00
// Feature is a boolean string used to toggle functionality
2023-03-31 22:21:49 +02:00
type Feature string
2023-03-31 22:49:50 +02:00
// IsEnabled returns true when a feature is set to be true
2023-03-31 22:21:49 +02:00
func (value Feature) IsEnabled() bool {
return strings.ToLower(string(value)) == "true"
}
2023-03-31 22:49:50 +02:00
// IsEnabled returns true when a feature is set to be true
// or if the feature flag is not set at all
2023-03-31 22:21:49 +02:00
func (value Feature) IsEnabledByDefault() bool {
v := strings.ToLower(string(value))
if v == "" {
v = "true"
}
return Feature(v).IsEnabled()
2023-03-31 05:51:05 +02:00
}