-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
forward.go
70 lines (59 loc) · 1.59 KB
/
forward.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package message
import (
"context"
"golang.org/x/xerrors"
"github.com/gotd/td/tg"
)
// ForwardBuilder is a forward request builder.
type ForwardBuilder struct {
builder *Builder
from tg.InputPeerClass
ids []int
withMyScore bool
}
// WithMyScore sets flag to include your score in the forwarded game.
func (b *ForwardBuilder) WithMyScore() *ForwardBuilder {
b.withMyScore = true
return b
}
// Send sends forwarded messages.
func (b *ForwardBuilder) Send(ctx context.Context) (tg.UpdatesClass, error) {
p, err := b.builder.peer(ctx)
if err != nil {
return nil, xerrors.Errorf("peer: %w", err)
}
upd, err := b.builder.sender.forwardMessages(ctx, &tg.MessagesForwardMessagesRequest{
Silent: b.builder.silent,
Background: b.builder.background,
WithMyScore: b.withMyScore,
FromPeer: b.from,
ID: b.ids,
ToPeer: p,
ScheduleDate: b.builder.scheduleDate,
})
if err != nil {
return nil, xerrors.Errorf("send inline bot result: %w", err)
}
return upd, nil
}
// ForwardIDs creates builder to forward messages by ID.
func (b *Builder) ForwardIDs(from tg.InputPeerClass, id int, ids ...int) *ForwardBuilder {
return &ForwardBuilder{
builder: b,
from: from,
ids: append([]int{id}, ids...),
}
}
// ForwardMessages creates builder to forward messages.
func (b *Builder) ForwardMessages(from tg.InputPeerClass, msg tg.MessageClass, m ...tg.MessageClass) *ForwardBuilder {
r := make([]int, 1+len(m))
r[0] = msg.GetID()
for i := range m {
r[i+1] = m[i].GetID()
}
return &ForwardBuilder{
builder: b,
from: from,
ids: r,
}
}