}
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)",
+ return fmt.Sprintf("%s (Door is %s and %s and was last used%s at %s)",
IfThenElseStr(present, "Somebody is present!" , "Everybody left."),
IfThenElseStr(locked, "locked","unlocked"),
IfThenElseStr(shut, "shut","ajar"),
- who,
+ IfThenElseStr(len(who) == 0,"", " by " + 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"
+ var who string
button_msg := "The button has been pressed ! Propably someone is bored and in need of company ! ;-)"
for eventinterface := range(events) {
present = event.Present
xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: composeMessage(present, locked, shut, who, event.Ts), DistributeLevel: r3xmppbot.R3OnlineOnlyInfo, RememberAsStatus: true}
case DoorCommandEvent:
- who = event.Who
+ if len(event.Who) > 0 && len(event.Using) > 0 {
+ who = fmt.Sprintf("%s (%s)",event.Who, event.Using)
+ } else {
+ 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