102 lines
3.0 KiB
Go
102 lines
3.0 KiB
Go
/* SPDX-License-Identifier: GPL-2.0
|
|
*
|
|
* Copyright (C) 2021 Jason A. Donenfeld. All Rights Reserved.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"net"
|
|
"os"
|
|
"regexp"
|
|
"time"
|
|
|
|
"golang.zx2c4.com/irc/hbot"
|
|
)
|
|
|
|
func main() {
|
|
channelArg := flag.String("channel", "", "channel to join")
|
|
serverArg := flag.String("server", "", "server and port")
|
|
nickArg := flag.String("nick", "", "nickname")
|
|
passwordArg := flag.String("password-file", "", "optional file with password")
|
|
flag.Parse()
|
|
if matched, _ := regexp.MatchString(`^#[a-zA-Z0-9_-]+$`, *channelArg); !matched {
|
|
fmt.Fprintln(os.Stderr, "Invalid channel")
|
|
flag.Usage()
|
|
os.Exit(1)
|
|
}
|
|
if _, _, err := net.SplitHostPort(*serverArg); err != nil {
|
|
fmt.Fprintln(os.Stderr, "Invalid server")
|
|
flag.Usage()
|
|
os.Exit(1)
|
|
}
|
|
if matched, _ := regexp.MatchString(`^[a-zA-Z0-9\[\]_-]{1,16}$`, *nickArg); !matched {
|
|
fmt.Fprintln(os.Stderr, "Invalid nick")
|
|
flag.Usage()
|
|
os.Exit(1)
|
|
}
|
|
password := ""
|
|
if len(*passwordArg) > 0 {
|
|
f, err := os.Open(*passwordArg)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Unable to open password file: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
password, err = bufio.NewReader(f).ReadString('\n')
|
|
f.Close()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Unable to read password file: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
if len(password) > 0 && password[len(password)-1] == '\n' {
|
|
password = password[:len(password)-1]
|
|
}
|
|
}
|
|
|
|
feeds := NewCgitFeedMonitorer(time.Second * 10)
|
|
feeds.AddFeed("https://git.zx2c4.com/wireguard-linux/")
|
|
feeds.AddFeed("https://git.zx2c4.com/wireguard-tools/")
|
|
feeds.AddFeed("https://git.zx2c4.com/wireguard-linux-compat/")
|
|
feeds.AddFeed("https://git.zx2c4.com/wireguard-windows/")
|
|
feeds.AddFeed("https://git.zx2c4.com/wireguard-go/")
|
|
feeds.AddFeed("https://git.zx2c4.com/wireguard-freebsd/")
|
|
feeds.AddFeed("https://git.zx2c4.com/wireguard-openbsd/")
|
|
feeds.AddFeed("https://git.zx2c4.com/wireguard-android/")
|
|
feeds.AddFeed("https://git.zx2c4.com/android-wireguard-module-builder/")
|
|
feeds.AddFeed("https://git.zx2c4.com/wireguard-apple/")
|
|
feeds.AddFeed("https://git.zx2c4.com/wireguard-rs/")
|
|
feeds.AddFeed("https://git.zx2c4.com/wintun/")
|
|
feeds.AddFeed("https://git.zx2c4.com/wg-dynamic/")
|
|
|
|
bot := hbot.NewBot(&hbot.Config{
|
|
Host: *serverArg,
|
|
Nick: *nickArg,
|
|
Realname: "Your Friendly Neighborhood WurGur Bot",
|
|
Channels: []string{*channelArg},
|
|
Logger: hbot.Logger{Verbosef: log.Printf, Errorf: log.Printf},
|
|
Password: password,
|
|
})
|
|
|
|
urlShortener := regexp.MustCompile(`(.*\?id=[a-f0-9]{8})([a-f0-9]+)$`)
|
|
go func() {
|
|
for commit := range feeds.Updates() {
|
|
<-bot.Joined()
|
|
log.Printf("New commit %s in %s", commit.Commit.ID, commit.RepoTitle)
|
|
url := commit.Commit.Link.Href
|
|
if matches := urlShortener.FindStringSubmatch(url); len(matches) == 3 {
|
|
url = matches[1]
|
|
}
|
|
bot.Msg(*channelArg, fmt.Sprintf("\x01ACTION found a new commit in \x0303%s\x0f - \x0306%s\x0f - %s\x01", commit.RepoTitle, commit.Commit.Title, url))
|
|
}
|
|
}()
|
|
|
|
for {
|
|
bot.Run()
|
|
time.Sleep(time.Second * 5)
|
|
}
|
|
}
|