-
Notifications
You must be signed in to change notification settings - Fork 20
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -509,6 +509,42 @@ function message { | |
echo "you have successfully authorized and your access token is $access_token " | ||
fi | ||
;; | ||
webhook) | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should account for empty messages. Empty messages generate this error:
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still in the rough draft stages >.< |
||
esac | ||
|
There was a problem hiding this comment.
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.