slack-big-emoji 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d717723d6be71d5d01fc84d5957a22623b38a294
4
+ data.tar.gz: 26f432aa79813c94aff58a0837b5372c241e1dbd
5
+ SHA512:
6
+ metadata.gz: 5ebd90f25594fde8ccca402428694a5afc0b998091f079796e0513975ad82b0059a366c3a45f5c2bd318ce4ddb7fa63ef8a8b99ef47f4c7b157fcf749c5592a1
7
+ data.tar.gz: c8b8694b7f4c452ae867581394dc4b6ffd15801ed0029eda150c80276e7bb3ed3bd6108b0de2d549056017867ddf78351181b11c5b8d1b8d6f337f23d0725cbe
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1 @@
1
+ slack-big-emoji
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Alejandro AR
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,115 @@
1
+ # Slack Big Emoji
2
+
3
+ Slack Big Emoji is a ruby command-line tool (see support) that helps out with the generation of big emojis to a Slack team.
4
+
5
+ See [What's a Big Emoji?](#whats-a-big-emoji) for more information.
6
+
7
+ ## Support
8
+
9
+ Make sure you're using Ruby 2.4.0 (will support native OS X version soon) and you have a working installation of ImageMagick.
10
+
11
+ About images:
12
+
13
+ - Tool can only process static image files (only png, jpg, jpeg).
14
+ - Images must be square or hold a w/h ratio of 1.0, this is going to be validated.
15
+ - No GIF support since Slack's limit is 64kb and it's a pain to generalize optimization.
16
+
17
+ ## Installation
18
+
19
+ Installation is done through RubyGems, to install run:
20
+
21
+ ```
22
+ $ gem install slack-big-emoji
23
+ ```
24
+
25
+ Once completed you should be ready to go.
26
+
27
+ ## Usage
28
+
29
+ First, locate a square image and run:
30
+
31
+ ```
32
+ $ slack-big-emoji liarliar.jpg
33
+ ```
34
+
35
+ The script will resize and crop the image into tiles and upload them all (through a small wizard) to your team's Slack.
36
+
37
+ You can also run `slack-big-emoji --help` for more options.
38
+
39
+
40
+ ## What's a Big Emoji?
41
+
42
+ Big emojis are a set of multiple emojis combined in a grid that together displays a big image.
43
+
44
+
45
+ > — Probably you: What?
46
+ >
47
+ > — Me, probably: Why not?
48
+ >
49
+ > — You: I mean, what's a Slack Big Emoji?
50
+
51
+ A Bigger Emoji™.
52
+
53
+ With this tool you'll be able to turn this Jim Carrey snapshot from the movie Liar Liar:
54
+
55
+ ![Picture of Jim Carrey's teeth in the movie "Liar Liar"](https://user-images.githubusercontent.com/1270156/27774411-73333d40-5f57-11e7-933e-751dbc178617.jpg)
56
+
57
+ Into a set of emoji codes like this one:
58
+
59
+ ```
60
+ :liarliar00::liarliar01::liarliar02::liarliar03::liarliar04:
61
+ :liarliar05::liarliar06::liarliar07::liarliar08::liarliar09:
62
+ :liarliar10::liarliar11::liarliar12::liarliar13::liarliar14:
63
+ :liarliar15::liarliar16::liarliar17::liarliar18::liarliar19:
64
+ :liarliar20::liarliar21::liarliar22::liarliar23::liarliar24:
65
+ ```
66
+
67
+ Once posted in Slack will look like this (mobile looks shitty, tho):
68
+
69
+ ![](https://user-images.githubusercontent.com/1270156/27774488-935d2850-5f58-11e7-8417-944b1251a3da.png)
70
+
71
+ ## Advanced Installation & Usage
72
+
73
+ This gem can be used from an application too, add this line to your Gemfile:
74
+
75
+ ```ruby
76
+ gem 'slack-big-emoji'
77
+ ```
78
+
79
+ And then execute:
80
+
81
+ ```ruby
82
+ $ bundle install
83
+ ```
84
+
85
+ For example, this is the minimal setup for a command-line tool:
86
+
87
+ ```ruby
88
+ require 'slack-big-emoji'
89
+ # require 'slack-big-emoji/cli'
90
+
91
+ # Sets up option parser coming from ARGV
92
+ cli = SlackBigEmoji::CLI.new(ARGV)
93
+
94
+ # Converter takes as args the file and conversion options
95
+ emoji = SlackBigEmoji::Converter.new(cli.options)
96
+ emoji.convert
97
+
98
+ # The uploader takes care to upload a folder full of images
99
+ uploader = SlackBigEmoji::Uploader.new(emoji.output_filename)
100
+ uploader.upload_emojis
101
+
102
+ # The CLI generates a grid based on the output filename,
103
+ # this is the grid to be used in Slack to see the full emoji
104
+ cli.emoji_grid(emoji.output_filename)
105
+ ```
106
+
107
+ Further documentation can be read in code.
108
+
109
+ ## Contributing
110
+
111
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kinduff/slack-big-emoji. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
112
+
113
+ ## License
114
+
115
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-cayman
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/slack_big_emoji'
3
+
4
+ cli = SlackBigEmoji::CLI.new(ARGV)
5
+ emoji = SlackBigEmoji::Converter.new(cli.options)
6
+ unless emoji.valid?
7
+ abort "Image must be a square, w/h ratio of 1.0"
8
+ end
9
+
10
+ cli.log "File Info"
11
+ cli.log "--------------"
12
+ cli.log "File name", emoji.file_name
13
+ cli.log "Ratio", emoji.ratio
14
+ cli.log "File Resize Spec", emoji.file_resize_spec
15
+ cli.log ""
16
+ cli.log "Options"
17
+ cli.log "--------------"
18
+ cli.log "Tile Width", emoji.tile_width
19
+ cli.log "Crop Size", emoji.crop_size
20
+ cli.log ""
21
+ cli.log "CLI Options"
22
+ cli.log "--------------"
23
+ cli.options.each do |option, value|
24
+ cli.log "#{option}", value
25
+ end
26
+
27
+ cli.log ""
28
+ cli.log "Converting"
29
+ cli.log "--------------"
30
+ cli.log "Temp Input", emoji.image.path
31
+ cli.log "Output Dir", emoji.output_dir
32
+ cli.log "Output Path", emoji.output_path
33
+ emoji.convert
34
+ cli.log "Done", "Yes"
35
+
36
+ unless cli.options[:convert_only]
37
+ cli.log ""
38
+ cli.log "Uploading"
39
+ cli.log "--------------"
40
+ uploader = SlackBigEmoji::Uploader.new(emoji.file_name)
41
+ uploader.upload_emojis
42
+ end
43
+
44
+ cli.log ""
45
+ cli.log "Emoji Grid"
46
+ cli.log "--------------"
47
+ cli.emoji_grid(emoji.output_filename)
@@ -0,0 +1,6 @@
1
+ module SlackBigEmoji
2
+ require 'slack_big_emoji/version'
3
+ require 'slack_big_emoji/cli'
4
+ require 'slack_big_emoji/converter'
5
+ require 'slack_big_emoji/uploader'
6
+ end
@@ -0,0 +1,73 @@
1
+ require 'optparse'
2
+
3
+ module SlackBigEmoji
4
+ class CLI
5
+ attr_accessor :options
6
+
7
+ def initialize(args)
8
+ @options = parse(args)
9
+ end
10
+
11
+ def parse(args)
12
+ options = {}
13
+ opts = OptionParser.new do |opts|
14
+ opts.banner = "Usage: slack-big-emoji [options] FILE"
15
+ opts.version = SlackBigEmoji::VERSION
16
+
17
+ opts.on( '-f', '--file-name=NAME', 'Output filename.' ) do |val|
18
+ options[:output_filename] = val
19
+ end
20
+
21
+ opts.on( '-o', '--output-dir=NAME', 'Output directory.' ) do |val|
22
+ options[:output_dir] = val
23
+ end
24
+
25
+ options[:silent] = false
26
+ opts.on( '-s', '--silent', 'Silent or quiet mode.' ) do
27
+ options[:silent] = true
28
+ end
29
+
30
+ options[:convert_only] = false
31
+ opts.on( '-c', '--convert-only', 'Convert image but do not upload.' ) do
32
+ options[:convert_only] = true
33
+ end
34
+
35
+ opts.on_tail( '-h', '--help', 'Show this message' ) do
36
+ puts opts
37
+ exit
38
+ end
39
+ end
40
+ opts.parse! # removes switches destructively, but not non-options
41
+
42
+
43
+ file = args.first # ARGV args only - no options
44
+
45
+ # validates input to be one image file, no gif support (yet)
46
+ abort "Error: Missing input file" unless file
47
+ abort "Just specify one file" if args.count > 1
48
+ abort "Use a valid image file (png, jpeg or jpg)" if (file =~ /.\.(png|jpeg|jpg)$/).nil?
49
+
50
+ options[:file] = file
51
+
52
+ options
53
+ end
54
+
55
+ def emoji_grid(file_name)
56
+ 25.times do |i|
57
+ puts "" if i % 5 == 0 && i != 0
58
+ print ":#{file_name}#{("%02d" % i)}:"
59
+ end
60
+ puts # madrs
61
+ end
62
+
63
+ def log(*msg)
64
+ unless @options[:silent]
65
+ if msg.size == 1
66
+ puts msg
67
+ else
68
+ printf "%-20s %s\n", msg.first, msg.last
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,34 @@
1
+ require 'mini_magick'
2
+ require_relative 'uploader'
3
+
4
+ module SlackBigEmoji
5
+ class Converter
6
+ attr_accessor :image, :file_name, :ratio, :file_resize_spec, :tile_width, :crop_size, :output_dir, :output_filename, :output_path
7
+
8
+ def initialize(options={})
9
+ @image = ::MiniMagick::Image.open(options[:file])
10
+ @file_name = File.basename(options[:file], ".*")
11
+ @ratio = @image[:width].to_f/@image[:height].to_f
12
+ @file_resize_spec = '640x640'
13
+ @tile_width = 5
14
+ @crop_size = '128x128'
15
+ @output_dir = options[:output_dir] || @file_name
16
+ @output_filename = options[:output_filename] || @file_name
17
+ @output_path = "#{@output_dir}/#{@output_filename}%02d.png"
18
+ end
19
+
20
+ def valid?
21
+ return @ratio == 1
22
+ end
23
+
24
+ def convert
25
+ convert_opts = ["-resize", @file_resize_spec, "-crop", @crop_size]
26
+ Dir.mkdir(@output_dir) unless File.exists?(@output_dir)
27
+ ::MiniMagick::Tool::Convert.new do |convert|
28
+ convert << @image.path
29
+ convert.merge! convert_opts
30
+ convert << @output_path
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,71 @@
1
+ require 'highline/import'
2
+ require 'mechanize'
3
+
4
+ # Grabbed from https://github.com/oti/slack-reaction-decomoji/blob/master/import.rb
5
+ module SlackBigEmoji
6
+ class Uploader
7
+ BASE_DIR = File.expand_path(File.dirname(__FILE__))
8
+
9
+ def initialize(dir)
10
+ @dir = dir
11
+ @page = nil
12
+ @agent = Mechanize.new
13
+ end
14
+ attr_accessor :page, :agent
15
+
16
+ def upload_emojis
17
+ move_to_emoji_page
18
+ push_emojis
19
+ end
20
+
21
+ private
22
+
23
+ def login
24
+ team_name = ask('Your slack team name (subdomain): ')
25
+ email = ask('Login email: ')
26
+ password = ask('Login password (hidden): ') { |q| q.echo = false }
27
+
28
+ emoji_page_url = "https://#{team_name}.slack.com/admin/emoji"
29
+
30
+ page = agent.get(emoji_page_url)
31
+ page.form.email = email
32
+ page.form.password = password
33
+ @page = page.form.submit
34
+ end
35
+
36
+ def enter_two_factor_authentication_code
37
+ page.form['2fa_code'] = ask('Your two factor authentication code: ')
38
+ @page = page.form.submit
39
+ end
40
+
41
+ def move_to_emoji_page
42
+ loop do
43
+ if page && page.form['signin_2fa']
44
+ enter_two_factor_authentication_code
45
+ else
46
+ login
47
+ end
48
+
49
+ break if page.title.include?('Emoji')
50
+ puts 'Login failure. Please try again.'
51
+ puts
52
+ end
53
+ end
54
+
55
+ def push_emojis
56
+ Dir.glob("#{@dir}/*.png").sort.each do |path|
57
+ basename = File.basename(path, '.*')
58
+
59
+ # skip if already exists
60
+ next if page.body.include?(":#{basename}:")
61
+
62
+ puts "importing #{basename}..."
63
+
64
+ form = page.form_with(action: '/customize/emoji')
65
+ form['name'] = basename
66
+ form.file_upload.file_name = path
67
+ @page = form.submit
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ module SlackBigEmoji
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'slack_big_emoji/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "slack-big-emoji"
8
+ s.version = SlackBigEmoji::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["kinduff"]
11
+ s.email = ["abarcadabra@gmail.com"]
12
+
13
+ s.summary = %q{Command-line tool to create big emojis for Slack.}
14
+ s.description = %q{Slack Big Emoji is a ruby command-line tool (see support) that helps out with the generation of big emojis to a Slack team.}
15
+ s.homepage = "http://github.com/kinduff/slack-big-emoji"
16
+ s.license = "MIT"
17
+
18
+ s.require_paths = %w[lib]
19
+ s.files = `git ls-files`.split($\)
20
+ s.executables = %w[slack-big-emoji]
21
+ s.test_files = s.files.grep(%r{^spec/})
22
+ s.extra_rdoc_files = %w[README.md]
23
+
24
+ s.add_dependency "mechanize", "~> 2.7.5"
25
+ s.add_dependency "highline", "~> 1.7.8"
26
+ s.add_dependency "mini_magick", "~> 4.7.2"
27
+
28
+ s.add_development_dependency "bundler", "~> 1.11"
29
+ s.add_development_dependency "rake", "~> 10.0"
30
+ s.add_development_dependency "rspec", "~> 3.0"
31
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe SlackBigEmoji do
4
+ it 'has a version number' do
5
+ expect(SlackBigEmoji::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'slack_big_emoji'
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slack-big-emoji
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kinduff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mechanize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.7.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.7.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: highline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.7.8
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.7.8
41
+ - !ruby/object:Gem::Dependency
42
+ name: mini_magick
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 4.7.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 4.7.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.11'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: Slack Big Emoji is a ruby command-line tool (see support) that helps
98
+ out with the generation of big emojis to a Slack team.
99
+ email:
100
+ - abarcadabra@gmail.com
101
+ executables:
102
+ - slack-big-emoji
103
+ extensions: []
104
+ extra_rdoc_files:
105
+ - README.md
106
+ files:
107
+ - ".gitignore"
108
+ - ".rbenv-gemsets"
109
+ - ".rspec"
110
+ - ".travis.yml"
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - _config.yml
116
+ - bin/slack-big-emoji
117
+ - lib/slack_big_emoji.rb
118
+ - lib/slack_big_emoji/cli.rb
119
+ - lib/slack_big_emoji/converter.rb
120
+ - lib/slack_big_emoji/uploader.rb
121
+ - lib/slack_big_emoji/version.rb
122
+ - slack-big-emoji.gemspec
123
+ - spec/slack_big_emoji/slack_big_emoji_spec.rb
124
+ - spec/spec_helper.rb
125
+ homepage: http://github.com/kinduff/slack-big-emoji
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.6.12
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Command-line tool to create big emojis for Slack.
149
+ test_files:
150
+ - spec/slack_big_emoji/slack_big_emoji_spec.rb
151
+ - spec/spec_helper.rb