/
document.go
99 lines (83 loc) · 2.64 KB
/
document.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
package inline
import "github.com/gotd/td/tg"
// DocumentResultBuilder is document result option builder.
type DocumentResultBuilder struct {
result *tg.InputBotInlineResultDocument
msg MessageOption
}
func (b *DocumentResultBuilder) apply(r *resultPageBuilder) error {
m, err := b.msg.apply()
if err != nil {
return err
}
t := tg.InputBotInlineResultDocument{
ID: b.result.ID,
Type: b.result.Type,
Title: b.result.Title,
Description: b.result.Description,
Document: b.result.Document,
}
if t.ID == "" {
t.ID, err = r.generateID()
if err != nil {
return err
}
}
t.SendMessage = m
r.results = append(r.results, &t)
return nil
}
// ID sets ID of result.
// Should not be empty, so if id is not provided, random will be used.
func (b *DocumentResultBuilder) ID(id string) *DocumentResultBuilder {
b.result.ID = id
return b
}
// Title sets Result description.
func (b *DocumentResultBuilder) Title(title string) *DocumentResultBuilder {
b.result.SetTitle(title)
return b
}
// Description sets Result description.
func (b *DocumentResultBuilder) Description(description string) *DocumentResultBuilder {
b.result.SetDescription(description)
return b
}
// Document creates document result option builder.
func Document(doc tg.InputDocumentClass, typ string, msg MessageOption) *DocumentResultBuilder {
return &DocumentResultBuilder{
result: &tg.InputBotInlineResultDocument{
Type: typ,
Document: doc,
},
msg: msg,
}
}
// Video creates video result option builder.
func Video(doc tg.InputDocumentClass, msg MessageOption) *DocumentResultBuilder {
return Document(doc, VideoType, msg)
}
// Audio creates audio result option builder.
func Audio(doc tg.InputDocumentClass, msg MessageOption) *DocumentResultBuilder {
return Document(doc, AudioType, msg)
}
// File creates document result option builder.
func File(doc tg.InputDocumentClass, msg MessageOption) *DocumentResultBuilder {
return Document(doc, DocumentType, msg)
}
// GIF creates gif result option builder.
func GIF(doc tg.InputDocumentClass, msg MessageOption) *DocumentResultBuilder {
return Document(doc, GIFType, msg)
}
// MPEG4GIF creates mpeg4gif result option builder.
func MPEG4GIF(doc tg.InputDocumentClass, msg MessageOption) *DocumentResultBuilder {
return Document(doc, MPEG4GIFType, msg)
}
// Voice creates voice result option builder.
func Voice(doc tg.InputDocumentClass, msg MessageOption) *DocumentResultBuilder {
return Document(doc, VoiceType, msg)
}
// Sticker creates sticker result option builder.
func Sticker(doc tg.InputDocumentClass, msg MessageOption) *DocumentResultBuilder {
return Document(doc, StickerType, msg)
}