mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-08-08 22:13:25 +08:00
refactor: simplify GetMessagesRange function and improve error message formatting
This commit is contained in:
@@ -113,29 +113,28 @@ func InputMessageClassSliceFromInt(ids []int) []tg.InputMessageClass {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMessagesRange(ctx *ext.Context, chatID int64, minId, maxId int) ([]*tg.Message, error) {
|
func GetMessagesRange(ctx *ext.Context, chatID int64, minId, maxId int) (msg []*tg.Message, err error) {
|
||||||
if msg, err := getMessagesRange(ctx, chatID, minId, maxId); err == nil {
|
if msg, err = getMessagesRange(ctx, chatID, minId, maxId); err == nil {
|
||||||
return msg, nil
|
return
|
||||||
}
|
}
|
||||||
in := constant.TDLibPeerID(chatID)
|
in := constant.TDLibPeerID(chatID)
|
||||||
plain := in.ToPlain()
|
plain := in.ToPlain()
|
||||||
|
|
||||||
var channel constant.TDLibPeerID
|
var channel constant.TDLibPeerID
|
||||||
channel.Channel(plain)
|
channel.Channel(plain)
|
||||||
if msg, err := getMessagesRange(ctx, int64(channel), minId, maxId); err == nil {
|
if msg, err = getMessagesRange(ctx, int64(channel), minId, maxId); err == nil {
|
||||||
return msg, nil
|
return
|
||||||
}
|
}
|
||||||
var userID constant.TDLibPeerID
|
var userID constant.TDLibPeerID
|
||||||
userID.User(plain)
|
userID.User(plain)
|
||||||
if msg, err := getMessagesRange(ctx, int64(userID), minId, maxId); err == nil {
|
if msg, err = getMessagesRange(ctx, int64(userID), minId, maxId); err == nil {
|
||||||
return msg, nil
|
return
|
||||||
}
|
}
|
||||||
var chat constant.TDLibPeerID
|
var chat constant.TDLibPeerID
|
||||||
chat.Chat(plain)
|
chat.Chat(plain)
|
||||||
if msg, err := getMessagesRange(ctx, int64(chat), minId, maxId); err == nil {
|
if msg, err = getMessagesRange(ctx, int64(chat), minId, maxId); err == nil {
|
||||||
return msg, nil
|
return
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("failed to get messages range for chatID %d", chatID)
|
return nil, fmt.Errorf("failed to get messages range for chat %d: %w", chatID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessagesRange(ctx *ext.Context, chatID int64, minId, maxId int) ([]*tg.Message, error) {
|
func getMessagesRange(ctx *ext.Context, chatID int64, minId, maxId int) ([]*tg.Message, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user