-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtgbot-private.go
57 lines (52 loc) · 1.31 KB
/
tgbot-private.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
package tgbot
import (
"fmt"
"strings"
)
func (bot TgBot) addUsernameCommand(expr string) string {
strs := strings.Split(expr, " ")
opts := fmt.Sprintf(`(?:@%s)?`, bot.Username)
if len(strs) == 1 {
capt := strs[0]
lastc := capt[len(capt)-1]
if lastc == '$' {
strs[0] = capt[:len(capt)-1] + opts + "$"
} else {
strs[0] = strs[0] + opts
}
} else {
strs[0] = strs[0] + opts
}
newexpr := strings.Join(strs, " ")
return newexpr
}
func (bot *TgBot) addToConditionalFuncs(cf ConditionCallStructure) {
if !bot.BuildingChain {
bot.TestConditionalFuncs = append(bot.TestConditionalFuncs, cf)
} else {
if len(bot.ChainConditionals) > 0 {
bot.ChainConditionals[len(bot.ChainConditionals)-1].AddToConditionalFuncs(cf)
}
}
}
func (bot TgBot) cleanMessage(msg Message) Message {
if msg.Text != nil {
if bot.DefaultOptions.CleanInitialUsername {
text := *msg.Text
username := fmt.Sprintf("@%s", bot.Username)
if strings.HasPrefix(text, username) {
text = strings.TrimSpace(strings.Replace(text, username, "", 1)) // Replace one time
if bot.DefaultOptions.AllowWithoutSlashInMention &&
!strings.HasSuffix(text, "/") {
text = "/" + text
}
msg.Text = &text
}
}
if bot.DefaultOptions.LowerText {
text := strings.ToLower(*msg.Text)
msg.Text = &text
}
}
return msg
}