X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=r3-netstatus%2Fmain.go;h=81411f03c81be44a790c98e99933f9d31dae964f;hb=cbba478c4eca3c3bf534492adb8ef889e2289dd7;hp=3e6290a283790ac7325c4dc8f58d4b09744f3545;hpb=cd7b30c04615b0ac24fd70703362698e65aea927;p=svn42.git diff --git a/r3-netstatus/main.go b/r3-netstatus/main.go index 3e6290a..81411f0 100644 --- a/r3-netstatus/main.go +++ b/r3-netstatus/main.go @@ -37,25 +37,39 @@ func init() { //------- +func IfThenElseStr(c bool, strue, sfalse string) string { + if c {return strue} else {return sfalse} +} + +func composeMessage(present, locked, shut bool, who string, ts int64) string { + return fmt.Sprintf("%s (Door is %s and %s and was last used by %s at %s)", + IfThenElseStr(present, "Somebody is present!" , "Everybody left."), + IfThenElseStr(locked, "locked","unlocked"), + IfThenElseStr(shut, "shut","ajar"), + who, + time.Unix(ts,0).String()) +} + func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface{}) { events := ps.Sub("presence","door","buttons") var present, locked, shut bool = false, true, true var who string = "Unknown" + button_msg := "The button has been pressed ! Propably someone is bored and in need of company ! ;-)" for eventinterface := range(events) { switch event := eventinterface.(type) { case PresenceUpdate: present = event.Present - xmpp_presence_events_chan_ <- r3xmppbot.XMPPPresenceEvent{Present: present, Who: who, DoorLock: locked, DoorShut: shut, Ts: event.Ts} + xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: composeMessage(present, locked, shut, who, event.Ts), DistributeLevel: r3xmppbot.R3OnlineOnlyInfo, RememberAsStatus: true} case DoorCommandEvent: who = event.Who xmpp_presence_events_chan_ <- fmt.Sprintln("DoorCommand:",event.Command, "using", event.Using, "by", event.Who, time.Unix(event.Ts,0)) case DoorStatusUpdate: locked = event.Locked shut = event.Shut - xmpp_presence_events_chan_ <- r3xmppbot.XMPPPresenceEvent{Present: present, Who: who, DoorLock: locked, DoorShut: shut, Ts: event.Ts} + 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.XMPPPresenceEvent{Present: present, Who: who, DoorLock: locked, DoorShut: shut, Button: true, Ts: event.Ts} + xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: button_msg, DistributeLevel: r3xmppbot.R3OnlineOnlyInfo} } } }