5 pubsub "github.com/tuxychandru/pubsub"
12 type SpaceState struct {
14 buttonpress_until int64
20 presence_socket_path_ string
21 xmpp_presence_events_chan_ chan interface{}
22 xmpp_login_ struct {jid string; pass string}
23 xmpp_bot_authstring_ string
24 xmpp_state_save_dir_ string
30 flag.StringVar(&xmpp_login_.jid, "xjid", "realrauminfo@realraum.at/Tuer", "XMPP Bot Login JID")
31 flag.StringVar(&xmpp_login_.pass, "xpass", "", "XMPP Bot Login Password")
32 flag.StringVar(&xmpp_bot_authstring_, "xbotauth", "", "String that user use to authenticate themselves to the bot")
33 flag.StringVar(&presence_socket_path_,"presencesocket", "/var/run/tuer/presence.socket", "Path to presence socket")
34 flag.StringVar(&xmpp_state_save_dir_,"xstatedir","/flash/var/lib/r3netstatus/", "Directory to save XMPP bot state in")
40 func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface{}) {
41 events := ps.Sub("presence","door","buttons")
42 var present, locked, shut bool = false, true, true
43 var who string = "Unknown"
45 for eventinterface := range(events) {
46 switch event := eventinterface.(type) {
48 present = event.Present
49 xmpp_presence_events_chan_ <- r3xmppbot.XMPPPresenceEvent{Present: present, Who: who, DoorLock: locked, DoorShut: shut, Ts: event.Ts}
50 case DoorCommandEvent:
52 xmpp_presence_events_chan_ <- fmt.Sprintln("DoorCommand:",event.Command, "using", event.Using, "by", event.Who, time.Unix(event.Ts,0))
53 case DoorStatusUpdate:
56 xmpp_presence_events_chan_ <- fmt.Sprintln("DoorStatus:",r3xmppbot.IfThenElseStr(event.Locked, "locked","unlocked"), r3xmppbot.IfThenElseStr(event.Shut, "shut","ajar"), time.Unix(event.Ts,0))
57 case ButtonPressUpdate:
58 xmpp_presence_events_chan_ <- r3xmppbot.XMPPPresenceEvent{Present: present, Who: who, DoorLock: locked, DoorShut: shut, Button: true, Ts: event.Ts}
65 var bot *r3xmppbot.XmppBot
66 bot, xmpp_presence_events_chan_, err = r3xmppbot.NewStartedBot(xmpp_login_.jid, xmpp_login_.pass, xmpp_bot_authstring_, xmpp_state_save_dir_, true)
73 newlinequeue := make(chan string, 1)
75 //~ brn := brain.New()
76 defer close(newlinequeue)
78 //~ defer brn.Shutdown()
80 ticker := time.NewTicker(time.Duration(7) * time.Minute)
82 go EventToXMPP(ps, xmpp_presence_events_chan_)
83 go ReadFromUSocket(presence_socket_path_, newlinequeue)
86 case e := <-newlinequeue:
87 ParseSocketInputLine(e, ps) //, brn)
89 ps.Pub(TimeTick{time.Now().Unix()}, "publishjson")