botanswer
AnisB 4 years ago
parent 2159f673e0
commit f1050fd77f

@ -105,9 +105,6 @@ func main() {
defer f.Close()
}
// ==========================
// Run TUI
//================================
startClient(c)
}
@ -129,18 +126,6 @@ func startClient(config *config) {
var client *xmpp.Client
router := xmpp.NewRouter()
handleMessage := func(s xmpp.Sender, p stanza.Packet) {
msg, ok := p.(stanza.Message)
if !ok {
_, _ = fmt.Fprintf(os.Stdout, "Ignoring packet: %T\n", p)
return
}
_, _ = fmt.Fprintf(os.Stdout, "Body = %s - from = %s\n", msg.Body, msg.From)
reply := stanza.Message{Attrs: stanza.Attrs{To: msg.From}, Body: msg.Body}
_ = s.Send(reply)
}
errorHandler:= func(err error) {
fmt.Println(err.Error())
}
@ -176,10 +161,10 @@ func startClient(config *config) {
// ====================
// Start working
currentContacts := strings.Split(config.Contacts, configContactSep)[0]
fmt.Println(infoFormat+"Now sending messages to "+currentContacts+" in a private conversation\n")
CorrespChan <- currentContacts
fmt.Println("currentContacts", currentContacts)
currentContact := strings.Split(config.Contacts, configContactSep)[0]
fmt.Println(infoFormat+"Now sending messages to "+currentContact+" in a private conversation\n")
CorrespChan <- currentContact
fmt.Println("currentContacts", currentContact)
startMessaging(client, config)
}
@ -187,6 +172,7 @@ func startClient(config *config) {
func startMessaging(client xmpp.Sender, config *config) {
fmt.Println("START MESSAGING")
var text string
var correspondent string
for {
@ -200,6 +186,7 @@ func startMessaging(client xmpp.Sender, config *config) {
}
return
case text = <-textChan:
fmt.Println("TEST 1")
reply := stanza.Message{Attrs: stanza.Attrs{To: correspondent, Type: stanza.MessageTypeChat}, Body: text}
if logger != nil {
raw, _ := xml.Marshal(reply)
@ -211,6 +198,7 @@ func startMessaging(client xmpp.Sender, config *config) {
return
}
case text = <-rawTextChan:
fmt.Println("TEST 2")
if logger != nil {
logger.Println(text)
}
@ -220,7 +208,18 @@ func startMessaging(client xmpp.Sender, config *config) {
return
}
case crrsp := <-CorrespChan:
fmt.Println("TEST 3")
correspondent = crrsp
reply := stanza.Message{Attrs: stanza.Attrs{To: correspondent, Type: stanza.MessageTypeChat}, Body: text}
if logger != nil {
raw, _ := xml.Marshal(reply)
logger.Println(string(raw))
}
err := client.Send(reply)
if err != nil {
fmt.Printf("There was a problem sending the message : %v", reply)
return
}
case <-rosterChan:
fmt.Println("rosterchan")
}

Loading…
Cancel
Save