112 lines
3.1 KiB
Go
112 lines
3.1 KiB
Go
/* SPDX-License-Identifier: GPL-2.0
|
|
*
|
|
* Copyright (C) 2021 Jason A. Donenfeld. All Rights Reserved.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"math/rand"
|
|
"net"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"path/filepath"
|
|
"syscall"
|
|
"time"
|
|
|
|
"golang.zx2c4.com/irc/hbot"
|
|
)
|
|
|
|
func main() {
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
shortlink := NewShortLink(filepath.Join(os.Getenv("STATE_DIRECTORY"), "links.txt"))
|
|
http.HandleFunc("/l/", shortlink.HandleRequest)
|
|
listener, err := net.FileListener(os.Stdin)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
go func() {
|
|
err = http.Serve(listener, nil)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}()
|
|
|
|
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/wireguard-nt/")
|
|
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/")
|
|
|
|
const channel = "#wireguard"
|
|
bot := hbot.NewBot(&hbot.Config{
|
|
Host: "irc.libera.chat:6697",
|
|
Nick: "WurGurBoo",
|
|
Realname: "Your Friendly Neighborhood WurGur Bot",
|
|
Channels: []string{channel},
|
|
Logger: hbot.Logger{Verbosef: log.Printf, Errorf: log.Printf},
|
|
Password: os.Getenv("WURGURBOO_PASSWORD"),
|
|
})
|
|
banter := NewBanter(channel, bot.Nick())
|
|
bot.AddTrigger(hbot.Trigger{
|
|
Condition: func(b *hbot.Bot, m *hbot.Message) bool { return m.Command == "PRIVMSG" },
|
|
Action: banter.Handle,
|
|
})
|
|
ntDriverBuilderNotifier := NewNtDriverBuilderNotifier(channel, bot)
|
|
http.HandleFunc("/nt-driver-builder-notify", ntDriverBuilderNotifier.HandleRequest)
|
|
|
|
c := make(chan os.Signal, 1)
|
|
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
|
go func() {
|
|
for range c {
|
|
bot.Close()
|
|
shortlink.SaveToDisk()
|
|
os.Exit(0)
|
|
}
|
|
}()
|
|
|
|
type seenCommit struct {
|
|
repo string
|
|
subject string
|
|
}
|
|
seenCommits := make(map[seenCommit]string, 4096)
|
|
|
|
go func() {
|
|
for commit := range feeds.Updates() {
|
|
<-bot.Joined()
|
|
sc := seenCommit{commit.RepoTitle, commit.Commit.Title}
|
|
if short, ok := seenCommits[sc]; ok {
|
|
log.Printf("Updated commit %s in %s", commit.Commit.ID, commit.RepoTitle)
|
|
shortlink.Set(short, commit.Commit.Link.Href, true)
|
|
continue
|
|
}
|
|
log.Printf("New commit %s in %s", commit.Commit.ID, commit.RepoTitle)
|
|
short := shortlink.New(commit.Commit.Link.Href)
|
|
seenCommits[sc] = short
|
|
bot.Action(channel, fmt.Sprintf("found a new commit in \x0303%s\x0f - \x0306%s\x0f - %s",
|
|
sc.repo, sc.subject,
|
|
fmt.Sprintf("https://w-g.pw/l/%s", short)),
|
|
)
|
|
}
|
|
}()
|
|
|
|
for {
|
|
bot.Run()
|
|
time.Sleep(time.Second * 5)
|
|
}
|
|
}
|