Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding new feature to treehouses message discord #2138

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions modules/message.sh
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,42 @@ function message {
echo "you have successfully authorized and your access token is $access_token "
fi
;;
webhook)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could echo error message if webhook and/or apitoken isn't provided:

e.g.

Error: Please add a webhook URL.

webhook_url=$3
declare -A discordVariables
discordVariables[botname]="jq .name"
discordVariables[webhookid]="jq .id"
discordVariables[webhooktoken]="jq .token"
discordVariables[server]="jq .guild_id"
discordVariables[channel]="jq .channel_id"
getinfo=$(curl -s -X GET "$webhook_url")

for key in "${!discordVariables[@]}"; do
if [ "$key" == "botname" ] ; then
discordVariables[$key]=$(echo "$getinfo" | ${discordVariables[$key]} )
else
discordVariables[$key]=$(echo "$getinfo" | ${discordVariables[$key]} | sed 's/\"//g' )
fi
done

for key in "${!discordVariables[@]}"; do
config add "discord_${discordVariables[server]}_${discordVariables[channel]}_${key}" "${discordVariables[$key]}"
done

echo "Your webhook url is $webhook_url"
;;
send)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should account for empty messages. Empty messages generate this error:

line 542: {"message":: command not found
ERROR: message not delivered

shift; shift;
message=$*
webhookid=$(config | grep "webhookid" | cut -d "=" -f2)
webhooktoken=$(config | grep "webhooktoken" | cut -d "=" -f2)
message_response=$(curl -s -X POST -H "Content-Type: application/json" -d "{\"content\": \"$message\"}" "https://discord.com/api/webhooks/${webhookid}/${webhooktoken}")
if $message_response ; then
echo "message successfully delivered to Discord"
else
log_comment_and_exit1 "ERROR: message not delivered"
fi
;;
*)
log_help_and_exit1 "Error: This command does not exist" message
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message could be updated to explicitly list all the Discord commands that exist.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still in the rough draft stages >.<

esac
Expand Down