}
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(who == "","", " 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) {
var (
re_presence_ *regexp.Regexp = regexp.MustCompile("Presence: (yes|no)(?:, (opened|closed), (.+))?")
re_status_ *regexp.Regexp = regexp.MustCompile("Status: (closed|opened), (opening|waiting|closing|idle), (ajar|shut).*")
- re_command_ *regexp.Regexp = regexp.MustCompile("(open|close|toggle) (?:(Card|Phone|SSH|ssh) )?(.+)")
+ re_command_ *regexp.Regexp = regexp.MustCompile("(open|close|toggle)(?:/s+(Card|Phone|SSH|ssh))?(?:/s+(.+))?")
re_button_ *regexp.Regexp = regexp.MustCompile("PanicButton|button\\d?")
re_temp_ *regexp.Regexp = regexp.MustCompile("temp0: (\\d+\\.\\d+)")
re_photo_ *regexp.Regexp = regexp.MustCompile("photo0: (\\d+)")