|
|
|
@ -142,6 +142,8 @@ func startClient(config *config) {
|
|
|
|
|
if err = client.Connect(); err != nil {
|
|
|
|
|
fmt.Sprintf("%sXMPP connection failed: %s", infoFormat, err)
|
|
|
|
|
fmt.Println("Failed to connect to server. Exiting...")
|
|
|
|
|
cm := xmpp.NewStreamManager(client, nil)
|
|
|
|
|
log.Fatal(cm.Run())
|
|
|
|
|
servConnFail := errors.New("failed to connect to server. Check your configuration ? Exiting")
|
|
|
|
|
errChan <- servConnFail
|
|
|
|
|
return
|
|
|
|
@ -189,10 +191,35 @@ func answerMessage(s xmpp.Sender, p stanza.Packet) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
_, _ = fmt.Fprintf(os.Stdout, "Body = %s - from = %s\n", msg.Body, msg.From)
|
|
|
|
|
keepMessage := msg.Body
|
|
|
|
|
fmt.Println("keep the message",keepMessage)
|
|
|
|
|
fmt.Println("keep the message", msg.Body)
|
|
|
|
|
answersArray := []string {"Test","Help","Time"}
|
|
|
|
|
|
|
|
|
|
switch {
|
|
|
|
|
case strings.Contains(strings.ToLower(msg.Body), "test") :
|
|
|
|
|
answer := "succesful test"
|
|
|
|
|
reply := stanza.Message{Attrs: stanza.Attrs{To: msg.From}, Body: answer}
|
|
|
|
|
fmt.Println("ANSEWERING.....")
|
|
|
|
|
s.Send(reply)
|
|
|
|
|
|
|
|
|
|
case strings.Contains(strings.ToLower(msg.Body), "help") :
|
|
|
|
|
answer := strings.Join(answersArray,", ")
|
|
|
|
|
reply := stanza.Message{Attrs: stanza.Attrs{To: msg.From}, Body: "here is the list of commands : " + answer}
|
|
|
|
|
s.Send(reply)
|
|
|
|
|
|
|
|
|
|
case strings.Contains(strings.ToLower(msg.Body), "time") :
|
|
|
|
|
answer := time.Now().String()
|
|
|
|
|
reply := stanza.Message{Attrs: stanza.Attrs{To: msg.From}, Body: answer}
|
|
|
|
|
s.Send(reply)
|
|
|
|
|
|
|
|
|
|
/*if strings.Contains(strings.ToLower(keepMessage), "help") {
|
|
|
|
|
testMessage := "test"
|
|
|
|
|
reply := stanza.Message{Attrs: stanza.Attrs{To: msg.From}, Body: testMessage}
|
|
|
|
|
s.Send(reply)
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
/*reply := stanza.Message{Attrs: stanza.Attrs{To: msg.From}, Body: msg.Body}
|
|
|
|
|
_ = s.Send(reply)*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -274,10 +301,6 @@ func gethdlNotif(APIKey string, APIEndPoint string ) string {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func readConfig() *config {
|
|
|
|
|
viper.SetConfigName(configFileName) // name of config file (without extension)
|
|
|
|
|
viper.BindPFlags(pflag.CommandLine)
|
|
|
|
|