From e26fbdbdb87c7c24ddb90710036e275325612c64 Mon Sep 17 00:00:00 2001 From: Divanshu Chauhan Date: Sun, 4 Aug 2024 19:45:15 +0530 Subject: [PATCH] add new logs for error in admincache --- .gitignore | 1 + alita/utils/cache/adminCache.go | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index c6f671d3..a7f03757 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ Alita_Robot Alita_Robot.exe .env .db.env +local.docker-compose.yml # Mac OS DS_Store file .DS_Store diff --git a/alita/utils/cache/adminCache.go b/alita/utils/cache/adminCache.go index 4892a258..f9dfdeeb 100644 --- a/alita/utils/cache/adminCache.go +++ b/alita/utils/cache/adminCache.go @@ -10,6 +10,15 @@ import ( // LoadAdminCache loads the admin cache for the chat. func LoadAdminCache(b *gotgbot.Bot, chat *gotgbot.Chat) AdminCache { + if b == nil { + log.Error("LoadAdminCache: bot is nil") + return AdminCache{} + } + if chat == nil { + log.Error("LoadAdminCache: chat is nil") + return AdminCache{} + } + adminList, err := chat.GetAdministrators(b, nil) if err != nil { log.Error(err) @@ -17,7 +26,6 @@ func LoadAdminCache(b *gotgbot.Bot, chat *gotgbot.Chat) AdminCache { } var userList []gotgbot.MergedChatMember - for _, admin := range adminList { userList = append(userList, admin.MergeChatMember()) } @@ -45,13 +53,17 @@ func LoadAdminCache(b *gotgbot.Bot, chat *gotgbot.Chat) AdminCache { // GetAdminCacheList gets the admin cache for the chat. func GetAdminCacheList(chatId int64) (bool, AdminCache) { - gotAdminlist, _ := Marshal.Get( + gotAdminlist, err := Marshal.Get( Context, AdminCache{ ChatId: chatId, }, new(AdminCache), ) + if err != nil { + log.Error(err) + return false, AdminCache{} + } if gotAdminlist == nil { return false, AdminCache{} }