From 772421c40df4b542066ac0477e3a0630cff5f5eb Mon Sep 17 00:00:00 2001 From: Rogee Date: Mon, 2 Sep 2024 16:20:28 +0800 Subject: [PATCH] fix: issues --- .vscode/launch.json | 3 ++- internal/client_channel.go | 2 +- internal/client_channel_config.go | 5 ++++- internal/cmd_export.go | 6 +++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 994be44..bef9e28 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,7 +13,8 @@ "args": [ "export", "--alias", - "yunpanshare" + "yunpanshare", + "--history", ] } ] diff --git a/internal/client_channel.go b/internal/client_channel.go index bd11424..2a1b192 100644 --- a/internal/client_channel.go +++ b/internal/client_channel.go @@ -15,7 +15,7 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *Channel request := &tg.MessagesGetHistoryRequest{ Peer: inputPeer, - Limit: 1, + Limit: 10, } if modeHistory { // 提供此ID供遍历历史消息 diff --git a/internal/client_channel_config.go b/internal/client_channel_config.go index 3536881..fe239ed 100644 --- a/internal/client_channel_config.go +++ b/internal/client_channel_config.go @@ -17,6 +17,9 @@ type ChannelConfig struct { } func NewChannelConfig(channelID int64) *ChannelConfig { + if channelID == 0 { + panic("channel id is required") + } return &ChannelConfig{ID: channelID} } @@ -53,7 +56,7 @@ func (c *ChannelConfig) file(_ context.Context) (string, error) { // if file not exists then create it if _, err := os.Stat(channelConfigFile); os.IsNotExist(err) { // create config file - data, _ := json.Marshal(&ChannelConfig{ID: channelID}) + data, _ := json.Marshal(c) if err := os.WriteFile(channelConfigFile, data, 0o644); err != nil { return "", errors.Wrap(err, "write channel config") } diff --git a/internal/cmd_export.go b/internal/cmd_export.go index 760f343..7ab274b 100644 --- a/internal/cmd_export.go +++ b/internal/cmd_export.go @@ -47,7 +47,11 @@ func exportCmd(ctx context.Context) error { } } - cfg := NewChannelConfig(channel.ID) + if channel.GetID() == 0 { + return errors.New("channel not found") + } + + cfg := NewChannelConfig(channel.GetID()) if err := cfg.Read(ctx); err != nil { return err }