From 74fdc5a9b14f9ae248133784d106da8cc18686fd Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 26 Jan 2019 21:24:20 +0100 Subject: tell-*: use jq and respect the channel --- reaktor/commands/tell-on_join | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'reaktor/commands/tell-on_join') diff --git a/reaktor/commands/tell-on_join b/reaktor/commands/tell-on_join index bb4982c..c21dc87 100755 --- a/reaktor/commands/tell-on_join +++ b/reaktor/commands/tell-on_join @@ -6,15 +6,20 @@ if test "${FLOCK-}" != "$state_file"; then exec env FLOCK="$state_file" flock "$state_file" "$0" "$@" fi -to="$_from" +# TODO tell now, if already joined +jq -r <"$state_file" \ + --arg to "$_from" \ + --arg msgtarget "$_msgtarget" \ + ' + select(.to == $to and .msgtarget == $msgtarget) | + "\(.to): \(.text) \u00032-- \(.from)\u00032 \(.date)" + ' -test -e "$state_file" || touch "$state_file" -# print messages -sed -n '/^'"$to"' /{ - s/^\([^ ]\+\) \([^ ]\+\) <\([^>]\+\)> \(.*\)/\1: \4 2-- \2, \3/p -}' "$state_file" +jq -c <"$state_file" >"$state_file.tmp" \ + --arg to "$_from" \ + --arg msgtarget "$_msgtarget" \ + ' + select((.to == $to and .msgtarget == $msgtarget) | not) + ' -# delete messages -sed -i '/^'"$to"' /{ - d -}' "$state_file" +mv "$state_file.tmp" "$state_file" -- cgit v1.2.3