Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed range of nil slice from BlacklistStriuct #446

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions alita/db/blacklists_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,26 @@ 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)
if err != nil {
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 {
Expand Down