From d99d47e4e189305225272dc7865ae6eae9a49c8a Mon Sep 17 00:00:00 2001 From: B4D_US3R Date: Thu, 10 Apr 2025 19:29:33 +0500 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=BA=D0=B8=20=D1=82=D1=83=D1=82=D0=BE=D0=B2?= =?UTF-8?q?,=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B0=D0=B2=D1=82?= =?UTF-8?q?=D0=BE=D0=BC=D0=B0=D1=82=D0=BE=D0=BC=20=D0=BE=D1=82=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D1=8F=D0=B5=D1=82=D1=81=D1=8F=20=D0=B8=20=D1=82?= =?UTF-8?q?=D0=B5=D0=BA=D1=81=D1=82=20=D0=B2=20=D0=BF=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B5,=20=D0=B8=20=D0=BA=D0=B0=D1=80=D1=82=D0=B8=D0=BD=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 27 +++++++++++++++++++++++- config.yaml | 2 -- main.go | 59 +++++++++++++++-------------------------------------- 3 files changed, 43 insertions(+), 45 deletions(-) delete mode 100644 config.yaml diff --git a/.gitignore b/.gitignore index bdd4986..83d7ac2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,28 @@ secret.conf go.sum -config.yaml \ No newline at end of file +config.yaml + +### Go ### +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work + +# End of https://www.toptal.com/developers/gitignore/api/go diff --git a/config.yaml b/config.yaml deleted file mode 100644 index 81b3139..0000000 --- a/config.yaml +++ /dev/null @@ -1,2 +0,0 @@ -instance: pleroma.catgirls.asia -rss_url: https://pleroma.catgirls.asia/users/SiberiaBread/feed.atom \ No newline at end of file diff --git a/main.go b/main.go index 07eab1b..41a3c2d 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,7 @@ type KikiSettings struct { RSSUri string `yaml:"rss_url,omitempty"` } -func getDataFromConfig(path string) *mastodon.Config { +func getSecrets(path string) *mastodon.Config { var clientData MastodonClientData secretConfig, err := os.ReadFile(path) if err != nil { @@ -154,16 +154,7 @@ func newsText(url string) []*gofeed.Item { return feed.Items } -func createPost(statusText string) { - config := getDataFromConfig("secret.conf") - - mastoClient := mastodon.NewClient(config) - - toot := mastodon.Toot{ - Status: statusText, - Visibility: "unlisted", - } - +func createPost(mastoClient mastodon.Client, toot mastodon.Toot) { _, err := mastoClient.PostStatus(context.Background(), &toot) if err != nil { log.Println(err) @@ -189,10 +180,8 @@ func picBytesArray(picturesArray []string) [][]byte { return picturesBytes } -func uploadPictures(filesBytes [][]byte) []*mastodon.Attachment { - config := getDataFromConfig("secret.conf") +func uploadPictures(mastoClient mastodon.Client, filesBytes [][]byte) []*mastodon.Attachment { var attachments []*mastodon.Attachment - mastoClient := mastodon.NewClient(config) for _, file := range filesBytes { att, err := mastoClient.UploadMediaFromBytes(context.Background(), file) if err != nil { @@ -204,25 +193,6 @@ func uploadPictures(filesBytes [][]byte) []*mastodon.Attachment { return attachments } -func postWithPictures(attachments []*mastodon.Attachment) { - var mediaID []mastodon.ID - config := getDataFromConfig("secret.conf") - mastoClient := mastodon.NewClient(config) - for _, attach := range attachments { - mediaID = append(mediaID, attach.ID) - } - toot := mastodon.Toot{ - MediaIDs: mediaID, - Visibility: "unlisted", - Sensitive: true, - } - _, err := mastoClient.PostStatus(context.Background(), &toot) - if err != nil { - log.Println(err) - } - -} - func main() { cmd := &cli.Command{ Name: "kiki", @@ -256,21 +226,26 @@ func main() { log.Println(err) } kikiConfig := getKikiConfig(confFile) + mastoClient := mastodon.NewClient(getSecrets("secret.conf")) ticker := time.NewTicker(1 * time.Minute) defer ticker.Stop() for range ticker.C { news := newsText(kikiConfig.RSSUri) if news[0].GUID != lastGUID { - if !hasHTMLTags(news[0].Description) { - log.Println(news[0].Description) - createPost(news[0].Description) - lastGUID = news[0].GUID - log.Println("Пост отправлен") - } else { - attachments := uploadPictures(picBytesArray(returnImgArray(news[0].Description))) - postWithPictures(attachments) - lastGUID = news[0].GUID + toot := mastodon.Toot{ + Visibility: "unlisted", + Sensitive: true, } + log.Println(news[0].Description) + toot.Status = news[0].Description + lastGUID = news[0].GUID + if hasHTMLTags(news[0].Description) { + attachments := uploadPictures(*mastoClient, picBytesArray(returnImgArray(news[0].Description))) + for _, attach := range attachments { + toot.MediaIDs = append(toot.MediaIDs, attach.ID) + } + } + createPost(*mastoClient, toot) } } return nil