Skip to content

Instantly share code, notes, and snippets.

@gecko655
Last active September 4, 2018 16:14
Show Gist options
  • Save gecko655/aa93ae94382dfbf38c06a1bfe9d06bfa to your computer and use it in GitHub Desktop.
Save gecko655/aa93ae94382dfbf38c06a1bfe9d06bfa to your computer and use it in GitHub Desktop.
# Slack team内で最近発言されたチャンネルだけをリストアップするやつ
# channels.listのページングは何も考えてない。1000くらいなら取れるっぽい。
TOKEN='xoxp-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' #slack regacy|user|bot token
curl 'https://slack.com/api/channels.list?token='$TOKEN'&exclude_archived=true&exclude_members=true&limit=1000' > tmp
for row in `cat tmp | jq -r '.channels[] | .id +"," + .name'`
do
ch_id=`echo $row | cut -d',' -f 1`
date_raw=`curl 'https://slack.com/api/channels.history?token='$TOKEN'&channel='$ch_id'&count=100' | \
jq -r '[.messages[] | select(.subtype == 'null')][0] | .ts' | \ # find the last HUMAN-made post
sed 's/\..*$//'`
if [[ "$date_raw" = 'null' ]]; then
continue #no one (human) posted in this channel
fi
date_readable=`date -r $date_raw`
echo "${date_raw},${date_readable},${row}"
done | sort -t',' -k1 -nr | cut -d',' -f'2,4' > result
rm tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment