Skip to content

Instantly share code, notes, and snippets.

@daybreaker
Last active October 4, 2021 14:10
Show Gist options
  • Save daybreaker/d99b19a7a855d5559a6dcf43d2b53c3b to your computer and use it in GitHub Desktop.
Save daybreaker/d99b19a7a855d5559a6dcf43d2b53c3b to your computer and use it in GitHub Desktop.
Download and Zip your slack emoji
# gem install slack-ruby-client rubyzip
# run with: ruby dlemoji.rb
require 'rubygems'
require 'zip'
require 'slack-ruby-client'
require 'open-uri'
token = 'your slack api token'
directory = '/<absolute/path/to>/emoji/' # The emoji directory must exist, and be empty.
zipfile_name = 'emoji.zip'
# Download the image from slack's server and save locally
def download_image(url, dest, dir = '')
open(url) do |u|
File.open(dir + dest, 'wb') { |f| f.write(u.read) }
end
end
Slack.configure do |config|
config.token = token
end
client = Slack::Web::Client.new
client.emoji_list.emoji.each do |name, url|
next if url.include? 'alias:' # skip aliased emoji
download_image(url, name + '.' + url.split('.').last, directory)
end
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
Dir[File.join(directory, '*')].each do |file|
zipfile.add(file.sub(directory, ''), file)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment