From 4f0cd8667a051e96717e81b46a92c4a49c7f9ab7 Mon Sep 17 00:00:00 2001 From: Neethu-Mohan Date: Mon, 22 Feb 2021 15:10:04 -0500 Subject: [PATCH] `treehouses message discord apitoken` (fixes #2027) (#2028) Co-authored-by: dogi --- README.md | 1 + _treehouses | 2 ++ modules/help.sh | 1 + modules/message.sh | 55 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 5 files changed, 60 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4584176908..94100e5f9d 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,7 @@ message gitter sets api/channel info in config file a slack sets api/channel info in config file and sends/recieves messages in slack + discord sets api/channel info in config file shutdown [now|in|force] shutdown the system ``` diff --git a/_treehouses b/_treehouses index f9ef95395e..7f8dae0c91 100644 --- a/_treehouses +++ b/_treehouses @@ -241,6 +241,8 @@ treehouses message slack send treehouses message slack show treehouses message slack mark treehouses message slack read +treehouses message discord apitoken +treehouses message discord authorize treehouses networkmode treehouses networkmode info treehouses ntp internet diff --git a/modules/help.sh b/modules/help.sh index a60d49e32b..e767d2fad6 100644 --- a/modules/help.sh +++ b/modules/help.sh @@ -145,6 +145,7 @@ message gitter sets api/channel info in config file a slack sets api/channel info in config file and sends/recieves messages in slack + discord .......sets api/channel info in config file shutdown [now|in|force] shutdown the system EOF echo "$helpdefault" diff --git a/modules/message.sh b/modules/message.sh index 0d920a7f89..de0351d5d4 100644 --- a/modules/message.sh +++ b/modules/message.sh @@ -447,6 +447,55 @@ function message { log_help_and_exit1 "Error: This command does not exist" message esac ;; + discord) + case "$2" in + apitoken) + if check_apitoken discord; then + get_apitoken discord + elif [[ $3 != "" ]] && [[ $4 != "" ]]; then + client_id=$3 + if [[ $4 == http?(s)://* ]]; then + redirect_uri=$4 + else + log_and_exit1 "Invalid URL" + fi + conf_var_update "discord_clientid" "$client_id" + conf_var_update "discord_redirecturl" "$redirect_uri" + authorization_url=$(curl -Ls -o /dev/null -w %'{'url_effective'}' https://discord.com/api/oauth2/authorize?response_type=token\&client_id=${client_id}\&scope=identify) + echo "To get the access token, navigate to" + echo + echo "$authorization_url" + echo + echo "Then, click \"Authorize\" to provide permissions for your app" + echo "From the redirected link , you will get your access token for discord" + echo + echo "For example, if redirected link is \"http://localhost/token_type=Bearer&access_token=1234567890&expires_in=604800&scope=identify\"' then the access token is \"1234567890\"" + echo "Then, run $BASENAME message discord authorize " + else + echo "You do not have an authorized access token" + echo "" + echo "To get an authorized access token" + echo "" + echo "Navigate to https://discord.com/developers/applications. Create an APP by clicking \"New Application\" and provide a suitable name for your APP." + echo "Then move to the option \"OAuth2\" below \"General Information\" and add a redirect URL ( For eg: http://localhost/ ) by clicking \"Add Redirect\" below \"Redirects\"." + echo "Then, save the settings by pressing green save button at the bottom of the page." + echo "Note both the CLIENT ID and your Redirect URL" + echo "Run $BASENAME message discord apitoken " + fi + ;; + authorize) + if [[ $3 == "" ]]; then + echo "authorization code is missing" + else + access_token=$3 + conf_var_update "discord_apitoken" "$access_token" + echo "you have successfully authorized and your access token is $access_token " + fi + ;; + *) + log_help_and_exit1 "Error: This command does not exist" message + esac + ;; *) log_help_and_exit1 "Error: This command does not exist" message ;; @@ -504,4 +553,10 @@ function message_help { echo " $BASENAME message slack mark \"channel ID\"" echo " Marks messages of a slack channel using channel ID" echo + echo " $BASENAME message discord apitoken" + echo " Check for API token for discord" + echo + echo " $BASENAME message discord authorize \"1234567890\"" + echo " Sets and saves API token" + echo } diff --git a/package.json b/package.json index ba55d6cb0b..fd9b6599ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@treehouses/cli", - "version": "1.25.5", + "version": "1.25.6", "remote": "4000", "description": "Thin command-line interface for Raspberry Pi low level configuration.", "main": "cli.sh",