Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ $ export SLACK_CLI_TOKEN='token'

## Examples and Recipes

### `avatar`

```console
$ # Upload avatar via prompts:
$ slack avatar upload
$
$ # Upload avatar via arguments:
$ slack avatar upload avatar.png
$
$ # Delete avatar:
$ slack avatar delete
```

### `chat send`

```console
Expand Down
35 changes: 33 additions & 2 deletions src/slack
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cmd="${1}" ; shift

# SUBCOMMAND PARSING ##############################################################################
case "${cmd}${1}" in
chatdelete|chatsend|chatupdate|\
avatarupload|avatardelete|chatdelete|chatsend|chatupdate|\
filedelete|fileinfo|filelist|fileupload|\
presenceactive|presenceaway|\
reminderadd|remindercomplete|reminderdelete|reminderinfo|reminderlist| \
Expand Down Expand Up @@ -99,6 +99,9 @@ while (( "$#" )); do
--user|-ur*) user=${2} ; shift ; shift ;;
*)
case "${cmd}${sub}" in
avatarupload)
[ -n "${1}" ] && [ -z "${file}" ] && file=${1}
;;
chatdelete)
[ -n "${1}" ] && [ -n "${timestamp}" ] && [ -z "${channel}" ] && channel=${1}
[ -n "${1}" ] && [ -z "${timestamp}" ] && timestamp=${1}
Expand Down Expand Up @@ -147,6 +150,9 @@ ${trace}

# ARGUMENT AND OPTION PROMPTING ###################################################################
case "${cmd}${sub}" in
avatarupload)
[ -z "${file}" ] && read -e -p 'Enter avatar upload (e.g. avatar.png): ' file
;;
chatdelete)
[ -z "${channel}" ] && read -e -p 'Enter channel (e.g. #general): ' channel
[ -z "${timestamp}" ] && read -e -p 'Enter timestamp (e.g. 1405894322.002768): ' timestamp
Expand Down Expand Up @@ -432,6 +438,10 @@ function help() {
echo ' status clear Clear status'
echo ' status edit Edit status'
echo
echo 'Avatar Commands:'
echo ' avatar upload Upload avatar'
echo ' avatar delete Delete avatar'
echo
echo 'More Information:'
echo ' repo https://github.com/rockymadden/slack-cli'
}
Expand Down Expand Up @@ -518,6 +528,27 @@ function fileupload() {
jqify "${msg}"
}

function avatarupload() {
if [ -f "${file}" ]; then
local _file=${file}
fi

local msg=$(\
curl -s -X POST https://slack.com/api/users.setPhoto \
${_file:+ --form "image=@${_file}"} \
--form "token=${token}")

jqify "${msg}"
}

function avatardelete() {
local msg=$(\
curl -s https://slack.com/api/users.deletePhoto \
--form "token=${token}")

jqify "${msg}"
}

function init() {
echo "${token}" > "${etcdir}/.slack"

Expand Down Expand Up @@ -652,7 +683,7 @@ case "${cmd}${sub}" in
--help|-h) help ; exit 0 ;;
--version|-v) version ; exit 0 ;;
init) init ; exit $? ;;
chatdelete|chatsend|chatupdate|\
avatarupload|avatardelete|chatdelete|chatsend|chatupdate|\
filedelete|fileinfo|filelist|fileupload|\
presenceactive|presenceaway|\
reminderadd|remindercomplete|reminderdelete|reminderinfo|reminderlist|\
Expand Down
Binary file added test/assets/avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions test/integration/avatar.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bats

load suite

@test 'avatar upload should succeed' {
build/bin/slack avatar upload test/assets/avatar.png
}

@test 'avatar delete should succeed' {
build/bin/slack avatar delete
}