diff --git a/helpers/dbHelpers.go b/helpers/dbHelpers.go index 9dd402a..be9ac2b 100644 --- a/helpers/dbHelpers.go +++ b/helpers/dbHelpers.go @@ -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) } } @@ -41,11 +41,11 @@ func GetNewAccounts(existingAccountIds []string, posts []models.Post) []models.A 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) } -func InsertNewAccounts(db *gorm.DB, newAccounts []models.Account) int{ +func InsertNewAccounts(db *gorm.DB, newAccounts []models.Account) int { return int(db.Create(&newAccounts).RowsAffected) } @@ -57,7 +57,3 @@ func arrayContains(arr []string, str string) bool { } return false } - - - - diff --git a/main.go b/main.go index 677ccba..89b1b66 100644 --- a/main.go +++ b/main.go @@ -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))