slack-big-emoji 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d717723d6be71d5d01fc84d5957a22623b38a294
4
- data.tar.gz: 26f432aa79813c94aff58a0837b5372c241e1dbd
2
+ SHA256:
3
+ metadata.gz: 38855d83a1df5924df61d4921d9a899dc0727b420aa89d016e7b4ab816666aa6
4
+ data.tar.gz: 8fee74c779c257dba1096656c8998cbd268b2b9b80e410a60ca4d51ec84daec1
5
5
  SHA512:
6
- metadata.gz: 5ebd90f25594fde8ccca402428694a5afc0b998091f079796e0513975ad82b0059a366c3a45f5c2bd318ce4ddb7fa63ef8a8b99ef47f4c7b157fcf749c5592a1
7
- data.tar.gz: c8b8694b7f4c452ae867581394dc4b6ffd15801ed0029eda150c80276e7bb3ed3bd6108b0de2d549056017867ddf78351181b11c5b8d1b8d6f337f23d0725cbe
6
+ metadata.gz: b154c46ecdcc8ccf01bb150e3e4cc1862ef07e008f4ecb4751c6c18a8dd93aac4c2dd08f4c1914996cb4046041070e342b237a5610c4387a7de858de8a140729
7
+ data.tar.gz: cbf84d4d743fa140ef6343d2730f59a696000b803a53800483edbc347a965b4693d1a7c2884022707009c7779bff8c4ea8af004e2c38da864dd6240f11141d2a
@@ -1,6 +1,6 @@
1
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'
2
+ require_relative 'slack_big_emoji/version'
3
+ require_relative 'slack_big_emoji/cli'
4
+ require_relative 'slack_big_emoji/converter'
5
+ require_relative 'slack_big_emoji/uploader'
6
6
  end
@@ -1,7 +1,8 @@
1
1
  require 'highline/import'
2
2
  require 'mechanize'
3
+ require 'logger'
3
4
 
4
- # Grabbed from https://github.com/oti/slack-reaction-decomoji/blob/master/import.rb
5
+ # Grabbed from https://github.com/decomoji/slack-reaction-decomoji/blob/fd1f9b6a12b95ee27b9ad4173560db9ae3015ea0/scripts/import.rb
5
6
  module SlackBigEmoji
6
7
  class Uploader
7
8
  BASE_DIR = File.expand_path(File.dirname(__FILE__))
@@ -11,7 +12,7 @@ module SlackBigEmoji
11
12
  @page = nil
12
13
  @agent = Mechanize.new
13
14
  end
14
- attr_accessor :page, :agent
15
+ attr_accessor :page, :agent, :team_name, :token
15
16
 
16
17
  def upload_emojis
17
18
  move_to_emoji_page
@@ -21,21 +22,23 @@ module SlackBigEmoji
21
22
  private
22
23
 
23
24
  def login
24
- team_name = ask('Your slack team name (subdomain): ')
25
+ @team_name = ask('Your slack team name(subdomain): ')
25
26
  email = ask('Login email: ')
26
- password = ask('Login password (hidden): ') { |q| q.echo = false }
27
+ password = ask('Login password(hidden): ') { |q| q.echo = false }
27
28
 
28
- emoji_page_url = "https://#{team_name}.slack.com/admin/emoji"
29
+ emoji_page_url = "https://#{team_name}.slack.com/customize/emoji"
29
30
 
30
31
  page = agent.get(emoji_page_url)
31
32
  page.form.email = email
32
33
  page.form.password = password
33
34
  @page = page.form.submit
35
+ @token = @page.body[/(?<=api_token":")[^"]+/]
34
36
  end
35
37
 
36
38
  def enter_two_factor_authentication_code
37
39
  page.form['2fa_code'] = ask('Your two factor authentication code: ')
38
40
  @page = page.form.submit
41
+ @token = @page.body[/(?<=api_token":")[^"]+/]
39
42
  end
40
43
 
41
44
  def move_to_emoji_page
@@ -53,19 +56,35 @@ module SlackBigEmoji
53
56
  end
54
57
 
55
58
  def push_emojis
59
+ emojis = list_emojis
56
60
  Dir.glob("#{@dir}/*.png").sort.each do |path|
57
61
  basename = File.basename(path, '.*')
58
62
 
59
63
  # skip if already exists
60
- next if page.body.include?(":#{basename}:")
64
+ next if emojis.include?(basename)
61
65
 
62
66
  puts "importing #{basename}..."
63
67
 
64
- form = page.form_with(action: '/customize/emoji')
65
- form['name'] = basename
66
- form.file_upload.file_name = path
67
- @page = form.submit
68
+ params = {
69
+ name: basename,
70
+ image: File.new(path),
71
+ mode: 'data',
72
+ token: token
73
+ }
74
+ agent.post("https://#{@team_name}.slack.com/api/emoji.add", params)
68
75
  end
69
76
  end
77
+
78
+ def list_emojis
79
+ emojis = []
80
+ loop.with_index(1) do |_, n|
81
+ params = { query: '', page: n, count: 100, token: token }
82
+ res = JSON.parse(agent.post("https://#{team_name}.slack.com/api/emoji.adminList", params).body)
83
+ raise res['error'] if res['error']
84
+ emojis.push(*res['emoji'].map { |e| e['name'] })
85
+ break if res['paging']['pages'] == n || res['paging']['pages'] == 0
86
+ end
87
+ emojis
88
+ end
70
89
  end
71
90
  end
@@ -1,3 +1,3 @@
1
1
  module SlackBigEmoji
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-big-emoji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kinduff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-03 00:00:00.000000000 Z
11
+ date: 2019-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  version: '0'
143
143
  requirements: []
144
144
  rubyforge_project:
145
- rubygems_version: 2.6.12
145
+ rubygems_version: 2.7.7
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: Command-line tool to create big emojis for Slack.