2019-05-10 08:21:59 +00:00
|
|
|
package settings
|
|
|
|
|
2019-05-10 08:53:58 +00:00
|
|
|
import (
|
2020-01-11 19:38:51 +00:00
|
|
|
"encoding/json"
|
2019-05-10 08:53:58 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
2019-10-20 15:22:52 +00:00
|
|
|
"time"
|
2019-05-10 08:53:58 +00:00
|
|
|
)
|
|
|
|
|
2019-05-10 08:21:59 +00:00
|
|
|
const (
|
2020-03-18 19:33:33 +00:00
|
|
|
version = "5.1.0"
|
2019-06-23 13:12:35 +00:00
|
|
|
twitchUser = "galchedbot"
|
|
|
|
twitchIRCRoom = "galched"
|
2019-05-10 12:55:43 +00:00
|
|
|
discordTokenPath = "./tokens/.discordtoken"
|
2019-06-23 13:12:35 +00:00
|
|
|
twitchTokenPath = "./tokens/.twitchtoken"
|
2019-05-10 12:55:43 +00:00
|
|
|
subdayDataPath = "./backups/subday"
|
2020-03-18 19:33:33 +00:00
|
|
|
petDataPath = "./backups/pets"
|
2020-01-11 19:38:51 +00:00
|
|
|
youtubeTokenPath = "./tokens/.youtubetoken"
|
|
|
|
webLoginsPath = "./tokens/.weblogins"
|
2019-05-10 12:16:35 +00:00
|
|
|
|
|
|
|
// Permitted roles in discord for subday
|
|
|
|
subRole1 = "433672344737677322"
|
|
|
|
subRole2 = "433680494635515904"
|
|
|
|
galchedRole = "301467455497175041"
|
|
|
|
smorcRole = "301470784491356172"
|
2020-01-11 19:38:51 +00:00
|
|
|
|
|
|
|
defaultQueueAddr = ":8888"
|
2019-05-10 08:21:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
2019-10-20 15:22:52 +00:00
|
|
|
SongInfo struct {
|
|
|
|
Path string
|
|
|
|
Signature string
|
|
|
|
Description string
|
|
|
|
Permissions []string
|
|
|
|
Timeout time.Duration
|
|
|
|
}
|
|
|
|
|
2019-05-10 08:21:59 +00:00
|
|
|
Settings struct {
|
2019-07-28 20:10:24 +00:00
|
|
|
Version string
|
|
|
|
DiscordToken string
|
|
|
|
TwitchUser string
|
|
|
|
TwitchIRCRoom string
|
|
|
|
TwitchToken string
|
2020-01-11 19:38:51 +00:00
|
|
|
YoutubeToken string
|
2019-07-28 20:10:24 +00:00
|
|
|
SubdayDataPath string
|
2020-03-18 19:33:33 +00:00
|
|
|
PetDataPath string
|
2019-07-28 20:10:24 +00:00
|
|
|
PermittedRoles []string
|
|
|
|
DiscordVoiceChannel string
|
2019-10-20 15:22:52 +00:00
|
|
|
Songs []SongInfo
|
2020-01-11 19:38:51 +00:00
|
|
|
|
|
|
|
QueueAddress string
|
|
|
|
LoginUsers map[string]string
|
2019-05-10 08:21:59 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2019-05-10 08:53:58 +00:00
|
|
|
func New() (*Settings, error) {
|
|
|
|
discordToken, err := ioutil.ReadFile(discordTokenPath)
|
|
|
|
if err != nil {
|
2019-05-10 12:16:35 +00:00
|
|
|
log.Print("settings: cannot read discord token file", err)
|
2019-05-10 08:21:59 +00:00
|
|
|
}
|
2019-06-23 13:12:35 +00:00
|
|
|
twitchToken, err := ioutil.ReadFile(twitchTokenPath)
|
|
|
|
if err != nil {
|
|
|
|
log.Print("settings: cannot read twitch token file", err)
|
|
|
|
}
|
2020-01-11 19:38:51 +00:00
|
|
|
youtubetoken, err := ioutil.ReadFile(youtubeTokenPath)
|
|
|
|
if err != nil {
|
|
|
|
log.Print("settings: cannot read twitch token file", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
webLogins := make(map[string]string)
|
|
|
|
webLoginsRaw, err := ioutil.ReadFile(webLoginsPath)
|
|
|
|
if err != nil {
|
|
|
|
log.Print("settings: cannot read web login file", err)
|
|
|
|
} else {
|
|
|
|
err = json.Unmarshal(webLoginsRaw, &webLogins)
|
|
|
|
if err != nil {
|
|
|
|
log.Print("settings: cannot parse web login file", err)
|
|
|
|
}
|
|
|
|
}
|
2019-05-10 08:53:58 +00:00
|
|
|
|
|
|
|
return &Settings{
|
2019-07-28 20:10:24 +00:00
|
|
|
Version: version,
|
|
|
|
DiscordToken: string(discordToken),
|
|
|
|
TwitchToken: string(twitchToken),
|
2020-01-11 19:38:51 +00:00
|
|
|
YoutubeToken: string(youtubetoken),
|
2019-07-28 20:10:24 +00:00
|
|
|
TwitchUser: twitchUser,
|
|
|
|
TwitchIRCRoom: twitchIRCRoom,
|
|
|
|
SubdayDataPath: subdayDataPath,
|
2020-03-18 19:33:33 +00:00
|
|
|
PetDataPath: petDataPath,
|
2019-07-28 20:10:24 +00:00
|
|
|
DiscordVoiceChannel: "301793085522706432",
|
|
|
|
PermittedRoles: []string{subRole1, subRole2, galchedRole, smorcRole},
|
2019-10-20 15:22:52 +00:00
|
|
|
Songs: []SongInfo{
|
|
|
|
{
|
|
|
|
Path: "songs/polka.dca",
|
|
|
|
Signature: "!song",
|
2020-01-11 19:38:51 +00:00
|
|
|
Description: "сыграть гимн галчед (только для избранных)",
|
2019-10-20 15:22:52 +00:00
|
|
|
Permissions: []string{"AlexV", "Rummy_Quamox", "Lidiya_owl"},
|
|
|
|
Timeout: 10 * time.Second,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Path: "songs/whisper.dca",
|
|
|
|
Signature: "!sax",
|
|
|
|
Description: "kreygasm",
|
|
|
|
Timeout: 20 * time.Second,
|
|
|
|
},
|
2020-01-11 19:38:51 +00:00
|
|
|
{
|
|
|
|
Path: "songs/st.dca",
|
|
|
|
Signature: "!chiki",
|
|
|
|
Description: "briki v damki",
|
|
|
|
Timeout: 20 * time.Second,
|
|
|
|
},
|
2019-10-20 15:22:52 +00:00
|
|
|
},
|
2020-01-11 19:38:51 +00:00
|
|
|
QueueAddress: defaultQueueAddr,
|
|
|
|
LoginUsers: webLogins,
|
2019-05-10 08:53:58 +00:00
|
|
|
}, nil
|
2019-05-10 08:21:59 +00:00
|
|
|
}
|