|
|
|
@ -198,7 +198,7 @@ func startClient(config *config) {
|
|
|
|
|
for {
|
|
|
|
|
select {
|
|
|
|
|
case <-timer.C:
|
|
|
|
|
fmt.Println("cheking notifs ...")
|
|
|
|
|
fmt.Println("checking notifs...")
|
|
|
|
|
notifications <- gethdlNotif(config.Hodlhodl[APIKey], config.Hodlhodl[APIEndPoint])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -212,32 +212,34 @@ func answerMessage(s xmpp.Sender, p stanza.Packet) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
_, _ = fmt.Fprintf(os.Stdout, "Body = %s - from = %s\n", msg.Body, msg.From)
|
|
|
|
|
fmt.Println("keep the message", msg.Body)
|
|
|
|
|
|
|
|
|
|
//answersArray := []string{"Test", "Help", "Time"}
|
|
|
|
|
if len(msg.Body) > 0 {
|
|
|
|
|
fmt.Println("keep the message", msg.Body)
|
|
|
|
|
receivedCmd := strings.Fields(msg.Body)[0]
|
|
|
|
|
args := strings.Fields(msg.Body)[1:]
|
|
|
|
|
fmt.Println("command is : ", receivedCmd)
|
|
|
|
|
fmt.Println("args are : ", args)
|
|
|
|
|
|
|
|
|
|
receivedCmd := strings.Fields(msg.Body)[0]
|
|
|
|
|
args := strings.Fields(msg.Body)[1:]
|
|
|
|
|
fmt.Println("command is : ", receivedCmd)
|
|
|
|
|
fmt.Println("args are : ", args)
|
|
|
|
|
// if command is handled
|
|
|
|
|
|
|
|
|
|
// if command is handled
|
|
|
|
|
// Commands is a dict of Commands=map[ string ]Command
|
|
|
|
|
// [ regCommandName ]regCommand
|
|
|
|
|
|
|
|
|
|
// Commands is a dict of Commands=map[ string ]Command
|
|
|
|
|
// [ regCommandName ]regCommand
|
|
|
|
|
for regCommandName, regCommand := range Commands {
|
|
|
|
|
|
|
|
|
|
for regCommandName, regCommand := range Commands {
|
|
|
|
|
var result string
|
|
|
|
|
if receivedCmd == "#" + regCommandName {
|
|
|
|
|
result = handleCommand(regCommand, args)
|
|
|
|
|
} /*else {
|
|
|
|
|
result = handleCommand(Commands["default"], args)
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
var result string
|
|
|
|
|
if receivedCmd == regCommandName {
|
|
|
|
|
result = handleCommand(regCommand, args)
|
|
|
|
|
} else {
|
|
|
|
|
result = handleCommand(Commands["default"], args)
|
|
|
|
|
reply := stanza.Message{Attrs: stanza.Attrs{To: msg.From}, Body: result}
|
|
|
|
|
s.Send(reply)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reply := stanza.Message{Attrs: stanza.Attrs{To: msg.From}, Body: result}
|
|
|
|
|
s.Send(reply)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//switch {
|
|
|
|
|
//case strings.Contains(strings.ToLower(msg.Body), "test"):
|
|
|
|
|
//answer := "succesful test"
|
|
|
|
@ -294,7 +296,7 @@ func hodlNotifications(client xmpp.Sender, config *config, notifications chan st
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func gethdlNotif(APIKey string, APIEndPoint string) string {
|
|
|
|
|
fmt.Println("get notif")
|
|
|
|
|
//fmt.Println("get notif")
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequest("POST", APIEndPoint+"/notifications/read", nil)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -324,7 +326,7 @@ func gethdlNotif(APIKey string, APIEndPoint string) string {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
fmt.Println("no notif empty string")
|
|
|
|
|
//fmt.Println("no notif empty string")
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|