bot account in config + switch case answers

Former-commit-id: 26b37c3c11c66e8fc5be42a2871bffa3906b218b
botanswer
AnisB 3 years ago
parent 9aac073eb1
commit c241063191

@ -2,7 +2,7 @@
Server :
- full_address: "xmpp.sp4ke.xyz"
Client :
- jid: "vicious@xmpp.sp4ke.xyz"
- jid: "bot@xmpp.sp4ke.xyz"
- pass: "***REMOVED***" #Password in a config file yay
Contacts : "chakib@xmpp.sp4ke.xyz;vicious@xmpp.sp4ke.xyz"

@ -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)

Loading…
Cancel
Save