chatwork_to_slack 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -0
- data/Rakefile +2 -0
- data/bin/chatwork_to_slack +72 -0
- data/chatwork_to_slack.gemspec +30 -0
- data/lib/chatwork_to_slack/filters/dtext.rb +33 -0
- data/lib/chatwork_to_slack/filters/emoji.rb +55 -0
- data/lib/chatwork_to_slack/filters/picon.rb +26 -0
- data/lib/chatwork_to_slack/filters/pre.rb +18 -0
- data/lib/chatwork_to_slack/filters/quote.rb +43 -0
- data/lib/chatwork_to_slack/filters/reply.rb +50 -0
- data/lib/chatwork_to_slack/importer.rb +73 -0
- data/lib/chatwork_to_slack/message.rb +59 -0
- data/lib/chatwork_to_slack/version.rb +3 -0
- data/lib/chatwork_to_slack.rb +83 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 85fa4771962810514b9243ea9fba89437b0d494c
|
4
|
+
data.tar.gz: 5e560b0ec21b5074210684c79fea90271470d6fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2540f1af5593f1987e5e654feba202b8b4a7470591712f7c8e41a83bf065e18a7f099a3283b579a3c50bddf3d490ae59cf9e5cf6cef616072b717dc39f18c6c4
|
7
|
+
data.tar.gz: 7ada0d43214f3b19776f61bf22c9421582343c4d845fd3bc71dda4cb8f72bbcfaa74e7e047ed26a1820bef76b221060b45940aaf11adfbe42bba0baeac34c6fd
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 kkosuge
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# ChatWorkToSlack
|
2
|
+
|
3
|
+
ChatWork(chatwork.com)のデータを Slack の Import CSV 形式に変換するツール
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
$ gem install chatwork_to_slack
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
ユーザー定義リストのテンプレートを作成
|
14
|
+
|
15
|
+
```
|
16
|
+
$ chatwork_to_slack --generate-template -k chatwork_api_key
|
17
|
+
```
|
18
|
+
|
19
|
+
ChatWork からデータをダウンロードして Slack 形式に変換
|
20
|
+
|
21
|
+
```
|
22
|
+
$ chatwork_to_slack -i example@example.co.jp -p your_password -x chatwork_room_id -c slack_channel_name
|
23
|
+
```
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kkosuge/chatwork_to_slack.
|
28
|
+
|
29
|
+
|
30
|
+
## License
|
31
|
+
|
32
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "chatwork_to_slack"
|
5
|
+
require "optparse"
|
6
|
+
require "fileutils"
|
7
|
+
require "chatwork"
|
8
|
+
require "goodbye_chatwork"
|
9
|
+
require "csv"
|
10
|
+
require "pry"
|
11
|
+
require "pp"
|
12
|
+
|
13
|
+
|
14
|
+
opts = ARGV.getopts('i:p:e:x:c:d:h:k:', 'generate-template')
|
15
|
+
email = opts['i']
|
16
|
+
password = opts['p']
|
17
|
+
chatwork_api_key = opts['k']
|
18
|
+
|
19
|
+
if opts['generate-template'] && !!chatwork_api_key
|
20
|
+
client = ChatWorkToSlack::Client.new(chatwork_api_key: chatwork_api_key)
|
21
|
+
if File.exists?('users.csv')
|
22
|
+
puts 'users.csv exists'
|
23
|
+
else
|
24
|
+
csv = client.generate_template
|
25
|
+
CSV.parse(csv).each {|row| p row }
|
26
|
+
File.write('users.csv', csv)
|
27
|
+
puts 'users.csv generated'
|
28
|
+
end
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
|
32
|
+
if opts['h'] || !email || !password
|
33
|
+
puts <<-EOS
|
34
|
+
Usage: chatwork_to_slack
|
35
|
+
-i your chatwork id -p your chatwork password
|
36
|
+
-e room id (export specified room's chat logs)
|
37
|
+
-x room id (export specified room's chat logs and download attachment files)
|
38
|
+
-c slack channel name
|
39
|
+
-d dir
|
40
|
+
-k chatwork API key (if --generate-template)
|
41
|
+
-h help
|
42
|
+
--generate-template generate users.csv
|
43
|
+
Example:
|
44
|
+
show room list
|
45
|
+
$ chatwork_to_slack -i example@example.com -p your_password
|
46
|
+
export specified room's chat logs (-e: chat logs only)
|
47
|
+
$ chatwork_to_slack -i example@example.com -p your_password -e room_id -c slack_channel_name
|
48
|
+
export specified room's chat logs (-x: chat logs and attachment files)
|
49
|
+
$ chatwork_to_slack -i example@example.com -p your_password -x room_id -c slack_channel_name
|
50
|
+
EOS
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
|
54
|
+
gcw = GoodbyeChatwork::Client.new(email, password, verbose: true)
|
55
|
+
|
56
|
+
users =
|
57
|
+
if File.exists?('users.csv')
|
58
|
+
CSV.table('users.csv').map {|t| t.to_h }
|
59
|
+
else
|
60
|
+
gcw.info '[warning] users.csv not found'
|
61
|
+
[]
|
62
|
+
end
|
63
|
+
|
64
|
+
ChatWorkToSlack::Importer.new(
|
65
|
+
gcw,
|
66
|
+
room_id: opts['x'] || opts['e'],
|
67
|
+
channel: opts['c'],
|
68
|
+
workdir: opts['d'] || 'chatwork_to_slack_data',
|
69
|
+
export_files: !!opts['x'],
|
70
|
+
users: users,
|
71
|
+
chatwork_api_key: chatwork_api_key
|
72
|
+
)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chatwork_to_slack/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "chatwork_to_slack"
|
8
|
+
spec.version = ChatWorkToSlack::VERSION
|
9
|
+
spec.authors = ["kkosuge"]
|
10
|
+
spec.email = ["root@kksg.net"]
|
11
|
+
|
12
|
+
spec.summary = %q{export ChatWork(chatwork.com) logs to Slack CSV format}
|
13
|
+
spec.description = %q{export ChatWork(chatwork.com) logs to Slack CSV format}
|
14
|
+
spec.homepage = "https://github.com/kkosuge/chatwork_to_slack"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "bin"
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
|
28
|
+
spec.add_runtime_dependency "chatwork", "~> 0.3"
|
29
|
+
spec.add_runtime_dependency "goodbye_chatwork", "~> 0.0"
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ChatWorkToSlack
|
2
|
+
module Filters
|
3
|
+
class Dtext
|
4
|
+
TEMPLATE = {
|
5
|
+
task_added: "タスク追加",
|
6
|
+
file_uploaded: "ファイルアップロード",
|
7
|
+
chatroom_chat_edited: "チャット変更",
|
8
|
+
chatroom_member_is: "メンバー ",
|
9
|
+
chatroom_priv_changed: " を管理者にしました",
|
10
|
+
chatroom_added: " が入室しました",
|
11
|
+
chatroom_deleted: " が退室しました",
|
12
|
+
chatroom_leaved: " が退室しました",
|
13
|
+
chatroom_chatname_is: "チャット名を ",
|
14
|
+
chatroom_description_is: "説明文を ",
|
15
|
+
chatroom_changed: " に変更しました",
|
16
|
+
chatroom_set: " に設定しました",
|
17
|
+
chatroom_groupchat_created: "チャット作成",
|
18
|
+
task_done: "タスク終了",
|
19
|
+
nickname_suffix: " さん",
|
20
|
+
chatroom_over_groupchatnum: " は,制限により入室できません"
|
21
|
+
}
|
22
|
+
|
23
|
+
def self.call(text, options)
|
24
|
+
text.scan(/(\[dtext:([\w]+)\])/).each do |dtext|
|
25
|
+
if t = TEMPLATE[dtext[1].to_sym]
|
26
|
+
text.gsub!(dtext[0], t)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
text
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ChatWorkToSlack
|
2
|
+
module Filters
|
3
|
+
class Emoji
|
4
|
+
TABLE = {
|
5
|
+
':)' => ':grinning:',
|
6
|
+
':(' => ':weary:',
|
7
|
+
':D' => ':smiley:',
|
8
|
+
'8-)' => ':sunglasses:',
|
9
|
+
':o' => ':hushed:',
|
10
|
+
';)' => ':wink:',
|
11
|
+
';(' => ':cry:',
|
12
|
+
'(sweat)' => ':sweat:',
|
13
|
+
':|' => ':neutral_face:',
|
14
|
+
':*' => ':kissing_heart:',
|
15
|
+
':p' => ':stuck_out_tongue_winking_eye:',
|
16
|
+
'(blush)' => ':relaxed:',
|
17
|
+
':^)' => ':thinking_face:',
|
18
|
+
'|-)' => ':sleeping:',
|
19
|
+
'(inlove)' => ':heart_eyes:',
|
20
|
+
']:)' => ':triumph:',
|
21
|
+
'(talk)' => ':open_mouth:',
|
22
|
+
'(yawn)' => ':astonished:',
|
23
|
+
'(puke)' => ':hankey:',
|
24
|
+
'(emo)' => ':sunglasses:',
|
25
|
+
'8-|' => ':nerd_face:',
|
26
|
+
':#)' => ':grin:',
|
27
|
+
'(nod)' => ':grin::slightly_smiling_face:',
|
28
|
+
'(shake)' => 'confused:',
|
29
|
+
'(^^;)' => ':sweat:',
|
30
|
+
'(whew)' => ':sweat:',
|
31
|
+
'(clap)' => ':clap:',
|
32
|
+
'(bow)' => ':bow:',
|
33
|
+
'(roger)' => ':hand:',
|
34
|
+
'(flex)' => ':muscle:',
|
35
|
+
'(dance)' => ':raised_hands:',
|
36
|
+
'(:/)' => ':spock-hand:',
|
37
|
+
'(devil)' => ':smiling_imp:',
|
38
|
+
'(*)' => ':star:',
|
39
|
+
'(h)' => ':heart:',
|
40
|
+
'(F)' => ':sunflower:',
|
41
|
+
'(cracker)' => ':tada:',
|
42
|
+
'(^)' => ':birthday:',
|
43
|
+
'(coffee)' => ':coffee:',
|
44
|
+
'(beer)' => ':beer:',
|
45
|
+
'(handshake)' => ':spock-hand:',
|
46
|
+
'(y)' => ':+1:',
|
47
|
+
}
|
48
|
+
|
49
|
+
def self.call(text, options)
|
50
|
+
TABLE.each {|c, s| text.gsub!(c, s)}
|
51
|
+
text
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ChatWorkToSlack
|
2
|
+
module Filters
|
3
|
+
class Picon
|
4
|
+
def self.call(text, options)
|
5
|
+
return text unless options[:users]
|
6
|
+
|
7
|
+
text.scan(/(\[piconname:([\w]+)\])/).each do |picon|
|
8
|
+
user = options[:users].find {|cw| cw[:chatwork_account_id] == picon[1].to_i }
|
9
|
+
next unless user
|
10
|
+
member =
|
11
|
+
if user[:slack_name]
|
12
|
+
"#{user[:chatwork_name]} ( @#{user[:slack_name]} )"
|
13
|
+
else
|
14
|
+
user[:chatwork_name]
|
15
|
+
end
|
16
|
+
text.gsub!(picon[0], member)
|
17
|
+
end
|
18
|
+
|
19
|
+
text.scan(/(\[picon:([\w]+)\])/).each do |picon|
|
20
|
+
text.gsub!(picon[0], '')
|
21
|
+
end
|
22
|
+
text
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ChatWorkToSlack
|
2
|
+
module Filters
|
3
|
+
class Pre
|
4
|
+
def self.call(text, options)
|
5
|
+
title_regexp = /(\[info\](\[title\]([\p{Hiragana}\p{Katakana}\p{Han}。、\w\s ]+)\[\/title\]))/
|
6
|
+
text.scan(title_regexp).each do |title|
|
7
|
+
text.gsub!(title[0], "*#{title[2]}*\n#{title[0]}")
|
8
|
+
text.gsub!(title[1], '')
|
9
|
+
end
|
10
|
+
text
|
11
|
+
.gsub(/\[code\]/, "```")
|
12
|
+
.gsub(/\[\/code\]/, "```")
|
13
|
+
.gsub(/\[info\]/, "```\n")
|
14
|
+
.gsub(/\[\/info\]/, "\n```")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module ChatWorkToSlack
|
2
|
+
module Filters
|
3
|
+
class Quote
|
4
|
+
attr_reader :users, :chatwork_users
|
5
|
+
def initialize(users)
|
6
|
+
@users = users
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.call(text, options)
|
10
|
+
new(options[:users]).call(text)
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(text)
|
14
|
+
qts = text.scan(/(\[qt\].+\[\/qt\])/m)
|
15
|
+
return text if qts.empty?
|
16
|
+
|
17
|
+
quotes =
|
18
|
+
if text.scan(/\[qt\]/m).size > 1
|
19
|
+
text.split(/\[\/qt\]/).map{|t| "#{t}[/qt]".scan(/(\[qt\].+\[\/qt\])/m)[0]}.compact.map(&:first)
|
20
|
+
else
|
21
|
+
qts.first
|
22
|
+
end
|
23
|
+
|
24
|
+
result = text
|
25
|
+
quotes.each do |quote|
|
26
|
+
result.gsub!(quote,qtmeta(quote).split("\n").map{|t| ">#{t}"}.join("\n").gsub(/\[\/?qt\]/,''))
|
27
|
+
end
|
28
|
+
result
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def qtmeta(text)
|
34
|
+
q = text.scan(/\[qtmeta.+\]/).first
|
35
|
+
qh = q.scan(/([\w]+)=([\d]+)/).to_h
|
36
|
+
time = Time.at(qh['time'].to_i)
|
37
|
+
user = users.find {|cw| cw[:chatwork_account_id] == qh['aid'].to_i }
|
38
|
+
return text unless user
|
39
|
+
text.gsub(q, "@#{user[:slack_name]}: #{time}\n")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module ChatWorkToSlack
|
2
|
+
module Filters
|
3
|
+
class Reply
|
4
|
+
attr_reader :users
|
5
|
+
def initialize(users)
|
6
|
+
@users = users
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.call(text, options)
|
10
|
+
new(options[:users]).call(text)
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(text)
|
14
|
+
replace_reply(replace_to(text))
|
15
|
+
end
|
16
|
+
|
17
|
+
def replace_to(text)
|
18
|
+
if data = text.match(/(\[To:([\d]+)\](?:[\w\s]+さん)?)/)
|
19
|
+
to_text = data[0]
|
20
|
+
account_id = data[2]
|
21
|
+
user = users.find {|cw| cw[:chatwork_account_id] == account_id.to_i }
|
22
|
+
|
23
|
+
if !user || !user[:slack_name]
|
24
|
+
return replace_to(text.gsub(to_text, to_text.gsub(/\[/, '(').gsub(/\]/, ')')))
|
25
|
+
end
|
26
|
+
|
27
|
+
replace_to(text.gsub(to_text, "@#{user[:slack_name]}"))
|
28
|
+
else
|
29
|
+
text
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def replace_reply(text)
|
34
|
+
if data = text.match(/\[rp[\s\w\-=]+\](?:[\w\s]+さん)?/)
|
35
|
+
to_text = data[0]
|
36
|
+
account_id = to_text.match(/aid=([\d]+)/)[1]
|
37
|
+
user = users.find {|cw| cw[:chatwork_account_id] == account_id.to_i }
|
38
|
+
|
39
|
+
if !user || !user[:slack_name]
|
40
|
+
return replace_reply(text.gsub(to_text, to_text.gsub(/\[/, '(').gsub(/\]/, ')')))
|
41
|
+
end
|
42
|
+
|
43
|
+
replace_reply(text.gsub(to_text, "@#{user[:slack_name]}"))
|
44
|
+
else
|
45
|
+
text
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'chatwork'
|
2
|
+
|
3
|
+
module ChatWorkToSlack
|
4
|
+
class Importer
|
5
|
+
attr_reader :room_id, :channel, :workdir, :export_files, :gcw, :c2s, :users, :chatwork_api_key
|
6
|
+
def initialize(gcw, args)
|
7
|
+
@room_id = args[:room_id]
|
8
|
+
@channel = args[:channel]
|
9
|
+
@workdir = args[:workdir]
|
10
|
+
@export_files = args[:export_files]
|
11
|
+
@users = args[:users]
|
12
|
+
@chatwork_api_key = args[:chatwork_api_key]
|
13
|
+
@gcw = gcw
|
14
|
+
|
15
|
+
gcw.login
|
16
|
+
|
17
|
+
if !room_id || !channel
|
18
|
+
chatwork_list
|
19
|
+
else
|
20
|
+
create_workdir
|
21
|
+
export
|
22
|
+
convert
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def chatwork_list
|
27
|
+
puts gcw.room_list.map { |i| i.join(' ') }
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_workdir
|
31
|
+
unless File.exists?(workdir)
|
32
|
+
gcw.info "mkdir #{workdir}"
|
33
|
+
FileUtils.mkdir_p(workdir)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def export
|
38
|
+
if export_files
|
39
|
+
gcw.export_csv(room_id, chatwork_csv_path, { include_file: true, dir: chatwork_files_path })
|
40
|
+
else
|
41
|
+
gcw.export_csv(room_id, chatwork_csv_path)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def chatwork_csv_path
|
46
|
+
File.join(workdir, "#{room_id}.csv")
|
47
|
+
end
|
48
|
+
|
49
|
+
def chatwork_files_path
|
50
|
+
File.join(workdir, "#{room_id}_files")
|
51
|
+
end
|
52
|
+
|
53
|
+
def slack_csv_path
|
54
|
+
File.join(workdir, "#{channel}.csv")
|
55
|
+
end
|
56
|
+
|
57
|
+
def convert
|
58
|
+
gcw.info "create #{slack_csv_path}"
|
59
|
+
File.write(slack_csv_path, c2s.to_csv)
|
60
|
+
end
|
61
|
+
|
62
|
+
def c2s
|
63
|
+
@c2s ||= ChatWorkToSlack::Client.new(
|
64
|
+
room_id: room_id,
|
65
|
+
channel: channel,
|
66
|
+
workdir: workdir,
|
67
|
+
users: users,
|
68
|
+
chatwork_csv_path: chatwork_csv_path,
|
69
|
+
chatwork_api_key: chatwork_api_key
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "chatwork_to_slack/filters/dtext"
|
2
|
+
require "chatwork_to_slack/filters/emoji"
|
3
|
+
require "chatwork_to_slack/filters/picon"
|
4
|
+
require "chatwork_to_slack/filters/pre"
|
5
|
+
require "chatwork_to_slack/filters/reply"
|
6
|
+
require "chatwork_to_slack/filters/quote"
|
7
|
+
|
8
|
+
module ChatWorkToSlack
|
9
|
+
class Message
|
10
|
+
attr_reader :channel, :users
|
11
|
+
def initialize(args)
|
12
|
+
chatwork_message = args[:message]
|
13
|
+
@time = chatwork_message[0]
|
14
|
+
@name = chatwork_message[1]
|
15
|
+
@text = chatwork_message[2]
|
16
|
+
@users = args[:users]
|
17
|
+
@channel = args[:channel]
|
18
|
+
@chatwork_users = args[:chatwork_users]
|
19
|
+
end
|
20
|
+
|
21
|
+
def time
|
22
|
+
Time.parse(@time).to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
def name
|
26
|
+
if @name.match(/\A[\d]+\Z/)
|
27
|
+
user = @users.find{|u| u[:chatwork_account_id] == @name.to_i}
|
28
|
+
else
|
29
|
+
user = @users.find{|u| u[:chatwork_name] == @name}
|
30
|
+
end
|
31
|
+
|
32
|
+
if !!user
|
33
|
+
user[:slack_name] || @name
|
34
|
+
else
|
35
|
+
@name
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def text
|
40
|
+
options = { users: users }
|
41
|
+
filters.inject(@text) {|text, filter| filter.call(text, options)}
|
42
|
+
end
|
43
|
+
|
44
|
+
def filters
|
45
|
+
[
|
46
|
+
ChatWorkToSlack::Filters::Dtext,
|
47
|
+
ChatWorkToSlack::Filters::Emoji,
|
48
|
+
ChatWorkToSlack::Filters::Picon,
|
49
|
+
ChatWorkToSlack::Filters::Pre,
|
50
|
+
ChatWorkToSlack::Filters::Reply,
|
51
|
+
ChatWorkToSlack::Filters::Quote,
|
52
|
+
]
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_slack
|
56
|
+
[time, channel, name, text]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require "chatwork_to_slack/version"
|
2
|
+
require "chatwork_to_slack/message"
|
3
|
+
require "chatwork_to_slack/importer"
|
4
|
+
require "find"
|
5
|
+
require "csv"
|
6
|
+
|
7
|
+
module ChatWorkToSlack
|
8
|
+
class Client
|
9
|
+
attr_reader :room_id, :channel, :workdir, :chatwork_csv_path, :users, :chatwork_api_key
|
10
|
+
|
11
|
+
def initialize(args)
|
12
|
+
@room_id = args[:room_id]
|
13
|
+
@channel = args[:channel]
|
14
|
+
@workdir = args[:workdir]
|
15
|
+
@users = args[:users]
|
16
|
+
@chatwork_csv_path = args[:chatwork_csv_path]
|
17
|
+
@chatwork_api_key = args[:chatwork_api_key]
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_csv
|
21
|
+
invalid_users.each do |name|
|
22
|
+
puts "[WARN] #{name} is not valid slack username"
|
23
|
+
end
|
24
|
+
|
25
|
+
CSV.generate do |csv|
|
26
|
+
slack_messages.each do |slack_message|
|
27
|
+
csv << slack_message
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def generate_template
|
33
|
+
CSV.generate do |csv|
|
34
|
+
csv << ['chatwork_account_id', 'chatwork_name', 'slack_name']
|
35
|
+
chatwork_users.each do |u|
|
36
|
+
csv << [u['account_id'], u['name'], u['chatwork_id']]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def chatwork_users
|
44
|
+
@chatwork_users ||= ->{
|
45
|
+
return [] unless chatwork_api_key
|
46
|
+
ChatWork.api_key = chatwork_api_key
|
47
|
+
ChatWork::Contacts.get.push(ChatWork::Me.get)
|
48
|
+
}.call
|
49
|
+
end
|
50
|
+
|
51
|
+
def channel
|
52
|
+
@channel
|
53
|
+
end
|
54
|
+
|
55
|
+
def chatwork_messages
|
56
|
+
CSV.read(chatwork_csv_path)
|
57
|
+
end
|
58
|
+
|
59
|
+
def invalid_users
|
60
|
+
slack_messages.map{|m| m[2]}.uniq.reject{|u| u.gsub(/[0-9]/,'').match(/[\w\.\-]+/)}
|
61
|
+
end
|
62
|
+
|
63
|
+
def valid_messages
|
64
|
+
chatwork_messages.reject do |message|
|
65
|
+
message[2] == '[deleted]'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def messages
|
70
|
+
valid_messages.map do |message|
|
71
|
+
Message.new(
|
72
|
+
message: message,
|
73
|
+
users: users,
|
74
|
+
channel: channel
|
75
|
+
).to_slack
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def slack_messages
|
80
|
+
messages.sort{|a, b| a[0] <=> b[0]}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chatwork_to_slack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kkosuge
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: chatwork
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.3'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: goodbye_chatwork
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.0'
|
83
|
+
description: export ChatWork(chatwork.com) logs to Slack CSV format
|
84
|
+
email:
|
85
|
+
- root@kksg.net
|
86
|
+
executables:
|
87
|
+
- chatwork_to_slack
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/chatwork_to_slack
|
97
|
+
- chatwork_to_slack.gemspec
|
98
|
+
- lib/chatwork_to_slack.rb
|
99
|
+
- lib/chatwork_to_slack/filters/dtext.rb
|
100
|
+
- lib/chatwork_to_slack/filters/emoji.rb
|
101
|
+
- lib/chatwork_to_slack/filters/picon.rb
|
102
|
+
- lib/chatwork_to_slack/filters/pre.rb
|
103
|
+
- lib/chatwork_to_slack/filters/quote.rb
|
104
|
+
- lib/chatwork_to_slack/filters/reply.rb
|
105
|
+
- lib/chatwork_to_slack/importer.rb
|
106
|
+
- lib/chatwork_to_slack/message.rb
|
107
|
+
- lib/chatwork_to_slack/version.rb
|
108
|
+
homepage: https://github.com/kkosuge/chatwork_to_slack
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.4.5.1
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: export ChatWork(chatwork.com) logs to Slack CSV format
|
132
|
+
test_files: []
|
133
|
+
has_rdoc:
|