This commit is contained in:
Alexey Derlaft 2015-08-13 17:45:40 +03:00
parent 6aedddfdf4
commit 7c9c5ff2eb
1 changed files with 69 additions and 62 deletions

33
main.go
View File

@ -2,7 +2,7 @@ package main
import (
"fmt"
"github.com/cxindex/xmpp"
"github.com/derlaft/xmpp"
"io/ioutil"
"log"
"os/exec"
@ -13,9 +13,16 @@ import (
"time"
)
const room = "ttyh@conference.jabber.ru"
const name = обe"
const me = "hypnotoad@xmpp.ru"
const (
room = "room@conference.example.com"
name = "botname"
server = "example.com"
me = name + "@" + server
id = name
password = "password"
resource = "resource"
connect = "xmpp.example.com:5222"
)
var (
ping time.Time
@ -30,33 +37,33 @@ func main() {
Conn *xmpp.Conn
err error
)
start:
for {
if Conn != nil {
time.Sleep(5 * time.Second)
log.Println("Conn check:", Conn.Close())
time.Sleep(5 * time.Second)
}
Conn, err = xmpp.Dial("xmpp.ru:5222", "hypnotoad", "xmpp.ru", "pass", "AllHailHypnotoad", nil)
Conn, err = xmpp.Dial(connect, id, server, password, resource, &xmpp.Config{SkipTLS: true})
if err != nil {
log.Println("Conn", err)
goto start
continue
}
if err := Conn.SignalPresence("dnd", "is there some food in this world?", 12); err != nil {
log.Println("Signal", err)
goto start
continue
}
if err := Conn.SendPresence(room+"/"+name, ""); err != nil {
log.Println("Presence", err)
goto start
continue
}
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 {
Conn.SendIQ(server, "set", "<keepalive xmlns='urn:xmpp:keepalive:0'> <interval>60</interval> </keepalive>")
if _, _, err = Conn.SendIQ(server, "get", "<ping xmlns='urn:xmpp:ping'/>"); err != nil {
log.Println("KeepAlive err:", err)
return
}
@ -81,7 +88,7 @@ start:
case next = <-cs:
case <-time.After(65 * time.Second):
log.Println(Conn.Close(), "\n\t", "closed after 65 seconds of inactivity")
goto start
break
}
switch t := next.Value.(type) {
case *xmpp.ClientPresence:
@ -100,7 +107,7 @@ start:
}
}
log.Println(Conn.Close(), "\n\t", "wtf am I doing here?")
goto start
}
}
func SelfHandler(Conn *xmpp.Conn, Msg *xmpp.ClientMessage) {