diff --git a/Makefile b/Makefile index 521886f..aa5a037 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ install: all echo "Installing binaries..." install -Dm 755 justgrep "${DESTDIR}/usr/bin/justgrep" install -Dm 755 irc2json "${DESTDIR}/usr/bin/irc2json" + install -Dm 755 irc2text "${DESTDIR}/usr/bin/irc2text" echo "Installing man pages..." install -Dm 644 man1/justgrep.1 "${DESTDIR}/usr/share/man/man1/justgrep.1" install -Dm 644 man1/irc2json.1 "${DESTDIR}/usr/share/man/man1/irc2json.1" diff --git a/cmd/irc2text/irc2text.go b/cmd/irc2text/irc2text.go new file mode 100644 index 0000000..989ad9b --- /dev/null +++ b/cmd/irc2text/irc2text.go @@ -0,0 +1,33 @@ +package main + +import ( + "bufio" + "fmt" + "os" + + "github.com/Mm2PL/justgrep" +) + +func main() { + scanner := bufio.NewScanner(os.Stdin) + + for scanner.Scan() { + msg, err := justgrep.NewMessage(scanner.Text()) + if err != nil { + _, _ = fmt.Fprintf(os.Stderr, "Failed to irc parse message: %s\n", err) + os.Exit(1) + } + if msg.Action == "PRIVMSG" { + fmt.Printf("[%s] %s %s: %s\n", msg.Timestamp.UTC().Format("2006-01-02 15:04:05"), msg.Args[0], msg.User, msg.Args[1]) + } else if msg.Action == "NOTICE" { + fmt.Printf("NOTICE %s %s\n", msg.Args[0], msg.Args[1]) + } else if msg.Action == "CLEARCHAT" { + duration := msg.Tags["ban-duration"] + if duration == "" { + fmt.Printf("%s was permanently banned\n", msg.Args[1]) + } else { + fmt.Printf("%s was timed out for %s seconds\n", msg.Args[1], msg.Tags["ban-duration"]) + } + } + } +}