added input sanitization
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/xmppo/go-xmpp"
|
||||
"gopkg.in/ini.v1"
|
||||
@@ -71,19 +72,30 @@ func (nkbot *NekoUKrovuBot) Listen() {
|
||||
}
|
||||
|
||||
func (nkbot *NekoUKrovuBot) handleChat(ch *xmpp.Chat) {
|
||||
src := ch.Remote
|
||||
txt := ch.Text
|
||||
|
||||
if src == "sdsads" {
|
||||
if !nkbot.sanitizeInput(txt) {
|
||||
return
|
||||
}
|
||||
|
||||
if nkbot.checkForJelNekoUKrovu(txt) {
|
||||
n := ping.Run()
|
||||
n := ping.PingLocal255()
|
||||
nkbot.answer(fmt.Sprintf("%v uredjaja povezano", n))
|
||||
}
|
||||
}
|
||||
|
||||
func (nkbot *NekoUKrovuBot) sanitizeInput(input string) bool {
|
||||
if len(input) > 50 {
|
||||
return false
|
||||
}
|
||||
|
||||
if !utf8.ValidString(input) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (nkbot *NekoUKrovuBot) checkForJelNekoUKrovu(txt string) bool {
|
||||
normalizedText := strings.ToLower(txt)
|
||||
|
||||
@@ -99,10 +111,10 @@ func (nkbot *NekoUKrovuBot) checkForJelNekoUKrovu(txt string) bool {
|
||||
|
||||
func (nkbot *NekoUKrovuBot) answer(ans string) {
|
||||
chat := xmpp.Chat{
|
||||
Remote: "chatbottest@conference.dmz.rs",
|
||||
Type: "groupchat",
|
||||
Text: ans,
|
||||
Stamp: time.Now(),
|
||||
Remote: "chatbottest@conference.dmz.rs",
|
||||
Type: "groupchat",
|
||||
Text: ans,
|
||||
Stamp: time.Now(),
|
||||
}
|
||||
|
||||
n, err := nkbot.cl.Send(chat)
|
||||
|
Reference in New Issue
Block a user