mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-07-10 23:12:28 +08:00
fix: parse chat ID correctly in Save method for Telegram storage
This commit is contained in:
@@ -5,8 +5,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/duke-git/lancet/v2/convertor"
|
||||||
"github.com/gabriel-vasile/mimetype"
|
"github.com/gabriel-vasile/mimetype"
|
||||||
"github.com/gotd/td/telegram/message"
|
"github.com/gotd/td/telegram/message"
|
||||||
"github.com/gotd/td/telegram/message/styling"
|
"github.com/gotd/td/telegram/message/styling"
|
||||||
@@ -70,9 +73,17 @@ func (t *Telegram) Save(ctx context.Context, r io.Reader, storagePath string) er
|
|||||||
if tctx == nil {
|
if tctx == nil {
|
||||||
return fmt.Errorf("failed to get telegram context")
|
return fmt.Errorf("failed to get telegram context")
|
||||||
}
|
}
|
||||||
peer := tctx.PeerStorage.GetInputPeerById(t.config.ChatID)
|
chatID := t.config.ChatID
|
||||||
|
if after, ok0 := strings.CutPrefix(convertor.ToString(chatID), "-100"); ok0 {
|
||||||
|
cid, err := strconv.ParseInt(after, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to parse chat ID: %w", err)
|
||||||
|
}
|
||||||
|
chatID = cid
|
||||||
|
}
|
||||||
|
peer := tctx.PeerStorage.GetInputPeerById(chatID)
|
||||||
if peer == nil {
|
if peer == nil {
|
||||||
return fmt.Errorf("failed to get input peer for chat ID %d", t.config.ChatID)
|
return fmt.Errorf("failed to get input peer for chat ID %d", chatID)
|
||||||
}
|
}
|
||||||
mtype, err := mimetype.DetectReader(rs)
|
mtype, err := mimetype.DetectReader(rs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user