From 2f147f8f6d7e2714a9aaba15569034656c109ccd Mon Sep 17 00:00:00 2001 From: Merith-TK Date: Sun, 19 Mar 2023 14:51:18 -0700 Subject: [PATCH] add logChat exporter --- cmd/mc-logChat/README.md | 7 +++++++ cmd/mc-logChat/main.go | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 cmd/mc-logChat/README.md create mode 100644 cmd/mc-logChat/main.go diff --git a/cmd/mc-logChat/README.md b/cmd/mc-logChat/README.md new file mode 100644 index 0000000..0a3e4e3 --- /dev/null +++ b/cmd/mc-logChat/README.md @@ -0,0 +1,7 @@ +# MC LOGChat + +This tool extracts all chat messages from a minecraft logfile, and exports it to chat.txt + +## Usage +- `go install git.merith.xyz/packages/utils/cmd/mc-logChat` +- `mc-logChat ` \ No newline at end of file diff --git a/cmd/mc-logChat/main.go b/cmd/mc-logChat/main.go new file mode 100644 index 0000000..e52dbbf --- /dev/null +++ b/cmd/mc-logChat/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "fmt" + "io/ioutil" + "os" + "strings" +) + +func main() { + // check if there is an argument + if len(os.Args) < 2 { + fmt.Println("Error: No file specified") + os.Exit(1) + } + arg := os.Args[1] + + file, err := ioutil.ReadFile(arg) + if err != nil { + fmt.Println("Error: ", err) + os.Exit(1) + } + + // convert file to string + str := string(file) + // split string into slice of strings by new line + lines := strings.Split(str, "\n") + + chat := []string{} + // loop through slice of strings + for _, line := range lines { + if strings.Contains(line, "[CHAT]") { + chat = append(chat, line) + } + } + + // write chat to file + err = ioutil.WriteFile("chat.txt", []byte(strings.Join(chat, "\n")), 0644) + if err != nil { + fmt.Println("Error: ", err) + os.Exit(1) + } + +}