mirror of
https://github.com/iyear/tdl
synced 2025-01-09 04:17:35 +08:00
feat(forwarder): support forward single grouped message with --single
flag. close #487
This commit is contained in:
parent
757011033a
commit
fce339c7d7
@ -29,3 +29,5 @@ func (i *iterElem) Thread() int { return i.thread }
|
||||
func (i *iterElem) AsSilent() bool { return i.opts.silent }
|
||||
|
||||
func (i *iterElem) AsDryRun() bool { return i.opts.dryRun }
|
||||
|
||||
func (i *iterElem) AsGrouped() bool { return i.opts.grouped }
|
||||
|
@ -34,6 +34,7 @@ type Options struct {
|
||||
Mode forwarder.Mode
|
||||
Silent bool
|
||||
DryRun bool
|
||||
Single bool
|
||||
}
|
||||
|
||||
func Run(ctx context.Context, c *telegram.Client, kvd kv.KV, opts Options) (rerr error) {
|
||||
@ -84,6 +85,7 @@ func Run(ctx context.Context, c *telegram.Client, kvd kv.KV, opts Options) (rerr
|
||||
mode: opts.Mode,
|
||||
silent: opts.Silent,
|
||||
dryRun: opts.DryRun,
|
||||
grouped: !opts.Single,
|
||||
}),
|
||||
Progress: newProgress(fwProgress),
|
||||
PartSize: viper.GetInt(consts.FlagPartSize),
|
||||
|
@ -24,6 +24,7 @@ type iterOptions struct {
|
||||
mode forwarder.Mode
|
||||
silent bool
|
||||
dryRun bool
|
||||
grouped bool
|
||||
}
|
||||
|
||||
type iter struct {
|
||||
|
@ -32,6 +32,7 @@ func NewForward() *cobra.Command {
|
||||
cmd.Flags().Var(&opts.Mode, "mode", fmt.Sprintf("forward mode: [%s]", strings.Join(forwarder.ModeNames(), ", ")))
|
||||
cmd.Flags().BoolVar(&opts.Silent, "silent", false, "send messages silently")
|
||||
cmd.Flags().BoolVar(&opts.DryRun, "dry-run", false, "do not actually send messages, just show how they would be sent")
|
||||
cmd.Flags().BoolVar(&opts.Single, "single", false, "do not automatically detect and forward grouped messages")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func (f *Forwarder) Forward(ctx context.Context) error {
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := elem.Msg().GetGroupedID(); ok {
|
||||
if _, ok := elem.Msg().GetGroupedID(); ok && elem.AsGrouped() {
|
||||
grouped, err := utils.Telegram.GetGroupedMessages(ctx, f.opts.Pool.Default(ctx), elem.From().InputPeer(), elem.Msg())
|
||||
if err != nil {
|
||||
continue
|
||||
|
@ -23,4 +23,5 @@ type Elem interface {
|
||||
|
||||
AsSilent() bool
|
||||
AsDryRun() bool
|
||||
AsGrouped() bool // detect and forward grouped messages
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user