From 26e173994cd67eb9d01f0501244a8786148dadcf Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Fri, 6 Sep 2013 12:05:40 +0000 Subject: [PATCH] command regex and who --- r3-netstatus/main.go | 6 +++--- r3-netstatus/sockettoevent.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/r3-netstatus/main.go b/r3-netstatus/main.go index 81411f0..7016404 100644 --- a/r3-netstatus/main.go +++ b/r3-netstatus/main.go @@ -42,18 +42,18 @@ func IfThenElseStr(c bool, strue, sfalse string) string { } 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) { diff --git a/r3-netstatus/sockettoevent.go b/r3-netstatus/sockettoevent.go index f356482..e131973 100644 --- a/r3-netstatus/sockettoevent.go +++ b/r3-netstatus/sockettoevent.go @@ -13,7 +13,7 @@ import ( 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+)") -- 1.7.10.4