add logChat exporter
This commit is contained in:
parent
57189b093a
commit
2f147f8f6d
2 changed files with 51 additions and 0 deletions
7
cmd/mc-logChat/README.md
Normal file
7
cmd/mc-logChat/README.md
Normal file
|
@ -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 <logfile>`
|
44
cmd/mc-logChat/main.go
Normal file
44
cmd/mc-logChat/main.go
Normal file
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue