-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
option.go
46 lines (36 loc) · 1 KB
/
option.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
package inline
import (
"io"
"strconv"
"github.com/gotd/td/internal/crypto"
"github.com/gotd/td/tg"
)
type resultPageBuilder struct {
results []tg.InputBotInlineResultClass
random io.Reader
}
func (r *resultPageBuilder) generateID() (string, error) {
n, err := crypto.RandInt64(r.random)
if err != nil {
return "", err
}
return strconv.FormatInt(n, 10), nil
}
// ResultOption is an option of inline result.
type ResultOption interface {
apply(r *resultPageBuilder) error
}
// MessageOption is an option of inline result message.
type MessageOption interface {
apply() (tg.InputBotInlineMessageClass, error)
}
type messageOptionFunc func() (tg.InputBotInlineMessageClass, error)
func (m messageOptionFunc) apply() (tg.InputBotInlineMessageClass, error) {
return m()
}
// ResultMessage creates new MessageOption from given message object.
func ResultMessage(r tg.InputBotInlineMessageClass) MessageOption {
return messageOptionFunc(func() (tg.InputBotInlineMessageClass, error) {
return r, nil
})
}