56 lines
887 B
Go
56 lines
887 B
Go
package discord
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
var tagRagexp = regexp.MustCompile("<@([0-9]+)>")
|
|
|
|
func getTagBot(msg string) bool {
|
|
ids := tagRagexp.FindAllString(msg, -1)
|
|
if len(ids) == 0 {
|
|
return false
|
|
}
|
|
|
|
for _, id := range ids {
|
|
if id == client.ID {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func getCMD(str string) (cmd string, keyword bool) {
|
|
cmd = ""
|
|
keyword = false
|
|
charNumber := []rune(str)[0]
|
|
if charNumber == 33 || charNumber == 65218 {
|
|
keyword = true
|
|
if charNumber == 65218 {
|
|
cmd = str[3:]
|
|
} else {
|
|
cmd = str[1:]
|
|
}
|
|
} else {
|
|
cmd = str
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func parseTextMessage(msg string) (cmd string, keyword bool, payload string) {
|
|
tagBot := getTagBot(msg)
|
|
_ = tagBot
|
|
msg = strings.TrimSpace(tagRagexp.ReplaceAllString(msg, ""))
|
|
|
|
strs := strings.Split(msg, " ")
|
|
|
|
cmd, keyword = getCMD(strs[0])
|
|
|
|
payload = strings.Join(strs[1:], " ")
|
|
|
|
return
|
|
}
|