-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
builder.go
110 lines (92 loc) · 2.59 KB
/
builder.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package message
import (
"time"
"github.com/gotd/td/telegram/message/markup"
"github.com/gotd/td/telegram/message/peer"
"github.com/gotd/td/tg"
)
type peerPromise = peer.Promise
// Builder is a message builder.
type Builder struct {
// Sender to use.
sender *Sender
// The destination where the message will be sent.
peer peerPromise
// Set this flag to disable generation of the webpage preview.
noWebpage bool
// Send this message silently (no notifications for the receivers).
silent bool
// Send this message as background message.
background bool
// Clear the draft field.
clearDraft bool
// The message ID to which this message will reply to.
replyToMsgID int
// Reply markup for sending bot buttons.
replyMarkup tg.ReplyMarkupClass
// Scheduled message date for scheduled messages.
scheduleDate int
}
func (b *Builder) copy() *Builder {
if b == nil {
return nil
}
r := *b
return &r
}
// Silent sets flag to send this message silently (no notifications for the receivers).
func (b *Builder) Silent() *Builder {
r := b.copy()
r.silent = true
return r
}
// Background sets flag to send this message as background message.
func (b *Builder) Background() *Builder {
r := b.copy()
r.background = true
return r
}
// Clear sets flag to clear the draft field.
func (b *Builder) Clear() *Builder {
r := b.copy()
r.clearDraft = true
return r
}
// Reply sets message ID to reply.
func (b *Builder) Reply(id int) *Builder {
r := b.copy()
r.replyToMsgID = id
return r
}
// ReplyMsg sets message to reply.
func (b *Builder) ReplyMsg(msg tg.MessageClass) *Builder {
return b.Reply(msg.GetID())
}
// ScheduleTS sets scheduled message timestamp for scheduled messages.
func (b *Builder) ScheduleTS(date int) *Builder {
r := b.copy()
r.scheduleDate = date
return r
}
// Schedule sets scheduled message date for scheduled messages.
func (b *Builder) Schedule(date time.Time) *Builder {
return b.ScheduleTS(int(date.Unix()))
}
// NoWebpage sets flag to disable generation of the webpage preview.
func (b *Builder) NoWebpage() *Builder {
r := b.copy()
r.noWebpage = true
return r
}
// Markup sets reply markup for sending bot buttons.
// NB: markup will not be used, if you send multiple media attachments.
func (b *Builder) Markup(m tg.ReplyMarkupClass) *Builder {
r := b.copy()
r.replyMarkup = m
return r
}
// Row sets single row keyboard markup for sending bot buttons.
// NB: markup will not be used, if you send multiple media attachments.
func (b *Builder) Row(button tg.KeyboardButtonClass, buttons ...tg.KeyboardButtonClass) *Builder {
return b.Markup(markup.InlineRow(button, buttons...))
}