Skip to content

Instantly share code, notes, and snippets.

@daybreaker daybreaker/dlemoji.rb
Last active Jan 10, 2020

Embed
What would you like to do?
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
You can’t perform that action at this time.