Filter bot posts and add env vars for instance and tag configuration

This commit is contained in:
2025-05-10 22:26:15 +03:30
parent 5a897b5412
commit 8be6290635
2 changed files with 11 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ package helpers
import (
"CatsOfMastodonBotGo/models"
"gorm.io/gorm"
)
@@ -20,11 +21,10 @@ func GetExistingAccountIds(db *gorm.DB) []string {
db.Model(&models.Account{}).Pluck("acc_id", &existingAccountIds)
return existingAccountIds
}
func GetNewPosts(existingPostIds []string, posts []models.Post) []models.Post {
var newPosts []models.Post = nil
for _, post := range posts {
if !arrayContains(existingPostIds, post.ID) {
if !arrayContains(existingPostIds, post.ID) && len(post.Attachments) > 0 && !post.Account.IsBot {
newPosts = append(newPosts, post)
}
}
@@ -57,7 +57,3 @@ func arrayContains(arr []string, str string) bool {
}
return false
}

10
main.go
View File

@@ -13,8 +13,11 @@ import (
)
func main() {
var tag = "catsofmastodon"
var instance = os.Getenv("INSTANCE")
var tag = os.Getenv("COM_TAG")
if tag == "" {
tag = "catsofmastodon"
}
var instance = os.Getenv("COM_INSTANCE")
if instance == "" {
instance = "https://haminoa.net"
}
@@ -35,8 +38,9 @@ func main() {
var existingPostIds = helpers.GetExistingPostIds(db)
var existingAccountIds = helpers.GetExistingAccountIds(db)
var newAccounts = helpers.GetNewAccounts(existingAccountIds, posts)
var newPosts = helpers.GetNewPosts(existingPostIds, posts)
var newAccounts = helpers.GetNewAccounts(existingAccountIds, newPosts)
log.Println("Number of existing posts: ", len(existingPostIds))
log.Println("Number of existing accounts: ", len(existingAccountIds))