Fix tgbot - document upload issue for empty ban logs

This commit is contained in:
MHSanaei 2024-02-04 01:50:14 +03:30
parent 9d724d34e1
commit 2a2bf531ee

View file

@ -1568,30 +1568,44 @@ func (t *Tgbot) sendBanLogs(chatId int64, dt bool) {
file, err := os.Open(xray.GetIPLimitBannedPrevLogPath()) file, err := os.Open(xray.GetIPLimitBannedPrevLogPath())
if err == nil { if err == nil {
// Check if the file is non-empty before attempting to upload
fileInfo, _ := file.Stat()
if fileInfo.Size() > 0 {
document := tu.Document( document := tu.Document(
tu.ID(chatId), tu.ID(chatId),
tu.File(file), tu.File(file),
) )
_, err = bot.SendDocument(document) _, err = bot.SendDocument(document)
if err != nil { if err != nil {
logger.Error("Error in uploading backup: ", err) logger.Error("Error in uploading IPLimitBannedPrevLog: ", err)
} }
} else { } else {
logger.Error("Error in opening db file for backup: ", err) logger.Warning("IPLimitBannedPrevLog file is empty, not uploading.")
}
file.Close()
} else {
logger.Error("Error in opening IPLimitBannedPrevLog file for backup: ", err)
} }
file, err = os.Open(xray.GetIPLimitBannedLogPath()) file, err = os.Open(xray.GetIPLimitBannedLogPath())
if err == nil { if err == nil {
// Check if the file is non-empty before attempting to upload
fileInfo, _ := file.Stat()
if fileInfo.Size() > 0 {
document := tu.Document( document := tu.Document(
tu.ID(chatId), tu.ID(chatId),
tu.File(file), tu.File(file),
) )
_, err = bot.SendDocument(document) _, err = bot.SendDocument(document)
if err != nil { if err != nil {
logger.Error("Error in uploading config.json: ", err) logger.Error("Error in uploading IPLimitBannedLog: ", err)
} }
} else { } else {
logger.Error("Error in opening config.json file for backup: ", err) logger.Warning("IPLimitBannedLog file is empty, not uploading.")
}
file.Close()
} else {
logger.Error("Error in opening IPLimitBannedLog file for backup: ", err)
} }
} }