From 2fb3de9cbe05651c62bb3fcfd2f8b07ecf61f1e0 Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Fri, 10 Sep 2021 08:00:36 +0200 Subject: [PATCH] Support status expiration dates --- README.md | 6 ++++++ src/slack | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e27d2ab..332140b 100644 --- a/README.md +++ b/README.md @@ -363,6 +363,12 @@ $ slack status edit --text lunch --emoji :hamburger: $ $ # Edit status via short form options: $ slack status edit --tx lunch -em :hamburger: +$ +$ # Clear status at 09:30 today: +$ slack status edit -e "$(date -d '09:30' '+%s')" --tx coffee -em :coffee: +$ +$ # Clear status after 5 minutes: +$ slack status edit -e +300 --tx "Back in 5" -em :clock1: ``` ## Contributors diff --git a/src/slack b/src/slack index e309d95..e4ff9c0 100755 --- a/src/slack +++ b/src/slack @@ -55,6 +55,7 @@ while (( "$#" )); do --comment*|-cm*) comment=${2} ; shift ; shift ;; --count=*) count=${1/--count=/''} ; shift ;; --count|-cn*) count=${2} ; shift ; shift ;; + --expire|-e) expire=${2} ; shift ; shift ;; --emoji=*) emoji=${1/--emoji=/''} ; shift ;; --emoji*|-em*) emoji=${2} ; shift ; shift ;; --fields=*) fields=${1/--fields=/''} ; shift ;; @@ -407,7 +408,7 @@ function help() { echo " ${bin} status clear" echo ' [--compact|-c] [--filter|-f ] [--monochrome|-m] [--trace|-x]' echo - echo " ${bin} status edit [ []]" + echo " ${bin} status edit [-e ] [ []]" echo ' [--compact|-c] [--filter|-f ] [--monochrome|-m] [--trace|-x]' echo echo 'Configuration Commands:' @@ -647,9 +648,13 @@ function statusclear() { } function statusedit() { + if [[ "$expire" =~ ^\+ ]]; then + expire="$(( $(date '+%s') + expire ))" + fi + local msg=$(\ curl -s -X POST https://slack.com/api/users.profile.set \ - --data-urlencode "profile={\"status_text\":\"${text}\", \"status_emoji\":\"${emoji}\"}" \ + --data-urlencode "profile={\"status_text\":\"${text}\",\"status_expiration\":\"${expire:-0}\",\"status_emoji\":\"${emoji}\"}" \ --data-urlencode "token=${token}") jqify "${msg}"