forked from jshiffer/go-xmpp
fix query roster
process subscription="remove" roster improve roster process
This commit is contained in:
@@ -5,10 +5,11 @@ import (
|
||||
"crypto/tls"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/mattn/go-xmpp"
|
||||
"github.com/kjx98/go-xmpp"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var server = flag.String("server", "", "server")
|
||||
@@ -16,7 +17,7 @@ var username = flag.String("username", "", "username")
|
||||
var password = flag.String("password", "", "password")
|
||||
var status = flag.String("status", "xa", "status")
|
||||
var statusMessage = flag.String("status-msg", "I for one welcome our new codebot overlords.", "status message")
|
||||
var notls = flag.Bool("notls", false, "No TLS")
|
||||
var notls = flag.Bool("notls", true, "No TLS")
|
||||
var debug = flag.Bool("debug", false, "debug output")
|
||||
var session = flag.Bool("session", false, "use server session")
|
||||
|
||||
@@ -55,6 +56,7 @@ func main() {
|
||||
Debug: *debug,
|
||||
Session: *session,
|
||||
Status: *status,
|
||||
Resource: "bot",
|
||||
StatusMessage: *statusMessage,
|
||||
}
|
||||
|
||||
@@ -72,18 +74,52 @@ func main() {
|
||||
}
|
||||
switch v := chat.(type) {
|
||||
case xmpp.Chat:
|
||||
fmt.Println(v.Remote, v.Text)
|
||||
if v.Type == "roster" {
|
||||
fmt.Println("roster", v.Roster)
|
||||
} else {
|
||||
for _, element := range v.OtherElem {
|
||||
if element.XMLName.Space == "jabber:x:conference" {
|
||||
// if not join
|
||||
talk.JoinMUCNoHistory(v.Remote, "bot")
|
||||
}
|
||||
// composing, paused, active
|
||||
if element.XMLName.Space ==
|
||||
"http://jabber.org/protocol/chatstates" &&
|
||||
element.XMLName.Local == "composing" {
|
||||
fmt.Println(v.Remote, "is composing")
|
||||
}
|
||||
}
|
||||
if strings.TrimSpace(v.Text) != "" {
|
||||
fmt.Println(v.Remote, v.Text)
|
||||
}
|
||||
}
|
||||
case xmpp.Presence:
|
||||
fmt.Println(v.From, v.Show)
|
||||
fmt.Println("Presence:", v.From, v.Show, v.Type)
|
||||
case xmpp.Roster, xmpp.Contact:
|
||||
// TODO: update local roster
|
||||
fmt.Println("Roster/Contact:", v)
|
||||
case xmpp.IQ:
|
||||
// ping ignore
|
||||
if v.Type == "result" && v.ID == "c2s1" {
|
||||
fmt.Printf("Got pong from %s to %s\n", v.From, v.To)
|
||||
}
|
||||
default:
|
||||
fmt.Printf("def: %v\n", v)
|
||||
}
|
||||
}
|
||||
}()
|
||||
// get roster first
|
||||
talk.Roster()
|
||||
talk.SendOrg("<presence/>")
|
||||
for {
|
||||
in := bufio.NewReader(os.Stdin)
|
||||
line, err := in.ReadString('\n')
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if len(line) >= 4 && line[:4] == "quit" {
|
||||
break
|
||||
}
|
||||
line = strings.TrimRight(line, "\n")
|
||||
|
||||
tokens := strings.SplitN(line, " ", 2)
|
||||
@@ -91,4 +127,6 @@ func main() {
|
||||
talk.Send(xmpp.Chat{Remote: tokens[0], Type: "chat", Text: tokens[1]})
|
||||
}
|
||||
}
|
||||
talk.SendOrg("</stream:stream")
|
||||
time.Sleep(time.Second * 2)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user