-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathinline_query.go
111 lines (98 loc) · 2.87 KB
/
inline_query.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
111
package main
import (
"fmt"
"strconv"
"strings"
log "github.com/sirupsen/logrus"
tb "gopkg.in/tucnak/telebot.v2"
)
const queryImage = "https://avatars.githubusercontent.com/u/88730856?v=4"
func (bot TipBot) inlineQueryInstructions(q *tb.Query) {
instructions := []struct {
url string
title string
description string
}{
{
url: queryImage,
title: inlineQuerySendTitle,
description: fmt.Sprintf(inlineQuerySendDescription, bot.telegram.Me.Username),
},
{
url: queryImage,
title: inlineQueryReceiveTitle,
description: fmt.Sprintf(inlineQueryReceiveDescription, bot.telegram.Me.Username),
},
{
url: queryImage,
title: inlineQueryFaucetTitle,
description: fmt.Sprintf(inlineQueryFaucetDescription, bot.telegram.Me.Username),
},
}
results := make(tb.Results, len(instructions)) // []tb.Result
for i, instruction := range instructions {
result := &tb.ArticleResult{
//URL: instruction.url,
Text: instruction.description,
Title: instruction.title,
Description: instruction.description,
// required for photos
ThumbURL: instruction.url,
}
results[i] = result
// needed to set a unique string ID for each result
results[i].SetResultID(strconv.Itoa(i))
}
err := bot.telegram.Answer(q, &tb.QueryResponse{
Results: results,
CacheTime: 5, // a minute
IsPersonal: true,
QueryID: q.ID,
})
if err != nil {
log.Errorln(err)
}
}
func (bot TipBot) inlineQueryReplyWithError(q *tb.Query, message string, help string) {
results := make(tb.Results, 1) // []tb.Result
result := &tb.ArticleResult{
// URL: url,
Text: help,
Title: message,
Description: help,
// required for photos
ThumbURL: queryImage,
}
id := fmt.Sprintf("inl-error-%d-%s", q.From.ID, RandStringRunes(5))
result.SetResultID(id)
results[0] = result
err := bot.telegram.Answer(q, &tb.QueryResponse{
Results: results,
CacheTime: 1, // 60 == 1 minute, todo: make higher than 1 s in production
})
if err != nil {
log.Errorln(err)
}
}
func (bot TipBot) anyChosenInlineHandler(q *tb.ChosenInlineResult) {
fmt.Printf(q.Query)
}
func (bot TipBot) anyQueryHandler(q *tb.Query) {
if q.Text == "" {
bot.inlineQueryInstructions(q)
return
}
// create the inline send result
if strings.HasPrefix(q.Text, "/") {
q.Text = strings.TrimPrefix(q.Text, "/")
}
if strings.HasPrefix(q.Text, "send") || strings.HasPrefix(q.Text, "pay") {
bot.handleInlineSendQuery(q)
}
if strings.HasPrefix(q.Text, "faucet") || strings.HasPrefix(q.Text, "giveaway") || strings.HasPrefix(q.Text, "zapfhahn") || strings.HasPrefix(q.Text, "kraan") {
bot.handleInlineFaucetQuery(q)
}
if strings.HasPrefix(q.Text, "receive") || strings.HasPrefix(q.Text, "get") || strings.HasPrefix(q.Text, "payme") || strings.HasPrefix(q.Text, "request") {
bot.handleInlineReceiveQuery(q)
}
}