-
Notifications
You must be signed in to change notification settings - Fork 8
/
slack
executable file
路190 lines (164 loc) 路 4.72 KB
/
slack
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env bash
set -euo pipefail
#
# What in tarnation?
#
# CLI tool to control slack status and presence
#
# Requires:
# - ENV vars setup for your slack API tokens (KEEP THEM SAFE! DO NOT commit your tokens to github)
# * you can find them here: https://api.slack.com/custom-integrations/legacy-tokens
# - `spinner` from my dotfiles' `bin` folder
#
# Attribution: https://github.com/matthewfallshaw/utilities/blob/master/shell/slack-status
#
base_command=""
subcommand=""
presence=""
profile=""
dnd=""
base_command="$(basename "$0")"
help() {
printf -- "Usage: %s <subcommand>\n" "$base_command"
printf -- "\n"
printf -- "Subcommands:\n"
printf -- " away Set presence to away, and profile for being gone\n"
printf -- " lunch Set presence to away, and profile for lunch\n"
printf -- " coffee Set presence to away, and profile for coffee\n"
printf -- " pair Set DND to on, and profile for pairing\n"
printf -- " zoom Set DND to on, and profile for zoom/meeting\n"
printf -- " dnd Set DND to on, and profile for DND/focus\n"
printf -- " back Set presence to auto, and profile accordingly\n"
printf -- "\n"
}
function request() {
# $1=token
# $2=options
# $3=endpoint
# non-zero length string AND a value not equal to 0
# TODO: need better way to handle options/args that don't exist
if [[ -n $2 && $2 != 0 ]]; then
curl 2>/dev/null 1>&2 -s -S --data "" "https://slack.com/api/$3?token=$1&$2" | $HOME/.dotfiles/bin/spinner
else
curl 2>/dev/null 1>&2 -s -S --data "" "https://slack.com/api/$3?token=$1" | $HOME/.dotfiles/bin/spinner
fi
}
function set_profile() {
# $1=token
# $2=options
request $1 $2 "users.profile.set"
}
function set_presence() {
# $1=token
# $2=options
request $1 $2 "users.setPresence"
}
function set_dnd() {
# $1=token
# $2=options
request $1 $2 "dnd.setSnooze"
}
function end_dnd() {
# $1=token
# $2=options
request $1 $2 "dnd.endDnd"
}
function set_all_presence() {
set_presence $OUTSTAND_TOKEN $1
# set_presence $CIT_TOKEN $1
# set_presence $MAGICCITYTECH_TOKEN $1
}
function set_all_profile() {
set_profile $OUTSTAND_TOKEN $1
# set_profile $CIT_TOKEN $1
# set_profile $MAGICCITYTECH_TOKEN $1
}
function set_all_dnd() {
set_dnd $OUTSTAND_TOKEN $1
# set_dnd $CIT_TOKEN $1
# set_dnd $MAGICCITYTECH_TOKEN $1
}
function end_all_dnd() {
end_dnd $OUTSTAND_TOKEN $1
# end_dnd $CIT_TOKEN $1
# end_dnd $MAGICCITYTECH_TOKEN $1
}
function away() {
presence="presence=away"
set_all_presence $presence
# profile="profile=%7B%22status_text%22:%22..afk..%22,%22status_emoji%22:%22:wave:%22%7D"
# profile="profile=%7B%22status_text%22:%22%22,%22status_emoji%22:%22%22%7D"
profile="profile=%7B%22status_text%22:%22..afk..%22,%22status_emoji%22:%22:afk:%22%7D"
set_all_profile $profile
}
function brb() {
presence="presence=away"
set_all_presence $presence
# profile="profile=%7B%22status_text%22:%22..afk..%22,%22status_emoji%22:%22:wave:%22%7D"
profile="profile=%7B%22status_text%22:%22..be%20right%20back..%22,%22status_emoji%22:%22:brb:%22%7D"
set_all_profile $profile
}
function lunch() {
presence="presence=away"
set_all_presence $presence
profile="profile=%7B%22status_text%22:%22..lunch..%22,%22status_emoji%22:%22:taco:%22%7D"
set_all_profile $profile
}
function coffee() {
presence="presence=away"
set_all_presence $presence
profile="profile=%7B%22status_text%22:%22..covfefe..%22,%22status_emoji%22:%22:coffee:%22%7D"
set_all_profile $profile
}
function gone() {
presence="presence=away"
set_all_presence $presence
# profile="profile=%7B%22status_text%22:%22..afk..%22,%22status_emoji%22:%22:wave:%22%7D"
profile="profile=%7B%22status_text%22:%22%22,%22status_emoji%22:%22%22%7D"
set_all_profile $profile
dnd="num_minutes=930"
set_all_dnd $dnd
}
function pair() {
profile="profile=%7B%22status_text%22:%22..pairing..%22,%22status_emoji%22:%22:pear:%22%7D"
set_all_profile $profile
dnd="num_minutes=120"
set_all_dnd $dnd
}
function zoom() {
profile="profile=%7B%22status_text%22:%22..on%20a%20call..%22,%22status_emoji%22:%22:calendar:%22%7D"
set_all_profile $profile
dnd="num_minutes=120"
set_all_dnd $dnd
}
function dnd() {
profile="profile=%7B%22status_text%22:%22..focused%20work%20time..%22,%22status_emoji%22:%22:octagonal_sign:%22%7D"
set_all_profile $profile
dnd="num_minutes=120"
set_all_dnd $dnd
}
function back() {
presence="presence=auto"
set_all_presence $presence
profile="profile=%7B%22status_text%22:%22%22,%22status_emoji%22:%22%22%7D"
set_all_profile $profile
dnd=0
end_all_dnd $dnd
}
subcommand=$1
# options=$2
case $subcommand in
'' | '-h' | '--help')
help
;;
here)
back
;;
meeting | meet | loom)
zoom
;;
*)
shift
${subcommand} "$@"
;;
esac