quick fix bug

Former-commit-id: 254861b97deafa875745337149291285056d9f30
botanswer
AnisB 3 years ago
parent 82a5f2c2cb
commit d99e4858f7

@ -5,22 +5,22 @@
package main
import (
"fmt"
"log"
"os"
"flag"
"net/http"
"io/ioutil"
"encoding/json"
"encoding/xml"
"errors"
"gosrc.io/xmpp"
"gosrc.io/xmpp/stanza"
"flag"
"fmt"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"strings"
"strconv"
"gosrc.io/xmpp"
"gosrc.io/xmpp/stanza"
"io/ioutil"
"log"
"net/http"
"os"
"path"
"encoding/xml"
"strconv"
"strings"
"time"
)
@ -72,17 +72,14 @@ type Notification struct {
type config struct {
Server map[string]string `mapstructure:"server"`
Client map[string]string `mapstructure:"client"`
Contacts string `string:"contact"`
Recipient string `string:"recipient"`
Hodlhodl map[string]string `mapstructure:"hodlhodl"`
LogStanzas map[string]string `mapstructure:"logstanzas"`
}
func main() {
//body:= strings.NewReader(' -X POST -H "Authorization: Bearer ***REMOVED***" -H "Content-Type: application/json"`)
// ============================================================
// Parse the flag with the config directory path as argument
flag.String("c", defaultConfigFilePath, "Provide a path to the directory that contains the configuration"+
@ -124,7 +121,6 @@ func startClient(config *config) {
Insecure: true,
}
var err error
var client *xmpp.Client
router := xmpp.NewRouter()
@ -160,12 +156,11 @@ func startClient(config *config) {
/*cm := xmpp.NewStreamManager(client, nil)
log.Fatal(cm.Run())*/
// ====================
// Start working
// fmt.Println("CONFIG.HODLHDOL :", config.Hodlhodl[APIKey])
timer := time.NewTicker(5 * time.Second)
timer := time.NewTicker(JobSchedulerInterval)
notifications := make(chan string, 100)
go startMessaging(client, config, notifications)
@ -178,30 +173,27 @@ func startClient(config *config) {
}
}
}
func startMessaging(client xmpp.Sender, config *config, notifications chan string) {
fmt.Println("START MESSAGING")
currentContact := strings.Split(config.Contacts, configContactSep)[1]
fmt.Println(infoFormat+"Now sending messages to "+currentContact+" in a private conversation\n")
fmt.Println("currentContacts", currentContact)
recipient := config.Recipient
fmt.Println(infoFormat + "Now sending messages to " + recipient + " in a private conversation\n")
fmt.Println("currentContacts", recipient)
for {
select {
case notif := <-notifications:
// Test if notif is nil or skip this loop
if notif == "" { break ;}
if notif == "" {
break
}
fmt.Println("sending notification through xmpp")
reply := stanza.Message{Attrs: stanza.Attrs{To: currentContact, Type: stanza.MessageTypeChat}, Body: notif}
reply := stanza.Message{Attrs: stanza.Attrs{To: recipient, Type: stanza.MessageTypeChat}, Body: notif}
if logger != nil {
raw, _ := xml.Marshal(reply)
logger.Println(string(raw))
@ -244,7 +236,7 @@ func gethdlNotif(APIKey string, APIEndPoint string ) string {
//fmt.Println("RESULT body", res.Notifications[0].Body)
//fmt.Println("res: ", res)
//fmt.Println("res.Notifications: ", res.Notifications)
if (len(res.Notifications) > 0) {
if len(res.Notifications) > 0 {
//fmt.Println("type of notif = ", reflect.TypeOf(res.Notifications[0]))
fmt.Println("Join: ", strings.Join([]string{res.Notifications[0].Title, res.Notifications[0].Body}, " "))
//fmt.Println("RESULT stirng(body)", string(body))
@ -260,11 +252,6 @@ func gethdlNotif(APIKey string, APIEndPoint string ) string {
return ""
}
func readConfig() *config {
viper.SetConfigName(configFileName) // name of config file (without extension)
viper.BindPFlags(pflag.CommandLine)
@ -286,7 +273,7 @@ func readConfig() *config {
}
// Check if we have contacts to message
if len(strings.TrimSpace(config.Contacts)) == 0 {
if len(strings.TrimSpace(config.Recipient)) == 0 {
log.Panicln("You appear to have no contacts to message !")
}
// Check logging
@ -307,7 +294,6 @@ func errorHandler(err error) {
killChan <- err
}
func isDirectory(path string) (bool, error) {
fileInfo, err := os.Stat(path)
if err != nil {
@ -315,4 +301,3 @@ func isDirectory(path string) (bool, error) {
}
return fileInfo.IsDir(), err
}

Loading…
Cancel
Save