فهرست منبع

презенсы

kpmy 9 سال پیش
والد
کامیت
8a3792b11a
2فایلهای تغییر یافته به همراه32 افزوده شده و 1 حذف شده
  1. 19 0
      main.go
  2. 13 1
      misc.go

+ 19 - 0
main.go

@@ -4,6 +4,7 @@ import (
 	"flag"
 	"fmt"
 	"github.com/ivpusic/golog"
+	"reflect"
 	//	"github.com/skratchdot/open-golang/open"
 	"github.com/kpmy/xep/luaexecutor"
 	"github.com/kpmy/xep/muc"
@@ -150,6 +151,24 @@ func bot(st stream.Stream) error {
 						}
 					}
 				}
+			case dyn.Entity:
+				switch e.Type() {
+				case dyn.PRESENCE:
+					if from := e.Model().Attr("from"); from != "" && strings.HasPrefix(from, ROOM+"/") {
+						sender := strings.TrimPrefix(from, ROOM+"/")
+						um := muc.UserMapping()
+						user := sender
+						if u, ok := um[sender]; ok {
+							user, _ = u.(string)
+						}
+						if show := firstByName(e.Model(), "show"); e.Model().Attr("type") == "" && (show == nil || show.ChildrenCount() == 0) { //онлаен тип
+							//go func() { actors.With().Do(actors.C(doLuaAndPrint(`"` + user + `, насяльника..."`))).Run(st) }()
+							log.Println("ONLINE", user)
+						}
+					}
+				}
+			default:
+				log.Println(reflect.TypeOf(e))
 			}
 		}), 0)
 	}

+ 13 - 1
misc.go

@@ -4,7 +4,7 @@ import (
 	"bytes"
 	"github.com/kpmy/xippo/entity"
 	"github.com/kpmy/xippo/entity/dyn"
-	"github.com/kpmy/xippo/tools/dom"
+	"github.com/kpmy/ypk/dom"
 	"gopkg.in/xmlpath.v2"
 	"log"
 )
@@ -40,6 +40,8 @@ func conv(fn func(entity.Entity)) func(*bytes.Buffer) bool {
 						log.Println(err)
 					}
 				}
+			case dyn.PRESENCE:
+				fn(_e)
 			}
 		} else {
 			log.Println(err)
@@ -47,3 +49,13 @@ func conv(fn func(entity.Entity)) func(*bytes.Buffer) bool {
 		return
 	}
 }
+
+func firstByName(root dom.Element, name string) (ret dom.Element) {
+	for _, x := range root.Children() {
+		if e, ok := x.(dom.Element); ok && e.Name() == name {
+			ret = e
+			break
+		}
+	}
+	return
+}