basic
This commit is contained in:
parent
544f40fa63
commit
bdbc19f78c
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
WoWChatLog.txt
|
||||
.idea
|
||||
.idea
|
||||
config.toml
|
6
go.mod
6
go.mod
@ -1,3 +1,9 @@
|
||||
module gamboupload
|
||||
|
||||
go 1.24
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.4.0 // indirect
|
||||
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf // indirect
|
||||
github.com/sqweek/dialog v0.0.0-20240226140203-065105509627 // indirect
|
||||
)
|
||||
|
6
go.sum
Normal file
6
go.sum
Normal file
@ -0,0 +1,6 @@
|
||||
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
|
||||
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf h1:FPsprx82rdrX2jiKyS17BH6IrTmUBYqZa/CXT4uvb+I=
|
||||
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf/go.mod h1:peYoMncQljjNS6tZwI9WVyQB3qZS6u79/N3mBOcnd3I=
|
||||
github.com/sqweek/dialog v0.0.0-20240226140203-065105509627 h1:2JL2wmHXWIAxDofCK+AdkFi1KEg3dgkefCsm7isADzQ=
|
||||
github.com/sqweek/dialog v0.0.0-20240226140203-065105509627/go.mod h1:/qNPSY91qTz/8TgHEMioAUc6q7+3SOybeKczHMXFcXw=
|
70
main.go
70
main.go
@ -3,14 +3,52 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/sqweek/dialog"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Log string
|
||||
Apikey string
|
||||
}
|
||||
|
||||
var config Config
|
||||
|
||||
func main() {
|
||||
b, err := os.ReadFile("WoWChatLog.txt")
|
||||
if _, statErr := os.Stat("config.toml"); os.IsNotExist(statErr) {
|
||||
path, err := dialog.File().Title("Select your WoWChatLog.txt").Load()
|
||||
if err != nil {
|
||||
if errors.Is(err, dialog.ErrCancelled) {
|
||||
log.Fatalf("Cancelled dialog box, exiting")
|
||||
}
|
||||
}
|
||||
|
||||
newConfig := &Config{
|
||||
Log: path,
|
||||
Apikey: "12345",
|
||||
}
|
||||
|
||||
file, err := os.Create("config.toml")
|
||||
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("config.toml", &config)
|
||||
|
||||
b, err := os.ReadFile(config.Log)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -26,10 +64,36 @@ func main() {
|
||||
}
|
||||
|
||||
for _, game := range games {
|
||||
j, err := json.Marshal(game)
|
||||
err = upload(game, "https://forcek.in/game")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(string(j))
|
||||
}
|
||||
}
|
||||
|
||||
func upload(game Game, endpoint string) error {
|
||||
marshalled, err := json.Marshal(game)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(marshalled))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("X-API-KEY", config.Apikey)
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(resp.Status)
|
||||
return nil
|
||||
}
|
||||
|
||||
func uploadTest(game Game) error {
|
||||
return upload(game, "http://localhost:3000/game")
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ type Game struct {
|
||||
HighRoll int `json:"high_roll"`
|
||||
LowRoll int `json:"low_roll"`
|
||||
Payout int `json:"payout"`
|
||||
Players []string `json:"players"`
|
||||
}
|
||||
|
||||
var (
|
||||
@ -139,5 +140,10 @@ func parse(lines []string, i int) (Game, int, error) {
|
||||
g.Loser = endMatches[1]
|
||||
g.LowRoll = rolls[g.Loser]
|
||||
|
||||
g.Players = make([]string, 0)
|
||||
for pl, _ := range rolls {
|
||||
g.Players = append(g.Players, pl)
|
||||
}
|
||||
|
||||
return g, i, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user