mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-05-11 19:19:41 +08:00
fix: compatibility between tdlib and bot api style chatID
This commit is contained in:
@@ -103,8 +103,8 @@ func (t *Telegram) Save(ctx context.Context, r io.Reader, storagePath string) er
|
||||
if filename == "" {
|
||||
filename = xid.New().String() + mtype.Extension()
|
||||
}
|
||||
peer := tctx.PeerStorage.GetInputPeerById(chatID)
|
||||
if peer == nil {
|
||||
peer := tryGetInputPeer(tctx, chatID)
|
||||
if peer == nil || peer.Zero() {
|
||||
return fmt.Errorf("failed to get input peer for chat ID %d", chatID)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@ import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/celestix/gotgproto/ext"
|
||||
"github.com/gotd/td/constant"
|
||||
"github.com/gotd/td/tg"
|
||||
"github.com/krau/ffmpeg-go"
|
||||
"github.com/yapingcat/gomedia/go-mp4"
|
||||
)
|
||||
@@ -133,3 +136,28 @@ func extractFrameAt(rs io.ReadSeeker, timestamp float64) ([]byte, error) {
|
||||
|
||||
return out.Bytes(), nil
|
||||
}
|
||||
|
||||
func tryGetInputPeer(ctx *ext.Context, chatID int64) tg.InputPeerClass {
|
||||
peer := ctx.PeerStorage.GetInputPeerById(chatID)
|
||||
if peer != nil && !peer.Zero() {
|
||||
return peer
|
||||
}
|
||||
id := constant.TDLibPeerID(chatID)
|
||||
plain := id.ToPlain()
|
||||
var channel constant.TDLibPeerID
|
||||
channel.Channel(plain)
|
||||
peer = ctx.PeerStorage.GetInputPeerById(int64(channel))
|
||||
if peer != nil && !peer.Zero() {
|
||||
return peer
|
||||
}
|
||||
var chat constant.TDLibPeerID
|
||||
chat.Chat(plain)
|
||||
peer = ctx.PeerStorage.GetInputPeerById(int64(chat))
|
||||
if peer != nil && !peer.Zero() {
|
||||
return peer
|
||||
}
|
||||
var user constant.TDLibPeerID
|
||||
user.User(plain)
|
||||
peer = ctx.PeerStorage.GetInputPeerById(int64(user))
|
||||
return peer
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user