Skip to content

Commit

Permalink
Add irc2text
Browse files Browse the repository at this point in the history
  • Loading branch information
Mm2PL committed Aug 23, 2023
1 parent 78fe320 commit 594f609
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
33 changes: 33 additions & 0 deletions cmd/irc2text/irc2text.go
Original file line number Diff line number Diff line change
@@ -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"])
}
}
}
}

0 comments on commit 594f609

Please sign in to comment.