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