Skip to content

Instantly share code, notes, and snippets.

@Shiro-Nek0
Last active March 24, 2024 04:18
Show Gist options
  • Save Shiro-Nek0/ba8bb5333db3a0bde5697c48e10939d8 to your computer and use it in GitHub Desktop.
Save Shiro-Nek0/ba8bb5333db3a0bde5697c48e10939d8 to your computer and use it in GitHub Desktop.
modify elichika config for docker image
package main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
)
var Json string
var err error
func init() {
file, err := os.ReadFile("../config.json")
Json = string(file)
if err != nil {
fmt.Println("Config file not found")
os.Exit(1)
return
}
fmt.Println("Config file found!")
}
func main() {
cdnServer := flag.String("cdn_server", getStringValue("cdn_server"), "Set the CDN asset server URL")
splitted := strings.Split(getStringValue("server_address"), ":")
serverAddress := flag.String("server_address", splitted[0], "Set the server address")
serverPort := flag.String("server_port", splitted[1], "Set the server port")
tapBondGain := flag.Int("tap_bond_gain", getIntValue("tap_bond_gain"), "Set the tap bond gain")
autoJudgeType := flag.Int("auto_judge_type", getIntValue("auto_judge_type"), "Set the auto judge type")
tutorial := flag.Bool("tutorial", getBoolValue("tutorial"), "Set if the tutorial is enabled")
loginBonusSecond := flag.Int("login_bonus_second", getIntValue("login_bonus_second"), "Set the login bonus second")
timezone := flag.String("timezone", getStringValue("timezone"), "Set the timezone")
defaultContentAmount := flag.Int("default_content_amount", getIntValue("default_content_amount"), "Set the default content amount")
useAuthenticationKeys := flag.Bool("use_authentication_keys", getBoolValue("use_authentication_keys"), "Set if the authentication keys are used")
missionMultiplier := flag.Int("mission_multiplier", getIntValue("mission_multiplier"), "Set the mission multiplier")
flag.Parse()
Json, _ = sjson.Set(Json, "cdn_server", *cdnServer)
Json, _ = sjson.Set(Json, "server_address", *serverAddress+":"+*serverPort)
Json, _ = sjson.Set(Json, "tap_bond_gain", *tapBondGain)
Json, _ = sjson.Set(Json, "auto_judge_type", *autoJudgeType)
Json, _ = sjson.Set(Json, "tutorial", *tutorial)
Json, _ = sjson.Set(Json, "login_bonus_second", *loginBonusSecond)
Json, _ = sjson.Set(Json, "timezone", *timezone)
Json, _ = sjson.Set(Json, "default_content_amount", *defaultContentAmount)
Json, _ = sjson.Set(Json, "use_authentication_keys", *useAuthenticationKeys)
Json, _ = sjson.Set(Json, "mission_multiplier", *missionMultiplier)
err = os.WriteFile("../config.json", []byte(Json), 0644)
if err != nil {
fmt.Println("Error writing to file")
return
}
fmt.Println("Config file updated!")
}
func getStringValue(key string) string {
return gjson.Get(Json, key).String()
}
func getBoolValue(key string) bool {
return gjson.Get(Json, key).Bool()
}
func getIntValue(key string) int {
return int(gjson.Get(Json, key).Int())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment