From 24e0000e55128f408256e0be0638222078a05dae Mon Sep 17 00:00:00 2001 From: Sleryfink <84753790+aryazakaria01@users.noreply.github.com> Date: Wed, 14 Aug 2024 14:43:32 +0700 Subject: [PATCH] fixed range of nil slice from BlacklistStriuct Signed-off-by: Sleryfink <84753790+aryazakaria01@users.noreply.github.com> --- alita/db/blacklists_db.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/alita/db/blacklists_db.go b/alita/db/blacklists_db.go index 1ba98e4b..4ed94504 100644 --- a/alita/db/blacklists_db.go +++ b/alita/db/blacklists_db.go @@ -80,7 +80,8 @@ func GetBlacklistSettings(chatId int64) *BlacklistSettings { } func LoadBlacklistsStats() (blacklistTriggers, blacklistChats int64) { - var BlacklistStriuct []*BlacklistSettings + var blacklistStruct []*BlacklistSettings + cursor := findAll(blacklistsColl, bson.M{}) defer func(cursor *mongo.Cursor, ctx context.Context) { err := cursor.Close(ctx) @@ -88,7 +89,17 @@ func LoadBlacklistsStats() (blacklistTriggers, blacklistChats int64) { log.Error(err) } }(cursor, bgCtx) - for _, i := range BlacklistStriuct { + + for cursor.Next(bgCtx) { + var blacklistSetting BlacklistSettings + if err := cursor.Decode(&blacklistSetting); err != nil { + log.Error("Failed to decode blacklist setting:", err) + continue + } + blacklistStruct = append(blacklistStruct, &blacklistSetting) + } + + for _, i := range blacklistStruct { lenBl := len(i.Triggers) blacklistTriggers += int64(lenBl) if lenBl > 0 {