2020-07-29 21:11:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-09-29 19:51:15 +00:00
|
|
|
"fmt"
|
2021-01-31 23:12:50 +00:00
|
|
|
"io/fs"
|
2024-08-13 19:39:06 +00:00
|
|
|
"net/url"
|
2021-02-18 12:58:30 +00:00
|
|
|
"os"
|
2020-07-29 21:11:28 +00:00
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
2020-11-22 16:36:43 +00:00
|
|
|
"strings"
|
2024-08-01 19:17:05 +00:00
|
|
|
"time"
|
2020-08-16 12:36:54 +00:00
|
|
|
|
2024-08-26 14:43:28 +00:00
|
|
|
"github.com/hrfee/jfa-go/common"
|
2023-10-05 11:32:25 +00:00
|
|
|
"github.com/hrfee/jfa-go/easyproxy"
|
2024-08-01 19:17:05 +00:00
|
|
|
lm "github.com/hrfee/jfa-go/logmessages"
|
2020-08-16 12:36:54 +00:00
|
|
|
"gopkg.in/ini.v1"
|
2020-07-29 21:11:28 +00:00
|
|
|
)
|
|
|
|
|
2021-01-31 18:50:04 +00:00
|
|
|
var emailEnabled = false
|
2021-05-07 20:53:29 +00:00
|
|
|
var messagesEnabled = false
|
|
|
|
var telegramEnabled = false
|
2021-05-17 22:42:33 +00:00
|
|
|
var discordEnabled = false
|
2021-05-29 16:43:11 +00:00
|
|
|
var matrixEnabled = false
|
2021-01-31 18:50:04 +00:00
|
|
|
|
2021-01-31 23:12:50 +00:00
|
|
|
func (app *appContext) GetPath(sect, key string) (fs.FS, string) {
|
|
|
|
val := app.config.Section(sect).Key(key).MustString("")
|
|
|
|
if strings.HasPrefix(val, "jfa-go:") {
|
2021-02-02 15:44:30 +00:00
|
|
|
return localFS, strings.TrimPrefix(val, "jfa-go:")
|
2021-01-31 23:12:50 +00:00
|
|
|
}
|
2021-02-18 12:58:30 +00:00
|
|
|
dir, file := filepath.Split(val)
|
|
|
|
return os.DirFS(dir), file
|
2021-01-31 23:12:50 +00:00
|
|
|
}
|
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
func (app *appContext) MustSetValue(section, key, val string) {
|
|
|
|
app.config.Section(section).Key(key).SetValue(app.config.Section(section).Key(key).MustString(val))
|
|
|
|
}
|
|
|
|
|
2020-08-16 12:36:54 +00:00
|
|
|
func (app *appContext) loadConfig() error {
|
2020-07-29 21:11:28 +00:00
|
|
|
var err error
|
2024-08-20 19:19:32 +00:00
|
|
|
app.config, err = ini.ShadowLoad(app.configPath)
|
2020-07-29 21:11:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("jellyfin", "public_server", app.config.Section("jellyfin").Key("server").String())
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2021-12-20 20:44:08 +00:00
|
|
|
app.MustSetValue("ui", "redirect_url", app.config.Section("jellyfin").Key("public_server").String())
|
|
|
|
|
2020-08-16 12:36:54 +00:00
|
|
|
for _, key := range app.config.Section("files").Keys() {
|
2021-02-19 21:38:20 +00:00
|
|
|
if name := key.Name(); name != "html_templates" && name != "lang_files" {
|
2020-11-22 16:36:43 +00:00
|
|
|
key.SetValue(key.MustString(filepath.Join(app.dataPath, (key.Name() + ".json"))))
|
2020-10-23 13:39:04 +00:00
|
|
|
}
|
2020-07-29 21:11:28 +00:00
|
|
|
}
|
2023-06-20 20:43:25 +00:00
|
|
|
for _, key := range []string{"user_configuration", "user_displayprefs", "user_profiles", "ombi_template", "invites", "emails", "user_template", "custom_emails", "users", "telegram_users", "discord_users", "matrix_users", "announcements", "custom_user_page_content"} {
|
2020-11-22 16:36:43 +00:00
|
|
|
app.config.Section("files").Key(key).SetValue(app.config.Section("files").Key(key).MustString(filepath.Join(app.dataPath, (key + ".json"))))
|
2020-07-29 21:11:28 +00:00
|
|
|
}
|
2021-07-13 18:02:16 +00:00
|
|
|
for _, key := range []string{"matrix_sql"} {
|
|
|
|
app.config.Section("files").Key(key).SetValue(app.config.Section("files").Key(key).MustString(filepath.Join(app.dataPath, (key + ".db"))))
|
|
|
|
}
|
2024-08-12 17:53:46 +00:00
|
|
|
|
2020-11-22 16:36:43 +00:00
|
|
|
app.URLBase = strings.TrimSuffix(app.config.Section("ui").Key("url_base").MustString(""), "/")
|
2024-08-12 17:53:46 +00:00
|
|
|
if app.URLBase == "/invite" || app.URLBase == "/accounts" || app.URLBase == "/settings" || app.URLBase == "/activity" {
|
|
|
|
app.err.Printf(lm.BadURLBase, app.URLBase)
|
|
|
|
}
|
2024-08-13 19:39:06 +00:00
|
|
|
app.ExternalURI = strings.TrimSuffix(strings.TrimSuffix(app.config.Section("ui").Key("jfa_url").MustString(""), "/invite"), "/")
|
|
|
|
if !strings.HasSuffix(app.ExternalURI, app.URLBase) {
|
2024-08-12 17:53:46 +00:00
|
|
|
app.err.Println(lm.NoURLSuffix)
|
|
|
|
}
|
2024-08-13 19:39:06 +00:00
|
|
|
if app.ExternalURI == "" {
|
|
|
|
app.err.Println(lm.NoExternalHost + lm.LoginWontSave)
|
|
|
|
}
|
|
|
|
u, err := url.Parse(app.ExternalURI)
|
|
|
|
if err == nil {
|
|
|
|
app.ExternalDomain = u.Hostname()
|
|
|
|
}
|
2024-08-12 17:53:46 +00:00
|
|
|
|
2020-08-16 12:36:54 +00:00
|
|
|
app.config.Section("email").Key("no_username").SetValue(strconv.FormatBool(app.config.Section("email").Key("no_username").MustBool(false)))
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("password_resets", "email_html", "jfa-go:"+"email.html")
|
|
|
|
app.MustSetValue("password_resets", "email_text", "jfa-go:"+"email.txt")
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("invite_emails", "email_html", "jfa-go:"+"invite-email.html")
|
|
|
|
app.MustSetValue("invite_emails", "email_text", "jfa-go:"+"invite-email.txt")
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("email_confirmation", "email_html", "jfa-go:"+"confirmation.html")
|
|
|
|
app.MustSetValue("email_confirmation", "email_text", "jfa-go:"+"confirmation.txt")
|
2021-01-30 19:19:12 +00:00
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("notifications", "expiry_html", "jfa-go:"+"expired.html")
|
|
|
|
app.MustSetValue("notifications", "expiry_text", "jfa-go:"+"expired.txt")
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("notifications", "created_html", "jfa-go:"+"created.html")
|
|
|
|
app.MustSetValue("notifications", "created_text", "jfa-go:"+"created.txt")
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("deletion", "email_html", "jfa-go:"+"deleted.html")
|
|
|
|
app.MustSetValue("deletion", "email_text", "jfa-go:"+"deleted.txt")
|
2020-09-17 22:50:07 +00:00
|
|
|
|
2021-10-07 11:01:42 +00:00
|
|
|
app.MustSetValue("smtp", "hello_hostname", "localhost")
|
2021-11-09 20:18:54 +00:00
|
|
|
app.MustSetValue("smtp", "cert_validation", "true")
|
2023-10-14 12:28:12 +00:00
|
|
|
app.MustSetValue("smtp", "auth_type", "4")
|
2024-09-04 20:15:19 +00:00
|
|
|
app.MustSetValue("smtp", "port", "465")
|
2021-10-07 11:01:42 +00:00
|
|
|
|
2023-10-23 11:49:28 +00:00
|
|
|
app.MustSetValue("activity_log", "keep_n_records", "1000")
|
|
|
|
app.MustSetValue("activity_log", "delete_after_days", "90")
|
|
|
|
|
2022-01-26 20:00:40 +00:00
|
|
|
sc := app.config.Section("discord").Key("start_command").MustString("start")
|
|
|
|
app.config.Section("discord").Key("start_command").SetValue(strings.TrimPrefix(strings.TrimPrefix(sc, "/"), "!"))
|
|
|
|
|
2021-06-27 00:10:08 +00:00
|
|
|
jfUrl := app.config.Section("jellyfin").Key("server").String()
|
|
|
|
if !(strings.HasPrefix(jfUrl, "http://") || strings.HasPrefix(jfUrl, "https://")) {
|
|
|
|
app.config.Section("jellyfin").Key("server").SetValue("http://" + jfUrl)
|
|
|
|
}
|
|
|
|
|
2021-04-12 20:28:36 +00:00
|
|
|
// Deletion template is good enough for these as well.
|
|
|
|
app.MustSetValue("disable_enable", "disabled_html", "jfa-go:"+"deleted.html")
|
|
|
|
app.MustSetValue("disable_enable", "disabled_text", "jfa-go:"+"deleted.txt")
|
|
|
|
app.MustSetValue("disable_enable", "enabled_html", "jfa-go:"+"deleted.html")
|
|
|
|
app.MustSetValue("disable_enable", "enabled_text", "jfa-go:"+"deleted.txt")
|
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("welcome_email", "email_html", "jfa-go:"+"welcome.html")
|
|
|
|
app.MustSetValue("welcome_email", "email_text", "jfa-go:"+"welcome.txt")
|
2021-01-24 15:19:58 +00:00
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("template_email", "email_html", "jfa-go:"+"template.html")
|
|
|
|
app.MustSetValue("template_email", "email_text", "jfa-go:"+"template.txt")
|
2021-02-18 14:58:53 +00:00
|
|
|
|
2021-02-28 18:26:22 +00:00
|
|
|
app.MustSetValue("user_expiry", "behaviour", "disable_user")
|
|
|
|
app.MustSetValue("user_expiry", "email_html", "jfa-go:"+"user-expired.html")
|
|
|
|
app.MustSetValue("user_expiry", "email_text", "jfa-go:"+"user-expired.txt")
|
2021-02-28 15:41:06 +00:00
|
|
|
|
2024-07-28 15:02:47 +00:00
|
|
|
app.MustSetValue("user_expiry", "adjustment_email_html", "jfa-go:"+"expiry-adjusted.html")
|
|
|
|
app.MustSetValue("user_expiry", "adjustment_email_text", "jfa-go:"+"expiry-adjusted.txt")
|
|
|
|
|
2024-08-23 20:12:16 +00:00
|
|
|
app.MustSetValue("email", "collect", "true")
|
|
|
|
|
2021-05-30 10:47:41 +00:00
|
|
|
app.MustSetValue("matrix", "topic", "Jellyfin notifications")
|
2021-11-17 16:49:26 +00:00
|
|
|
app.MustSetValue("matrix", "show_on_reg", "true")
|
|
|
|
|
|
|
|
app.MustSetValue("discord", "show_on_reg", "true")
|
|
|
|
|
|
|
|
app.MustSetValue("telegram", "show_on_reg", "true")
|
2021-05-30 10:47:41 +00:00
|
|
|
|
2023-12-21 13:03:16 +00:00
|
|
|
app.MustSetValue("backups", "every_n_minutes", "1440")
|
|
|
|
app.MustSetValue("backups", "path", filepath.Join(app.dataPath, "backups"))
|
2023-12-21 16:47:17 +00:00
|
|
|
app.MustSetValue("backups", "keep_n_backups", "20")
|
2023-12-21 13:03:16 +00:00
|
|
|
|
2021-02-22 01:23:42 +00:00
|
|
|
app.config.Section("jellyfin").Key("version").SetValue(version)
|
2020-09-29 19:51:15 +00:00
|
|
|
app.config.Section("jellyfin").Key("device").SetValue("jfa-go")
|
2021-02-22 01:23:42 +00:00
|
|
|
app.config.Section("jellyfin").Key("device_id").SetValue(fmt.Sprintf("jfa-go-%s-%s", version, commit))
|
2021-07-27 15:48:24 +00:00
|
|
|
|
2023-12-23 20:54:55 +00:00
|
|
|
LOGIP = app.config.Section("advanced").Key("log_ips").MustBool(false)
|
2023-12-24 13:24:18 +00:00
|
|
|
LOGIPU = app.config.Section("advanced").Key("log_ips_users").MustBool(false)
|
2023-12-23 20:54:55 +00:00
|
|
|
|
2024-09-04 19:53:30 +00:00
|
|
|
app.MustSetValue("advanced", "auth_retry_count", "6")
|
|
|
|
app.MustSetValue("advanced", "auth_retry_gap", "10")
|
|
|
|
|
2024-09-04 20:15:19 +00:00
|
|
|
app.MustSetValue("ui", "port", "8056")
|
|
|
|
app.MustSetValue("advanced", "tls_port", "8057")
|
|
|
|
|
2023-12-20 18:18:39 +00:00
|
|
|
pwrMethods := []string{"allow_pwr_username", "allow_pwr_email", "allow_pwr_contact_method"}
|
|
|
|
allDisabled := true
|
|
|
|
for _, v := range pwrMethods {
|
|
|
|
if app.config.Section("user_page").Key(v).MustBool(true) {
|
|
|
|
allDisabled = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if allDisabled {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.info.Println(lm.EnableAllPWRMethods)
|
2023-12-20 18:18:39 +00:00
|
|
|
for _, v := range pwrMethods {
|
|
|
|
app.config.Section("user_page").Key(v).SetValue("true")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-07 20:53:29 +00:00
|
|
|
messagesEnabled = app.config.Section("messages").Key("enabled").MustBool(false)
|
|
|
|
telegramEnabled = app.config.Section("telegram").Key("enabled").MustBool(false)
|
2021-05-17 22:42:33 +00:00
|
|
|
discordEnabled = app.config.Section("discord").Key("enabled").MustBool(false)
|
2021-05-29 16:43:11 +00:00
|
|
|
matrixEnabled = app.config.Section("matrix").Key("enabled").MustBool(false)
|
2021-05-07 20:53:29 +00:00
|
|
|
if !messagesEnabled {
|
|
|
|
emailEnabled = false
|
|
|
|
telegramEnabled = false
|
2021-05-17 22:42:33 +00:00
|
|
|
discordEnabled = false
|
2021-05-29 16:43:11 +00:00
|
|
|
matrixEnabled = false
|
2021-05-07 20:53:29 +00:00
|
|
|
} else if app.config.Section("email").Key("method").MustString("") == "" {
|
2021-01-31 18:50:04 +00:00
|
|
|
emailEnabled = false
|
|
|
|
} else {
|
|
|
|
emailEnabled = true
|
|
|
|
}
|
2021-05-29 16:43:11 +00:00
|
|
|
if !emailEnabled && !telegramEnabled && !discordEnabled && !matrixEnabled {
|
2021-05-07 20:53:29 +00:00
|
|
|
messagesEnabled = false
|
|
|
|
}
|
2021-01-31 18:50:04 +00:00
|
|
|
|
2023-10-05 11:32:25 +00:00
|
|
|
if app.proxyEnabled = app.config.Section("advanced").Key("proxy").MustBool(false); app.proxyEnabled {
|
|
|
|
app.proxyConfig = easyproxy.ProxyConfig{}
|
|
|
|
app.proxyConfig.Protocol = easyproxy.HTTP
|
|
|
|
if strings.Contains(app.config.Section("advanced").Key("proxy_protocol").MustString("http"), "socks") {
|
|
|
|
app.proxyConfig.Protocol = easyproxy.SOCKS5
|
|
|
|
}
|
|
|
|
app.proxyConfig.Addr = app.config.Section("advanced").Key("proxy_address").MustString("")
|
|
|
|
app.proxyConfig.User = app.config.Section("advanced").Key("proxy_user").MustString("")
|
|
|
|
app.proxyConfig.Password = app.config.Section("advanced").Key("proxy_password").MustString("")
|
|
|
|
app.proxyTransport, err = easyproxy.NewTransport(app.proxyConfig)
|
|
|
|
if err != nil {
|
2024-08-01 19:17:05 +00:00
|
|
|
app.err.Printf(lm.FailedInitProxy, app.proxyConfig.Addr, err)
|
|
|
|
// As explained in lm.FailedInitProxy, sleep here might grab the admin's attention,
|
|
|
|
// Since we don't crash on this failing.
|
|
|
|
time.Sleep(15 * time.Second)
|
|
|
|
app.proxyEnabled = false
|
|
|
|
} else {
|
|
|
|
app.proxyEnabled = true
|
|
|
|
app.info.Printf(lm.InitProxy, app.proxyConfig.Addr)
|
2023-10-05 11:32:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-07 15:23:44 +00:00
|
|
|
app.MustSetValue("updates", "enabled", "true")
|
|
|
|
releaseChannel := app.config.Section("updates").Key("channel").String()
|
|
|
|
if app.config.Section("updates").Key("enabled").MustBool(false) {
|
|
|
|
v := version
|
|
|
|
if releaseChannel == "stable" {
|
|
|
|
if version == "git" {
|
|
|
|
v = "0.0.0"
|
|
|
|
}
|
|
|
|
} else if releaseChannel == "unstable" {
|
|
|
|
v = "git"
|
|
|
|
}
|
|
|
|
app.updater = newUpdater(baseURL, namespace, repo, v, commit, updater)
|
2023-10-05 11:32:25 +00:00
|
|
|
if app.proxyEnabled {
|
|
|
|
app.updater.SetTransport(app.proxyTransport)
|
|
|
|
}
|
2021-03-07 15:23:44 +00:00
|
|
|
}
|
|
|
|
if releaseChannel == "" {
|
|
|
|
if version == "git" {
|
|
|
|
releaseChannel = "unstable"
|
|
|
|
} else {
|
|
|
|
releaseChannel = "stable"
|
|
|
|
}
|
|
|
|
app.MustSetValue("updates", "channel", releaseChannel)
|
|
|
|
}
|
|
|
|
|
2021-01-10 15:51:04 +00:00
|
|
|
substituteStrings = app.config.Section("jellyfin").Key("substitute_jellyfin_strings").MustString("")
|
|
|
|
|
2021-12-20 20:17:18 +00:00
|
|
|
if substituteStrings != "" {
|
|
|
|
v := app.config.Section("ui").Key("success_message")
|
|
|
|
v.SetValue(strings.ReplaceAll(v.String(), "Jellyfin", substituteStrings))
|
|
|
|
}
|
|
|
|
|
2021-01-12 23:37:22 +00:00
|
|
|
oldFormLang := app.config.Section("ui").Key("language").MustString("")
|
|
|
|
if oldFormLang != "" {
|
2023-06-16 13:43:37 +00:00
|
|
|
app.storage.lang.chosenUserLang = oldFormLang
|
2021-01-12 23:37:22 +00:00
|
|
|
}
|
|
|
|
newFormLang := app.config.Section("ui").Key("language-form").MustString("")
|
|
|
|
if newFormLang != "" {
|
2023-06-16 13:43:37 +00:00
|
|
|
app.storage.lang.chosenUserLang = newFormLang
|
2021-01-12 23:37:22 +00:00
|
|
|
}
|
|
|
|
app.storage.lang.chosenAdminLang = app.config.Section("ui").Key("language-admin").MustString("en-us")
|
2021-01-14 17:51:12 +00:00
|
|
|
app.storage.lang.chosenEmailLang = app.config.Section("email").Key("language").MustString("en-us")
|
2021-03-30 21:41:28 +00:00
|
|
|
app.storage.lang.chosenPWRLang = app.config.Section("password_resets").Key("language").MustString("en-us")
|
2021-05-07 00:08:12 +00:00
|
|
|
app.storage.lang.chosenTelegramLang = app.config.Section("telegram").Key("language").MustString("en-us")
|
2021-01-14 17:51:12 +00:00
|
|
|
|
|
|
|
app.email = NewEmailer(app)
|
2021-01-11 19:17:43 +00:00
|
|
|
|
2020-07-29 21:11:28 +00:00
|
|
|
return nil
|
|
|
|
}
|
2024-08-26 14:43:28 +00:00
|
|
|
|
|
|
|
func (app *appContext) PatchConfigBase() {
|
|
|
|
conf := app.configBase
|
|
|
|
// Load language options
|
|
|
|
formOptions := app.storage.lang.User.getOptions()
|
|
|
|
pwrOptions := app.storage.lang.PasswordReset.getOptions()
|
|
|
|
adminOptions := app.storage.lang.Admin.getOptions()
|
|
|
|
emailOptions := app.storage.lang.Email.getOptions()
|
|
|
|
telegramOptions := app.storage.lang.Email.getOptions()
|
|
|
|
|
|
|
|
for i, section := range app.configBase.Sections {
|
|
|
|
if section.Section == "updates" && updater == "" {
|
|
|
|
section.Meta.Disabled = true
|
|
|
|
}
|
|
|
|
for j, setting := range section.Settings {
|
|
|
|
if section.Section == "ui" {
|
|
|
|
if setting.Setting == "language-form" {
|
|
|
|
setting.Options = formOptions
|
|
|
|
setting.Value = "en-us"
|
|
|
|
} else if setting.Setting == "language-admin" {
|
|
|
|
setting.Options = adminOptions
|
|
|
|
setting.Value = "en-us"
|
|
|
|
}
|
|
|
|
} else if section.Section == "password_resets" {
|
|
|
|
if setting.Setting == "language" {
|
|
|
|
setting.Options = pwrOptions
|
|
|
|
setting.Value = "en-us"
|
|
|
|
}
|
|
|
|
} else if section.Section == "email" {
|
|
|
|
if setting.Setting == "language" {
|
|
|
|
setting.Options = emailOptions
|
|
|
|
setting.Value = "en-us"
|
|
|
|
}
|
|
|
|
} else if section.Section == "telegram" {
|
|
|
|
if setting.Setting == "language" {
|
|
|
|
setting.Options = telegramOptions
|
|
|
|
setting.Value = "en-us"
|
|
|
|
}
|
|
|
|
} else if section.Section == "smtp" {
|
|
|
|
if setting.Setting == "ssl_cert" && PLATFORM == "windows" {
|
|
|
|
// Not accurate but the effect is hiding the option, which we want.
|
|
|
|
setting.Deprecated = true
|
|
|
|
}
|
|
|
|
} else if section.Section == "matrix" {
|
|
|
|
if setting.Setting == "encryption" && !MatrixE2EE() {
|
|
|
|
// Not accurate but the effect is hiding the option, which we want.
|
|
|
|
setting.Deprecated = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val := app.config.Section(section.Section).Key(setting.Setting)
|
|
|
|
switch setting.Type {
|
|
|
|
case "list":
|
|
|
|
setting.Value = val.StringsWithShadows("|")
|
|
|
|
case "text", "email", "select", "password", "note":
|
|
|
|
setting.Value = val.MustString("")
|
|
|
|
case "number":
|
|
|
|
setting.Value = val.MustInt(0)
|
|
|
|
case "bool":
|
|
|
|
setting.Value = val.MustBool(false)
|
|
|
|
}
|
|
|
|
section.Settings[j] = setting
|
|
|
|
}
|
|
|
|
conf.Sections[i] = section
|
|
|
|
}
|
|
|
|
app.patchedConfig = conf
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *appContext) PatchConfigDiscordRoles() {
|
|
|
|
if !discordEnabled {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r, err := app.discord.ListRoles()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
roles := make([]common.Option, len(r)+1)
|
|
|
|
roles[0] = common.Option{"", "None"}
|
|
|
|
for i, role := range r {
|
|
|
|
roles[i+1] = role
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, section := range app.patchedConfig.Sections {
|
|
|
|
if section.Section != "discord" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for j, setting := range section.Settings {
|
|
|
|
if setting.Setting != "apply_role" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
setting.Options = roles
|
|
|
|
section.Settings[j] = setting
|
|
|
|
}
|
|
|
|
app.patchedConfig.Sections[i] = section
|
|
|
|
}
|
|
|
|
}
|