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 ( import (
"CatsOfMastodonBotGo/models" "CatsOfMastodonBotGo/models"
"gorm.io/gorm" "gorm.io/gorm"
) )
@@ -20,11 +21,10 @@ func GetExistingAccountIds(db *gorm.DB) []string {
db.Model(&models.Account{}).Pluck("acc_id", &existingAccountIds) db.Model(&models.Account{}).Pluck("acc_id", &existingAccountIds)
return existingAccountIds return existingAccountIds
} }
func GetNewPosts(existingPostIds []string, posts []models.Post) []models.Post { func GetNewPosts(existingPostIds []string, posts []models.Post) []models.Post {
var newPosts []models.Post = nil var newPosts []models.Post = nil
for _, post := range posts { 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) newPosts = append(newPosts, post)
} }
} }
@@ -41,11 +41,11 @@ func GetNewAccounts(existingAccountIds []string, posts []models.Post) []models.A
return newAccounts return newAccounts
} }
func InsertNewPosts(db *gorm.DB, newPosts []models.Post) int{ func InsertNewPosts(db *gorm.DB, newPosts []models.Post) int {
return int(db.Create(&newPosts).RowsAffected) return int(db.Create(&newPosts).RowsAffected)
} }
func InsertNewAccounts(db *gorm.DB, newAccounts []models.Account) int{ func InsertNewAccounts(db *gorm.DB, newAccounts []models.Account) int {
return int(db.Create(&newAccounts).RowsAffected) return int(db.Create(&newAccounts).RowsAffected)
} }
@@ -57,7 +57,3 @@ func arrayContains(arr []string, str string) bool {
} }
return false return false
} }

10
main.go
View File

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