From 3775c11abf91328d862c49e47921e421b960003c Mon Sep 17 00:00:00 2001 From: root Date: Sat, 21 Nov 2020 09:38:44 +0000 Subject: [PATCH 1/5] channel name and id --- modules/message.sh | 91 ++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/modules/message.sh b/modules/message.sh index 8309149cd..24fcd6e3c 100644 --- a/modules/message.sh +++ b/modules/message.sh @@ -216,6 +216,31 @@ function message { esac ;; slack) + function check_channel { + channel_list=$(curl -s -F token=$access_token https://slack.com/api/conversations.list) + channel_list=($(echo $channel_list | python -m json.tool | jq '.channels[].id' | tr -d '"')) + for i in "${channel_list[@]}"; do + if [ $i == $1 ]; then + return 0 + break + fi + done + return 1 + } + function channel_get { + name="$1" + count=0 + conversation_list=$(curl -s -F token=$access_token https://slack.com/api/conversations.list) + channel_name=($(echo $conversation_list | python -m json.tool | jq '.channels[].name' | tr -d '"')) + for i in "${channel_name[@]}"; do + if [[ $name == $i ]]; then + channel_id=$(echo $conversation_list | python -m json.tool | jq '.channels['$count'].id' | tr -d '"') + echo $channel_id + break + fi + ((count=count+1)) + done + } case "$2" in apitoken) if [[ $3 != "" ]]; then @@ -250,8 +275,10 @@ function message { send) channel=$3 if check_apitoken slack; then - if [[ $3 == "" ]]; then - log_comment_and_exit1 "ERROR: Group information is missing" "usage: $BASENAME message slack send " + if [[ $channel == "" ]]; then + log_comment_and_exit1 "ERROR: Channel information is missing" "usage: $BASENAME message slack send " + elif [[ "${channel:0:1}" == [a-z] ]]; then + channel=$(channel_get $3) fi shift; shift; shift; message=$* @@ -268,22 +295,14 @@ function message { ;; show) channel=$3 - function check_channel { - channel_list=$(curl -s -F token=$access_token https://slack.com/api/conversations.list) - channel_list=($(echo $channel_list | python -m json.tool | jq '.channels[].id' | tr -d '"')) - for i in "${channel_list[@]}"; do - if [ $i == $1 ]; then - return 0 - break - fi - done - return 1 - } if check_apitoken slack; then if [[ $channel == "" ]]; then - log_comment_and_exit1 "ERROR: Group information is missing" "usage: $BASENAME message slack read " - elif ! check_channel $channel; then - log_and_exit1 "invalid channel ID" + log_comment_and_exit1 "ERROR: Channel information is missing" "usage: $BASENAME message slack read " + elif [[ "${channel:0:1}" == [a-z] ]]; then + channel=$(channel_get $3) + fi + if ! check_channel $channel; then + log_and_exit1 "invalid channel ID or channel name" else channel_info=$(curl -s -F token=$access_token -F channel=$channel https://slack.com/api/conversations.info) last_read=$(echo $channel_info | python -m json.tool | jq '.channel.last_read' | tr -d '"') @@ -322,22 +341,14 @@ function message { ;; read) channel=$3 - function check_channel { - channel_list=$(curl -s -F token=$access_token https://slack.com/api/conversations.list) - channel_list=($(echo $channel_list | python -m json.tool | jq '.channels[].id' | tr -d '"')) - for i in "${channel_list[@]}"; do - if [ $i == $1 ]; then - return 0 - break - fi - done - return 1 - } if check_apitoken slack; then if [[ $channel == "" ]]; then - log_comment_and_exit1 "ERROR: Group information is missing" "usage: $BASENAME message slack read " - elif ! check_channel $channel; then - log_and_exit1 "invalid channel ID" + log_comment_and_exit1 "ERROR: Channel information is missing" "usage: $BASENAME message slack read " + elif [[ "${channel:0:1}" == [a-z] ]]; then + channel=$(channel_get $3) + fi + if ! check_channel $channel; then + log_and_exit1 "invalid channel ID or channel name" else channel_info=$(curl -s -F token=$access_token -F channel=$channel https://slack.com/api/conversations.info) last_read=$(echo $channel_info | python -m json.tool | jq '.channel.last_read' | tr -d '"') @@ -378,22 +389,14 @@ function message { ;; mark) channel=$3 - function check_channel { - channelList=$(curl -s -F token=$access_token https://slack.com/api/conversations.list) - channelList=($(echo $channelList | python -m json.tool | jq '.channels[].id' | tr -d '"')) - for i in "${channelList[@]}"; do - if [ $i == $1 ]; then - return 0 - break - fi - done - return 1 - } if check_apitoken slack; then if [[ $channel == "" ]]; then - log_comment_and_exit1 "ERROR: Group information is missing" "usage: $BASENAME message slack read " - elif ! check_channel $channel; then - log_and_exit1 "invalid channel ID" + log_comment_and_exit1 "ERROR: Channel information is missing" "usage: $BASENAME message slack read " + elif [[ "${channel:0:1}" == [a-z] ]]; then + channel=$(channel_get $3) + fi + if ! check_channel $channel; then + log_and_exit1 "invalid channel ID or channel name" else channel_info=$(curl -s -F token=$access_token -F channel=$channel https://slack.com/api/conversations.info) last_read=$(echo $channel_info | python -m json.tool | jq '.channel.last_read' | tr -d '"') From ef3cd86c1e3995f4b8db479de752f0949d14dd42 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 21 Nov 2020 09:51:18 +0000 Subject: [PATCH 2/5] chnages updated --- modules/message.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/message.sh b/modules/message.sh index 24fcd6e3c..91a71cec0 100644 --- a/modules/message.sh +++ b/modules/message.sh @@ -216,7 +216,7 @@ function message { esac ;; slack) - function check_channel { + function get_channel_id { channel_list=$(curl -s -F token=$access_token https://slack.com/api/conversations.list) channel_list=($(echo $channel_list | python -m json.tool | jq '.channels[].id' | tr -d '"')) for i in "${channel_list[@]}"; do @@ -278,7 +278,7 @@ function message { if [[ $channel == "" ]]; then log_comment_and_exit1 "ERROR: Channel information is missing" "usage: $BASENAME message slack send " elif [[ "${channel:0:1}" == [a-z] ]]; then - channel=$(channel_get $3) + channel=$(get_channel_id $3) fi shift; shift; shift; message=$* @@ -299,7 +299,7 @@ function message { if [[ $channel == "" ]]; then log_comment_and_exit1 "ERROR: Channel information is missing" "usage: $BASENAME message slack read " elif [[ "${channel:0:1}" == [a-z] ]]; then - channel=$(channel_get $3) + channel=$(get_channel_id $3) fi if ! check_channel $channel; then log_and_exit1 "invalid channel ID or channel name" @@ -345,7 +345,7 @@ function message { if [[ $channel == "" ]]; then log_comment_and_exit1 "ERROR: Channel information is missing" "usage: $BASENAME message slack read " elif [[ "${channel:0:1}" == [a-z] ]]; then - channel=$(channel_get $3) + channel=$(get_channel_id $3) fi if ! check_channel $channel; then log_and_exit1 "invalid channel ID or channel name" @@ -393,7 +393,7 @@ function message { if [[ $channel == "" ]]; then log_comment_and_exit1 "ERROR: Channel information is missing" "usage: $BASENAME message slack read " elif [[ "${channel:0:1}" == [a-z] ]]; then - channel=$(channel_get $3) + channel=$(get_channel_id $3) fi if ! check_channel $channel; then log_and_exit1 "invalid channel ID or channel name" From 010324a7137c6bb982cceda5812f181c9b59448c Mon Sep 17 00:00:00 2001 From: Neethu-Mohan Date: Sat, 21 Nov 2020 13:58:22 +0400 Subject: [PATCH 3/5] Update message.sh --- modules/message.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/message.sh b/modules/message.sh index 91a71cec0..85a59bf0c 100644 --- a/modules/message.sh +++ b/modules/message.sh @@ -216,7 +216,7 @@ function message { esac ;; slack) - function get_channel_id { + function check_channel { channel_list=$(curl -s -F token=$access_token https://slack.com/api/conversations.list) channel_list=($(echo $channel_list | python -m json.tool | jq '.channels[].id' | tr -d '"')) for i in "${channel_list[@]}"; do @@ -227,7 +227,7 @@ function message { done return 1 } - function channel_get { + function get_channel_id { name="$1" count=0 conversation_list=$(curl -s -F token=$access_token https://slack.com/api/conversations.list) From 4cad7407884e94a6e21faf4af9b1737f17beaa75 Mon Sep 17 00:00:00 2001 From: Neethu-Mohan Date: Sat, 21 Nov 2020 14:07:08 +0400 Subject: [PATCH 4/5] Update message.sh --- modules/message.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/message.sh b/modules/message.sh index 85a59bf0c..350d91ca5 100644 --- a/modules/message.sh +++ b/modules/message.sh @@ -233,7 +233,7 @@ function message { conversation_list=$(curl -s -F token=$access_token https://slack.com/api/conversations.list) channel_name=($(echo $conversation_list | python -m json.tool | jq '.channels[].name' | tr -d '"')) for i in "${channel_name[@]}"; do - if [[ $name == $i ]]; then + if [[ $name == "$i" ]]; then channel_id=$(echo $conversation_list | python -m json.tool | jq '.channels['$count'].id' | tr -d '"') echo $channel_id break From 19e760e4e1cff30c78d8a26d2a5c212961c5a9b1 Mon Sep 17 00:00:00 2001 From: dogi Date: Sat, 21 Nov 2020 05:10:27 -0500 Subject: [PATCH 5/5] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 521be382c..fb775cfe7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@treehouses/cli", - "version": "1.24.85", + "version": "1.24.86", "remote": "4000", "description": "Thin command-line interface for Raspberry Pi low level configuration.", "main": "cli.sh",