package internal import ( "context" "github.com/gotd/td/tg" "github.com/pkg/errors" "github.com/spf13/cobra" ) var ( channelID int64 modeHistory bool channelAlias string ) func ExportCmd() *cobra.Command { cmd := &cobra.Command{ Use: "export", Short: "export channels", RunE: wrapE(exportCmd), } cmd.Flags().Int64Var(&channelID, "channel", 0, "channel id") cmd.Flags().BoolVar(&modeHistory, "history", false, "history mode") cmd.Flags().StringVar(&channelAlias, "alias", "", "channel alias") return cmd } func exportCmd(ctx context.Context) error { if channelID == 0 && channelAlias == "" { return errors.New("channel id or alias is required") } var channel *tg.Channel var err error if channelAlias != "" { channel, err = client.ChannelInfoByAlias(ctx, channelAlias) if err != nil { return err } } else { channel, err = client.ChannelInfoByID(ctx, channelID) if err != nil { return err } } cfg := NewChannelConfig(channel.ID) if err := cfg.Read(ctx); err != nil { return err } // https://t.me/yunpanshare/37426 return client.Channel(ctx, channel, cfg, modeHistory) }