This commit is contained in:
Rogee
2024-08-30 12:38:03 +08:00
parent 1fde6ee1ff
commit e43fa0f078
26 changed files with 647 additions and 2 deletions

46
internal/cmd_export.go Normal file
View File

@@ -0,0 +1,46 @@
package internal
import (
"context"
"github.com/gotd/td/tg"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
var (
channelID int64
channelAlias string
)
func ExportCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "export",
Short: "export channels",
RunE: wrapE(func(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
}
}
return client.Channel(ctx, channel, 0)
}),
}
cmd.Flags().Int64Var(&channelID, "channel", 0, "channel id")
cmd.Flags().StringVar(&channelAlias, "alias", "", "channel alias")
return cmd
}