added new feeds module

This commit is contained in:
Andreas Neue 2024-07-05 11:58:57 +02:00
parent 519a6aeaf1
commit fa1fe08d7f
6 changed files with 67 additions and 6 deletions

View File

@ -8,10 +8,15 @@ vet:
fmt:
go list -f '{{.Dir}}' ./... | grep -v /vendor/ | xargs -L1 gofmt -l
test -z $$(go list -f '{{.Dir}}' ./... | grep -v /vendor/ | xargs -L1 gofmt -l)
#test -z $$(go list -f '{{.Dir}}' ./... | grep -v /vendor/ | xargs -L1 gofmt -l)
lint:
go list ./... | grep -v /vendor/ | xargs -L1 golint -set_exit_status
build:
go build -o bin/flokati ./cmd/flokati
go build -v -a -o bin/flokati ./cmd/flokati
docker:
docker build -t dr.dnix.de/flokati .
docker push dr.dnix.de/flokati

View File

@ -65,8 +65,9 @@ func Irc(say chan string) {
bot.Privmsg(tar, line[1])
time.Sleep(1 * time.Second)
}
}
time.Sleep(1 * time.Millisecond)
time.Sleep(1 * time.Millisecond)
}
}
func SetupHandlers(bot *irc.Conn, say chan string) {

View File

@ -39,7 +39,7 @@ func main() {
modules.BotName = strings.ToLower(*name)
switch *protocol {
case "irc":
Irc(say)
Irc(say)
case "matrix":
Matrix(say)
default:

2
go.mod
View File

@ -7,5 +7,5 @@ require (
git.dnix.de/an/go-pkg-xmlx v0.0.0-20151201012946-76f54ee73233
git.dnix.de/an/xlog v0.0.0-20160312133543-e7547652aef6
github.com/fluffle/goirc v1.1.1
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
)

2
go.sum
View File

@ -10,6 +10,8 @@ github.com/golang/mock v1.5.0 h1:jlYHihg//f7RRwuPfptm04yp4s7O6Kw8EZiVYIGcH0g=
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16 h1:ZtO5uywdd5dLDCud4r0r55eP4j9FuUNpl60Gmntcop4=
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U=
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=

53
modules/feeds.go Normal file
View File

@ -0,0 +1,53 @@
package modules
import (
"bufio"
"fmt"
"os"
"time"
"git.dnix.de/an/xlog"
"github.com/mmcdole/gofeed"
)
var feedsFeeds = flag.String("feeds_feeds", "feeds.txt", "Feed list file")
var feedsChannel = flag.String("feeds_channel", "", "Target channel")
func init() {
MsgFuncs["feeds"] = feedsHandleMessage
RunFuncs["feeds"] = feedsRun
}
func feedsRun() {
time.Sleep(1 * time.Minute)
file, err := os.Open(feedsFeeds)
if err != nil {
xlog.Fatal(err.Error())
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
go feedsPoll(scanner.Text())
}
if err := scanner.Err(); err != nil {
xlog.Fatal(err.Error())
}
}
func feedsHandleMessage(m *Message) {
}
func feedsPoll(url string) {
last := time.Now()
for {
fp := gofeed.NewParser()
feed, _ := fp.ParseURL(url)
for _, item := range feed.Items {
if item.UpdatedParsed.Unix() > last.Unix() {
SayCh <- fmt.Sprintf("%s\n[FEEDS] %s : %s - %s\n", *feedsChannel, feed.Title, item.Title, item.Link)
}
}
last = time.Now()
time.Sleep(15 * time.Minute)
}
}