Переворошил файлы (опять), закинул всё в докер

This commit is contained in:
B4D_US3R 2025-04-21 23:13:46 +05:00
parent be76c08756
commit c853cfb592
11 changed files with 135 additions and 54 deletions

16
Dockerfile Normal file
View file

@ -0,0 +1,16 @@
FROM golang:1.24
WORKDIR /app/kiki
RUN mkdir /app/kiki/config /app/kiki/service /app/kiki/stacker /app/kiki/tooter
COPY config/* /app/kiki/config
COPY service/* /app/kiki/service
COPY stacker/* /app/kiki/stacker
COPY tooter/* /app/kiki/tooter
RUN cd service && go mod tidy && cd ../
RUN go build -C ./service -o ../kiki
CMD [ "/app/kiki/kiki", "run" ]

14
config/go.mod Normal file
View file

@ -0,0 +1,14 @@
module kiki/config
go 1.24.2
require (
github.com/mattn/go-mastodon v0.0.9
gopkg.in/yaml.v2 v2.4.0
)
require (
github.com/gorilla/websocket v1.5.1 // indirect
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 // indirect
golang.org/x/net v0.25.0 // indirect
)

11
docker-compose.yml Normal file
View file

@ -0,0 +1,11 @@
services:
kiki:
build: ./
restart: always
volumes:
- ./config.yaml:/app/kiki/config.yaml
- ./secret.conf:/app/kiki/secret.conf
redis:
image: redis
restart: always

29
go.mod
View file

@ -1,29 +0,0 @@
module kiki
go 1.23.0
toolchain go1.24.2
require (
github.com/mattn/go-mastodon v0.0.9
github.com/mmcdole/gofeed v1.3.0
github.com/redis/go-redis/v9 v9.7.3
github.com/urfave/cli/v3 v3.1.1
golang.org/x/net v0.39.0
gopkg.in/yaml.v2 v2.4.0
)
require (
github.com/PuerkitoBio/goquery v1.10.2 // indirect
github.com/andybalholm/cascadia v1.3.3 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mmcdole/goxpp v1.1.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 // indirect
golang.org/x/text v0.24.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)

35
service/go.mod Normal file
View file

@ -0,0 +1,35 @@
module kiki/kiki
go 1.24.2
replace kiki/config => ../config
replace kiki/stacker => ../stacker
replace kiki/tooter => ../tooter
require (
github.com/mattn/go-mastodon v0.0.9
github.com/urfave/cli/v3 v3.2.0
kiki/config v0.0.0-00010101000000-000000000000
kiki/stacker v0.0.0-00010101000000-000000000000
kiki/tooter v0.0.0-00010101000000-000000000000
)
require (
github.com/PuerkitoBio/goquery v1.8.0 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mmcdole/gofeed v1.3.0 // indirect
github.com/mmcdole/goxpp v1.1.1-0.20240225020742-a0c311522b23 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/redis/go-redis/v9 v9.7.3 // indirect
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 // indirect
golang.org/x/net v0.39.0 // indirect
golang.org/x/text v0.24.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

View file

@ -8,9 +8,9 @@ import (
"path/filepath"
"time"
"kiki/src/config"
"kiki/src/stacker"
"kiki/src/tooter"
"kiki/config"
"kiki/stacker"
"kiki/tooter"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli/v3"
@ -56,6 +56,7 @@ func main() {
kikiConfig := config.GetKikiConfig(confFile)
rdb := stacker.ConnectToRedis(kikiConfig.Redis.Address)
defer stacker.SaveRedis(rdb)
ticker := time.NewTicker(1 * time.Minute)
defer ticker.Stop()
@ -72,7 +73,7 @@ func main() {
if !inStack {
log.Println(post.Description)
toot, err := tooter.CreateToot(*mastoClient, post.Description)
toot, err := tooter.CreateToot(*mastoClient, post)
if err != nil {
log.Println(err)
}
@ -82,17 +83,6 @@ func main() {
stacker.SetToRedis(rdb, post.GUID, post.Description)
}
}
/*if news[0].GUID != lastGUID {
log.Println(news[0].Description)
toot, err := tooter.CreateToot(*mastoClient, news[0].Description)
if err != nil {
log.Println(err)
}
tooter.CreatePost(*mastoClient, toot)
lastGUID = news[0].GUID
}*/
}
return nil
},

10
stacker/go.mod Normal file
View file

@ -0,0 +1,10 @@
module kiki/stacker
go 1.24.2
require github.com/redis/go-redis/v9 v9.7.3
require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
)

25
tooter/go.mod Normal file
View file

@ -0,0 +1,25 @@
module kiki/tooter
go 1.24.2
require (
github.com/mattn/go-mastodon v0.0.9
github.com/mmcdole/gofeed v1.3.0
golang.org/x/net v0.39.0
gopkg.in/yaml.v2 v2.4.0
kiki/config v0.0.0-00010101000000-000000000000
)
require (
github.com/PuerkitoBio/goquery v1.8.0 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mmcdole/goxpp v1.1.1-0.20240225020742-a0c311522b23 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 // indirect
golang.org/x/text v0.24.0 // indirect
)
replace kiki/config => ../config

View file

@ -4,13 +4,14 @@ import (
"context"
"fmt"
"io"
"kiki/src/config"
"log"
"net/http"
"net/url"
"os"
"strings"
"kiki/config"
"github.com/mattn/go-mastodon"
"github.com/mmcdole/gofeed"
"golang.org/x/net/html"
@ -36,7 +37,8 @@ func ClientConfiguration(Instance string) {
log.Println(err)
}
var userToken string
fmt.Println(u)
//fmt.Println(u)
fmt.Printf("Перейдите по ссылке\n%s\nИ введите user token ниже:\n", u)
fmt.Scanln(&userToken)
conf := &mastodon.Config{
@ -126,17 +128,18 @@ func UploadPictures(mastoClient mastodon.Client, filesBytes [][]byte) []*mastodo
return attachments
}
func CreateToot(mastoClient mastodon.Client, newsDesc string) (mastodon.Toot, error) {
var tootText string
func CreateToot(mastoClient mastodon.Client, newsDesc *gofeed.Item) (mastodon.Toot, error) {
var imgArray []string
var attachments []*mastodon.Attachment
var tootText string = fmt.Sprintf("src: %s\n\n", newsDesc.Link)
toot := mastodon.Toot{
Visibility: "unlisted",
Sensitive: true,
}
uString := html.UnescapeString(newsDesc)
uString := html.UnescapeString(newsDesc.Description)
pHtml, err := html.Parse(strings.NewReader(uString))
if err != nil {
return mastodon.Toot{}, err
@ -144,14 +147,20 @@ func CreateToot(mastoClient mastodon.Client, newsDesc string) (mastodon.Toot, er
for n := range pHtml.Descendants() {
if n.Type != html.ElementNode {
tootText += (n.Data + "\n")
tootText += (n.Data)
}
if n.Type == html.ElementNode && n.Data == "img" {
for _, attr := range n.Attr {
if attr.Key == "src" {
imgArray = append(imgArray, attr.Val)
if n.Type == html.ElementNode {
switch n.Data {
case "img":
for _, attr := range n.Attr {
if attr.Key == "src" {
imgArray = append(imgArray, attr.Val)
}
}
case "br":
tootText += "\n"
}
}