rwxrob-dot/scripts/twitter

57 lines
1.2 KiB
Plaintext
Raw Normal View History

2022-02-09 19:24:05 +00:00
#!/usr/bin/env bash
2022-02-09 07:29:05 +00:00
USER=rwxrob
EMAIL=rob@rwx.gg
ID=1210114652
update () {
local status="$1" image="$2" data media_id
if [[ -n "${image}" ]]; then
media_id=$(twurl -X POST -H upload.twitter.com \
'/1.1/media/upload.json?media_category=TWEET_IMAGE&additional_owners='${ID} \
-f "${image}" -F media | jq .media_id )
data="media_ids=${media_id}&status=${status}"
echo "$data"
else
data="status=${status}"
fi
twurl '/1.1/statuses/update.json' -d "${data}" | jq .created_at
}
tweets () {
twurl "/2/tweets?ids=$1"
}
############################## Main Command #############################
subcommand="${1-usage}"
shift 2>/dev/null
if [ -z "$subcommand" ]; then
usage
exit 1
fi
commands () {
echo ${commands[@]}
}
declare -a commands=(commands update tweets)
for i in ${commands[@]}; do
if [[ "$i" == "$subcommand" ]]; then
"$subcommand" "$@"
exit 0
fi
done
######################### Tab Completion Context ########################
# remember COMP_LINE is changed by shift
if [ -n "$COMP_LINE" ]; then
for cmd in ${commands[@]}; do
[[ "${cmd:0:${#1}}" == "$1" ]] && echo $cmd
done
exit 0
fi