Last active
June 6, 2018 17:25
-
-
Save catvec/3c348107a69e624ab7baab500ffee74c to your computer and use it in GitHub Desktop.
Sets your user's Slack status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Slack Status - Sets user Slack status | |
| # | |
| # Requires the HTTPie (https://httpie.org/) client | |
| # | |
| # Usage: slack-status STATUS [--help/-h] | |
| # | |
| # Args: | |
| # - STATUS: Status to set, one of | |
| # - music | |
| # - focus | |
| # - cool | |
| # - food | |
| # - out | |
| # - blocked | |
| # - common | |
| # Slack vars | |
| profile_set_url="slack.com/api/users.profile.set" | |
| token="<SLACK TOKEN>" | |
| # Get status | |
| status="$1" | |
| emoji="" | |
| message="" | |
| case "$status" in | |
| music) | |
| emoji=":headphones:" | |
| message="Plugged In" | |
| ;; | |
| focus) | |
| emoji=":hypnotized:" | |
| message="Deep Work" | |
| ;; | |
| cool) | |
| emoji=":cool-noah:" | |
| message="Maxin', relaxin', keyboard tappin', all cool" | |
| ;; | |
| food) | |
| emoji=":grapes:" | |
| message="Eating" | |
| ;; | |
| out) | |
| emoji=":takeout_box:" | |
| message="O^3" | |
| ;; | |
| blocked) | |
| emoji=":frowning:" | |
| message="Blocked" | |
| ;; | |
| common) | |
| emoji=":rocket:" | |
| message="Jammin' in WeeWork common space" | |
| ;; | |
| --help|-h) | |
| echo "Sets Slack Status" | |
| echo | |
| echo "Available statuses:" | |
| echo " - music" | |
| echo " - focus" | |
| echo " - cool" | |
| echo " - food" | |
| echo " - out" | |
| echo " - blocked" | |
| echo " - common" | |
| exit 1 | |
| ;; | |
| esac | |
| # Make request | |
| echo "Setting status to $emoji - $message" | |
| url="$profile_set_url?token=$token&profile={\"status_text\": \"$message\", \"status_emoji\": \"$emoji\"}" | |
| if ! http --follow POST "$url" > /dev/null; then | |
| echo "Error making Slack API request" | |
| else | |
| echo "Success" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment