aboutsummaryrefslogtreecommitdiffstats
path: root/reaktor/commands
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2019-01-26 21:24:20 +0100
committertv <tv@krebsco.de>2019-01-26 21:24:20 +0100
commit74fdc5a9b14f9ae248133784d106da8cc18686fd (patch)
tree78ce79a8b274cbd8b6e2a4c96dc3c81a4285a15d /reaktor/commands
parent3289e7af9f6d2e8b8537d582b6aa4e071ef046d6 (diff)
tell-*: use jq and respect the channelv0.7.0
Diffstat (limited to 'reaktor/commands')
-rwxr-xr-xreaktor/commands/tell-on_join25
-rwxr-xr-xreaktor/commands/tell-on_privmsg13
2 files changed, 22 insertions, 16 deletions
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"
diff --git a/reaktor/commands/tell-on_privmsg b/reaktor/commands/tell-on_privmsg
index 73163fa..9206d8c 100755
--- a/reaktor/commands/tell-on_privmsg
+++ b/reaktor/commands/tell-on_privmsg
@@ -6,12 +6,13 @@ if test "${FLOCK-}" != "$state_file"; then
exec env FLOCK="$state_file" flock "$state_file" "$0" "$@"
fi
-from="$_prefix"
-to=${1%% *}
-msg=${1#* }
-date=$(date)
-
# TODO tell now, if already joined
-printf '%s %s <%s> %s\n' "$to" "$from" "$date" "$msg" >> "$state_file"
+jq -cn \
+ --arg from "$_from" \
+ --arg to "${1%% *}" \
+ --arg text "${1##* }" \
+ --arg msgtarget "$_msgtarget" \
+ '{ $from, $to, $text, $msgtarget, date: (now | todate) }' \
+ >> "$state_file"
echo 'Consider it noted.' # that's what lambdabot says...