-
Notifications
You must be signed in to change notification settings - Fork 0
/
Incoming.go
79 lines (65 loc) · 1.54 KB
/
Incoming.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
package lib
import (
"strings"
"github.com/jh-bate/fantail-bot/Godeps/_workspace/src/github.com/tucnak/telebot"
)
type Incoming struct {
msg telebot.Message
action Action
}
func newIncoming(msg telebot.Message) *Incoming {
return &Incoming{msg: msg}
}
func (this Incoming) hasSubmisson() bool {
//eg /say some stuff
return this.isCmd() && len(strings.Fields(this.msg.Text)) > 1
}
func (this Incoming) getAction(s *session, prevActionName string) Action {
return NewAction(s, prevActionName)
}
func (this Incoming) createNote(tags ...string) *Note {
return NewNote(this.msg, tags...)
}
func (this Incoming) isSticker() bool {
return this.msg.Sticker.Exists()
}
func (this Incoming) sender() telebot.User {
return this.msg.Sender
}
func (this Incoming) getCmd() string {
if this.isCmd() {
if strings.Contains(this.msg.Text, "/") {
theCmd := strings.Fields(this.msg.Text)[0]
//lowercase it
return strings.ToLower(theCmd)
}
}
return ""
}
func (this Incoming) cmdMatches(cmds ...string) bool {
if this.isCmd() {
for i := range cmds {
if strings.EqualFold(cmds[i], this.getCmd()) {
return true
}
}
}
return false
}
func (this Incoming) submissonMatches(cmds ...string) bool {
if this.hasSubmisson() {
for i := range cmds {
if strings.EqualFold(cmds[i], this.getCmd()) {
return true
}
}
}
return false
}
func (this Incoming) isCmd() bool {
//eg /cmd
if this.msg.Text != "" && strings.Contains(this.msg.Text, "/") {
return strings.Contains(strings.Fields(this.msg.Text)[0], "/")
}
return false
}