This commit is contained in:
cx uname 2013-01-16 16:35:43 +04:00
parent d9fa80796a
commit ca0f779fc2
1 changed files with 6 additions and 14 deletions

20
main.go
View File

@ -17,7 +17,6 @@ const room = "ttyh@conference.jabber.ru"
const name = обe" const name = обe"
const me = "hypnotoad@xmpp.ru" const me = "hypnotoad@xmpp.ru"
// const room = "kkkkkkk2@conference.jabber.ru"
var ( var (
ping time.Time ping time.Time
admin []string admin []string
@ -44,19 +43,17 @@ start:
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
goto start goto start
} }
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):
//just in case
Conn.SendIQ("jabber.ru", "set", "<keepalive xmlns='urn:xmpp:keepalive:0'> <interval>60</interval> </keepalive>") 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 { if _, _, err = Conn.SendIQ("jabber.ru", "get", "<ping xmlns='urn:xmpp:ping'/>"); err != nil {
log.Println("KeepAlive err:", err) log.Println("KeepAlive err:", err)
return return
} }
ping = time.Now() ping = time.Now()
log.Println("KeepAlive is sent")
} }
} }
}(Conn) }(Conn)
@ -75,7 +72,6 @@ start:
for { for {
select { select {
case next = <-cs: case next = <-cs:
log.Println(next.Value)
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 goto start
@ -83,21 +79,15 @@ start:
switch t := next.Value.(type) { switch t := next.Value.(type) {
case *xmpp.ClientPresence: case *xmpp.ClientPresence:
PresenceHandler(Conn, t) PresenceHandler(Conn, t)
case *xmpp.ClientIQ:
if t.Type == "result" {
since := time.Since(ping)
log.Println(since, t.From)
}
case *xmpp.ClientMessage: case *xmpp.ClientMessage:
if len(t.Delay.Stamp) == 0 && len(t.Subject) == 0 && GetNick(t.From) != name { if len(t.Delay.Stamp) == 0 && len(t.Subject) == 0 && GetNick(t.From) != name {
log.Println(t)
if t.Type == "groupchat" { if t.Type == "groupchat" {
go MessageHandler(Conn, t) go MessageHandler(Conn, t)
} else if xmpp.RemoveResourceFromJid(strings.ToLower(t.From)) == me { } else if xmpp.RemoveResourceFromJid(strings.ToLower(t.From)) == me {
go SelfHandler(Conn, t) go SelfHandler(Conn, t)
} }
} }
default:
log.Println("da fuq?")
} }
} }
log.Println(Conn.Close(), "\n\t", "wtf am I doing here?") log.Println(Conn.Close(), "\n\t", "wtf am I doing here?")
@ -123,11 +113,13 @@ func MessageHandler(Conn *xmpp.Conn, Msg *xmpp.ClientMessage) {
} }
switch { switch {
case f("^\\!megakick", &Msg.Body): case f("^\\!megakick", &Msg.Body):
Strip(&Msg.Body, &Msg.From)
s := (strings.Split(Msg.Body, "!megakick ")) s := (strings.Split(Msg.Body, "!megakick "))
if in(admin, Msg.From) { if in(admin, Msg.From) {
Conn.ModUse(room, s[1], "none", "none") Conn.ModUse(room, s[1], "none", "")
} else {
Conn.Send(room, "groupchat", fmt.Sprintf("%s: GTFO", GetNick(Msg.From)))
} }
return
case f("^\\!", &Msg.Body): //any external command case f("^\\!", &Msg.Body): //any external command
Strip(&Msg.Body, &Msg.From) Strip(&Msg.Body, &Msg.From)
cmd := exec.Command("bash", "-c", GetCommand(Msg.Body, Msg.From, "./plugins/")) cmd := exec.Command("bash", "-c", GetCommand(Msg.Body, Msg.From, "./plugins/"))