-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbutton_func.go
84 lines (62 loc) · 1.7 KB
/
button_func.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
package telebot
import (
"fmt"
"net/url"
)
// NewInlineKeyboardButton creates a new inline keyboard button with the given text and options.
func NewInlineKeyboardButton(text string, options ...any) Button {
btn := &InlineKeyboardButton{
Text: text,
}
for _, option := range options {
switch value := option.(type) {
case string:
btn.CallbackData = toPtr(fmt.Sprintf("\f%s", value))
case *string:
btn.CallbackData = toPtr(fmt.Sprintf("\f%s", *value))
case *url.URL:
btn.URL = toPtr(value.String())
case *WebAppInfo:
btn.WebApp = value
case *LoginURL:
btn.LoginURL = value
case *SwitchInlineQueryStringType:
btn.SwitchInlineQuery = toPtr(string(*value))
case *SwitchInlineQueryChosenChatStringType:
btn.SwitchInlineQueryCurrentChat = toPtr(string(*value))
case *SwitchInlineQueryChosenChat:
btn.SwitchInlineQueryChosenChat = value
case *CallbackGame:
btn.CallbackGame = value
case bool:
btn.Pay = &value
}
}
if len(options) == 0 {
panic("telebot: NewInlineKeyboardButton: no options provided")
}
return btn
}
// NewKeyboardButton creates a new keyboard button with the given text and options.
func NewKeyboardButton(text string, options ...any) Button {
btn := &KeyboardButton{
Text: text,
}
for _, option := range options {
switch value := option.(type) {
case *KeyboardButtonRequestUsers:
btn.RequestUsers = value
case *KeyboardButtonRequestChat:
btn.RequestChat = value
case *RequestContact:
btn.RequestContact = toPtr(bool(*value))
case *RequestLocation:
btn.RequestLocation = toPtr(bool(*value))
case *KeyboardButtonPollType:
btn.RequestPoll = value
case *WebAppInfo:
btn.WebApp = value
}
}
return btn
}