93 lines
1.6 KiB
Go
93 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"github.com/BurntSushi/toml"
|
|
"github.com/sqweek/dialog"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
)
|
|
|
|
type Config struct {
|
|
Log string
|
|
Apikey string
|
|
WarcraftLogsApiKey string
|
|
}
|
|
|
|
var config Config
|
|
|
|
func getConfigPath() string {
|
|
if runtime.GOOS == "windows" {
|
|
return "config.toml"
|
|
}
|
|
|
|
xdg := os.Getenv("XDG_CONFIG_HOME")
|
|
if xdg == "" {
|
|
log.Fatal("$XDG_CONFIG_HOME not set")
|
|
}
|
|
|
|
os.MkdirAll(filepath.Join(xdg, "gambosite"), 0755)
|
|
return filepath.Join(xdg, "gambosite", "config.toml")
|
|
}
|
|
|
|
func setupConfig() {
|
|
cfgPath := getConfigPath()
|
|
|
|
if _, statErr := os.Stat(cfgPath); os.IsNotExist(statErr) {
|
|
chatlogPath, err := dialog.File().Title("Select your WoWChatLog.txt").Load()
|
|
if err != nil {
|
|
if errors.Is(err, dialog.ErrCancelled) {
|
|
log.Fatalf("Cancelled dialog box, exiting")
|
|
}
|
|
log.Fatal(err)
|
|
}
|
|
|
|
newConfig := &Config{
|
|
Log: chatlogPath,
|
|
Apikey: "12345",
|
|
}
|
|
|
|
file, err := os.Create(cfgPath)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer file.Close()
|
|
|
|
encoder := toml.NewEncoder(file)
|
|
if err := encoder.Encode(newConfig); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
_, err := toml.DecodeFile(cfgPath, &config)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
setupConfig()
|
|
|
|
fmt.Println("Select an option (1 or 2):")
|
|
fmt.Println("1) Upload a chat log for gambo tracking")
|
|
fmt.Println("2) Upload an RCLootCouncil export in csv format")
|
|
|
|
var choice int
|
|
_, err := fmt.Scanf("%d", &choice)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
switch choice {
|
|
case 1:
|
|
gambo()
|
|
case 2:
|
|
loot()
|
|
default:
|
|
log.Fatalf("%d is not a valid choice, retard\n", choice)
|
|
}
|
|
}
|