Example #1
0
func main() {
	Conn, err := xmpp.Dial("xmpp.ru:5222", "hypnotoad", "xmpp.ru", "password", "gsend", nil)
	if err != nil {
		println(err)
		return
	}

	if s, err := ioutil.ReadAll(os.Stdin); err == nil {
		Conn.Send("*****@*****.**", "chat", string(s[:len(s)-1]))
		return
	}
}
Example #2
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
start:
	Conn, err := xmpp.Dial("xmpp.ru:5222", "hypnotoad", "xmpp.ru", "pass", "AllHailHypnotoad", nil)
	if err != nil {
		log.Println("Conn", err)
		time.Sleep(5 * time.Second)
		goto start
	}
	if err := Conn.SignalPresence("dnd", "is there some food in this world?", 12); err != nil {
		log.Println("Signal", err)
		time.Sleep(5 * time.Second)
		goto start
	}
	if err := Conn.SendPresence(room+"/"+name, ""); err != nil {
		log.Println("Presence", err)
		time.Sleep(5 * time.Second)
		goto start
	}

	go func(Conn *xmpp.Conn) {
		for {
			select {
			case <-time.After(60 * time.Second):
				Conn.SendIQ("jabber.ru", "set", "<keepalive xmlns='urn:xmpp:keepalive:0'> <interval>60</interval> </keepalive>")
				if _, _, err = Conn.SendIQ("jabber.ru", "get", "<ping xmlns='urn:xmpp:ping'/>"); err != nil {
					log.Println("KeepAlive err:", err)
					return
				}
				ping = time.Now()
			}
		}
	}(Conn)

	go func(Conn *xmpp.Conn) {
		for {
			next, err := Conn.Next()
			if err != nil {
				log.Println("Next err:", err)
				return
			}
			cs <- next
		}
	}(Conn)

	for {
		select {
		case next = <-cs:
		case <-time.After(65 * time.Second):
			log.Println(Conn.Close(), "\n\t", "closed after 65 seconds of inactivity")
			goto start
		}
		switch t := next.Value.(type) {
		case *xmpp.ClientPresence:
			PresenceHandler(Conn, t)
		case *xmpp.ClientMessage:
			if len(t.Delay.Stamp) == 0 && len(t.Subject) == 0 {
				log.Println(t)
				if GetNick(t.From) != name {
					if t.Type == "groupchat" {
						go MessageHandler(Conn, t)
					} else if xmpp.RemoveResourceFromJid(strings.ToLower(t.From)) == me {
						go SelfHandler(Conn, t)
					}
				}
			}
		}
	}
	log.Println(Conn.Close(), "\n\t", "wtf am I doing here?")
	time.Sleep(5 * time.Second)
	goto start
}