X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=r3-netstatus%2Fmain.go;h=c6229ab3608afd404337049d34c70cdf7507b2cb;hb=988a91bab029af7738561b948f7f27023d5102b1;hp=ec65f06cdaeaf2f5dd895196995cf8ec08bfa325;hpb=31c937ec220968f64857c375008cc5376dcac701;p=svn42.git diff --git a/r3-netstatus/main.go b/r3-netstatus/main.go index ec65f06..c6229ab 100644 --- a/r3-netstatus/main.go +++ b/r3-netstatus/main.go @@ -22,6 +22,7 @@ var ( xmpp_login_ struct {jid string; pass string} xmpp_bot_authstring_ string xmpp_state_save_dir_ string + button_press_timeout_ int64 = 3600 ) //------- @@ -62,14 +63,27 @@ func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface }() var present, locked, shut bool = false, true, true + var last_buttonpress int64 = 0 var who string button_msg := "The button has been pressed ! Propably someone is bored and in need of company ! ;-)" - + button_status := r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowFreeForChat, "The button has been pressed :-)"} + + xmpp_presence_events_chan_ <- r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowNotAvailabe, "Nobody is here"} + for eventinterface := range(events) { switch event := eventinterface.(type) { case PresenceUpdate: present = event.Present xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: composeMessage(present, locked, shut, who, event.Ts), DistributeLevel: r3xmppbot.R3OnlineOnlyInfo, RememberAsStatus: true} + if present { + if time.Now().Unix() - last_buttonpress < button_press_timeout_ { + xmpp_presence_events_chan_ <- button_status + } else { + xmpp_presence_events_chan_ <- r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowOnline,"Somebody is present"} + } + } else { + xmpp_presence_events_chan_ <- r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowNotAvailabe,"Nobody is here"} + } case DoorCommandEvent: if len(event.Who) > 0 && len(event.Using) > 0 { who = fmt.Sprintf("%s (%s)",event.Who, event.Using) @@ -83,6 +97,8 @@ func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: composeMessage(present, locked, shut, who, event.Ts), DistributeLevel: r3xmppbot.R3DebugInfo, RememberAsStatus: true} case ButtonPressUpdate: xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: button_msg, DistributeLevel: r3xmppbot.R3OnlineOnlyInfo} + xmpp_presence_events_chan_ <- button_status + last_buttonpress = event.Ts } } }