Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Action struct {
- Type string
- Payload string
- Label string
- }
- type Button struct {
- Action Action
- Color string
- }
- type Buttons struct {
- Buttons []Button
- }
- func InitBByte(label string, payload []byte, color string) Button {
- b := Button{
- Action: Action{
- Type: "text",
- Payload: string(payload),
- Label: template.URLQueryEscaper(label),
- },
- Color: color,
- }
- return b
- }
- func Keyboard(chat float64, args ...Buttons) vk.H {
- var bs1 []Button
- var bs2 []Button
- var bs3 []Button
- var bs4 []Button
- for k, v := range args {
- if k == 0 {
- for _, b := range v.Buttons {
- bs1 = append(bs1, b)
- }
- }
- if k == 1 {
- for _, b := range v.Buttons {
- bs2 = append(bs2, b)
- }
- }
- if k == 2 {
- for _, b := range v.Buttons {
- bs3 = append(bs3, b)
- }
- }
- if k == 3 {
- for _, b := range v.Buttons {
- bs4 = append(bs4, b)
- }
- }
- }
- params := vk.H{}
- keb := vk.H{}
- if int(chat) > 2000000000 {
- keb["inline"] = true
- }
- keb["one_time"] = false
- if bs2 == nil {
- keb["buttons"] = []interface{}{bs1}
- } else if bs3 == nil {
- keb["buttons"] = []interface{}{bs1, bs2}
- } else if bs4 == nil {
- keb["buttons"] = []interface{}{bs1, bs2, bs3}
- } else {
- keb["buttons"] = []interface{}{bs1, bs2, bs3, bs4}
- }
- kbj, _ := json.Marshal(keb)
- params["keyboard"] = strings.ToLower(string(kbj))
- return params
- }
- func KbInline(one, two, three Buttons) vk.H {
- var bs1 []Button
- var bs2 []Button
- var bs3 []Button
- for _, b := range one.Buttons {
- bs1 = append(bs1, b)
- }
- for _, b := range two.Buttons {
- bs2 = append(bs2, b)
- }
- for _, b := range three.Buttons {
- bs3 = append(bs3, b)
- }
- params := vk.H{}
- kb := vk.H{}
- kb["inline"] = true
- if bs2 == nil {
- kb["buttons"] = []interface{}{one.Buttons}
- } else if bs3 == nil {
- kb["buttons"] = []interface{}{bs1, bs2}
- } else {
- kb["buttons"] = []interface{}{bs1, bs2, bs3}
- }
- kbj, _ := json.Marshal(kb)
- params["keyboard"] = strings.ToLower(string(kbj))
- return params
- }
- func Back(payload string) Buttons {
- s := InitBByte("Назад", []byte(`{"payload":"`+payload+`"}`), "secondary")
- params := Buttons{Buttons: []Button{s}}
- return params
- }
- func Menu(i float64) Buttons {
- if i < 2000000000 {
- s := InitBByte("Назад", []byte(`{"payload":"menu"}`), "secondary")
- params := Buttons{Buttons: []Button{s}}
- return params
- } else {
- return Buttons{}
- }
- }
- ##########################################
- s := bts.InitBByte("Моя стата", []byte(`{"payload":"invitestat"}`), "primary")
- params := bts.Keyboard(id.Chat, bts.Buttons{Buttons: []bts.Button{s}}, bts.Menu(id.Chat))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement