lita-chatwork 0.0.1
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 +17 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +48 -0
- data/Rakefile +6 -0
- data/lib/lita-chatwork.rb +7 -0
- data/lib/lita/adapters/chatwork.rb +56 -0
- data/lib/lita/adapters/chatwork/connector.rb +100 -0
- data/lib/lita/chatwork/version.rb +5 -0
- data/lita-chatwork.gemspec +29 -0
- data/locales/en.yml +4 -0
- data/spec/lita/adapters/chatwork_spec.rb +6 -0
- data/spec/spec_helper.rb +6 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d6575ccaa88c35ca8fb3c0a3b7673f4ee168ac25
|
4
|
+
data.tar.gz: 08da50225927f8539274f2055ef02d2c0b3828fe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3789936144967e129270d474fe0b0458f7a7cc39e983bb6ddff26f7cf9ed344dee6ecf57097d5c39143ca279fe3c2142e84471c7561458999e18361087c56f8a
|
7
|
+
data.tar.gz: aedc01703b928fcfc565894bfae653458b76d585d2028d6c5556be019492400acaaa2707c11148048909956858ffed95c1d233a2d38cae0d9fea1cb0a85682ff
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2015 t3-okada
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# lita-chatwork
|
2
|
+
|
3
|
+
A ChatWork adapter for Lita.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'lita-chatwork'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install lita-chatwork
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```
|
22
|
+
# Gemfile of your lita
|
23
|
+
|
24
|
+
source "https://rubygems.org"
|
25
|
+
|
26
|
+
gem 'lita', '~> 4.1.0'
|
27
|
+
gem "lita-chatwork"
|
28
|
+
gem "chatwork"
|
29
|
+
...
|
30
|
+
```
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
# lita_config.rb
|
34
|
+
|
35
|
+
Lita.configure do |config|
|
36
|
+
config.robot.adapter = :chatwork
|
37
|
+
config.adapters.chatwork.api_key = ENV['CHATWORK_API_KEY']
|
38
|
+
config.adapters.chatwork.interval = 5
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it ( http://github.com/tokada/lita-chatwork/fork )
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'lita'
|
2
|
+
require 'lita/adapters/chatwork/connector'
|
3
|
+
|
4
|
+
module Lita
|
5
|
+
module Adapters
|
6
|
+
class Chatwork < Adapter
|
7
|
+
config :api_key, type: String, required: true
|
8
|
+
config :interval, type: Fixnum, default: 5
|
9
|
+
config :with_reply, default: true # whether to include [rp] tag in reply message
|
10
|
+
config :debug, default: false
|
11
|
+
|
12
|
+
def initialize(robot)
|
13
|
+
super
|
14
|
+
@connector = Connector.new(robot,
|
15
|
+
api_key: config.api_key,
|
16
|
+
interval: config.interval,
|
17
|
+
with_reply: config.with_reply,
|
18
|
+
debug: config.debug,
|
19
|
+
)
|
20
|
+
end
|
21
|
+
attr_reader :connector
|
22
|
+
|
23
|
+
def join(room_id)
|
24
|
+
# NOT supported
|
25
|
+
end
|
26
|
+
|
27
|
+
def part(room_id)
|
28
|
+
# NOT YET supported
|
29
|
+
connector.part(room_id)
|
30
|
+
end
|
31
|
+
|
32
|
+
def set_topic(target, topic)
|
33
|
+
# NOT YET supported
|
34
|
+
connector.set_topic(target, topic)
|
35
|
+
end
|
36
|
+
|
37
|
+
def send_messages(target, strings)
|
38
|
+
connector.message(target, strings)
|
39
|
+
end
|
40
|
+
|
41
|
+
def run
|
42
|
+
connector.connect
|
43
|
+
robot.trigger(:connected)
|
44
|
+
sleep
|
45
|
+
rescue Interrupt
|
46
|
+
shut_down
|
47
|
+
end
|
48
|
+
|
49
|
+
def shut_down
|
50
|
+
robot.trigger(:disconnected)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
Lita.register_adapter(:chatwork, Chatwork)
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'chatwork'
|
3
|
+
|
4
|
+
module Lita
|
5
|
+
module Adapters
|
6
|
+
class Chatwork < Adapter
|
7
|
+
class Connector
|
8
|
+
attr_reader :robot
|
9
|
+
|
10
|
+
def initialize(robot, api_key: nil, interval: nil, with_reply: nil, debug: nil)
|
11
|
+
@robot = robot
|
12
|
+
@api_key = api_key
|
13
|
+
@interval = interval
|
14
|
+
@with_reply = with_reply
|
15
|
+
@debug = debug
|
16
|
+
end
|
17
|
+
|
18
|
+
def connect
|
19
|
+
raise "api_key is required." unless @api_key
|
20
|
+
ChatWork.api_key = @api_key
|
21
|
+
|
22
|
+
define_robot
|
23
|
+
|
24
|
+
loop do
|
25
|
+
wait
|
26
|
+
result = ChatWork::Room.get
|
27
|
+
if result.is_a?(ChatWork::APIError)
|
28
|
+
@logger.error "ChatWork::Room.get result: #{result} (#{result.message})"
|
29
|
+
break
|
30
|
+
end
|
31
|
+
|
32
|
+
joined_rooms = result.select{|r| r["sticky"] }
|
33
|
+
unread_rooms = result.select{|r| r["unread_num"] > 0 }
|
34
|
+
(joined_rooms | unread_rooms).each do |r|
|
35
|
+
wait
|
36
|
+
result = ChatWork::Message.get(room_id: r["room_id"])
|
37
|
+
next if result.is_a?(ChatWork::APIError) and result.message == "204"
|
38
|
+
result.each do |m|
|
39
|
+
next if m["account"]["account_id"] == @me["account_id"]
|
40
|
+
user = Lita::User.find_by_id(m["account"]["account_id"])
|
41
|
+
unless user
|
42
|
+
user = Lita::User.create(m["account"]["account_id"],
|
43
|
+
m["account"].merge("mention_name" =>
|
44
|
+
"[To:#{m["account"]["account_id"]}] #{m["account"]["name"]}さん"))
|
45
|
+
end
|
46
|
+
source_id = [r["room_id"], m["message_id"], m["send_time"], m["update-time"]].join("-")
|
47
|
+
case r["type"]
|
48
|
+
when "my"
|
49
|
+
next
|
50
|
+
when "direct"
|
51
|
+
source = Lita::Source.new(user: user, room: source_id, private_message: true)
|
52
|
+
else # "group"
|
53
|
+
source = Lita::Source.new(user: user, room: source_id)
|
54
|
+
end
|
55
|
+
message = Lita::Message.new(robot, m["body"], source)
|
56
|
+
message.command! if source.private_message?
|
57
|
+
message.command! if message.body =~ /#{@robot.mention_name}/
|
58
|
+
message.command! if message.body =~ /\[(?:rp|返信) aid=#{@me["account_id"]} to=\d+-\d+\]/
|
59
|
+
robot.receive(message)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def message(target, strings)
|
66
|
+
text = strings.join("\n")
|
67
|
+
room_id, message_id, send_time, update_time = target.room.split("-")
|
68
|
+
if target.user
|
69
|
+
reply_text = "[rp aid=#{target.user.id} to=#{room_id}-#{message_id}] #{target.user.name}さん\n#{text}"
|
70
|
+
ChatWork::Message.create(room_id: room_id, body: reply_text)
|
71
|
+
else
|
72
|
+
ChatWork::Message.create(room_id: room_id, body: text)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def set_topic(target, topic)
|
77
|
+
#TODO: support PUT /rooms/#{target.room}?name=#{topic}
|
78
|
+
end
|
79
|
+
|
80
|
+
def part(room_id)
|
81
|
+
#TODO: support DELETE /rooms/#{room_id}?action_type=leave
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def define_robot
|
87
|
+
begin
|
88
|
+
@me = ChatWork::Me.get
|
89
|
+
@robot.name = @me["name"]
|
90
|
+
@robot.mention_name = "[To:#{@me["account_id"]}]"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def wait
|
95
|
+
sleep @interval
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lita/chatwork/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lita-chatwork"
|
8
|
+
spec.version = Lita::Chatwork::VERSION
|
9
|
+
spec.authors = ["tokada"]
|
10
|
+
spec.email = ["ubiqnet@gmail.com"]
|
11
|
+
spec.description = %q{A ChatWork adapter for Lita.}
|
12
|
+
spec.summary = %q{A ChatWork adapter for Lita.}
|
13
|
+
spec.homepage = "https://github.com/tokada/lita-chatwork"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.metadata = { "lita_plugin_type" => "adapter" }
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_runtime_dependency "lita", ">= 4.1"
|
23
|
+
spec.add_runtime_dependency "chatwork", ">= 0.1.1"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rack-test"
|
28
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
29
|
+
end
|
data/locales/en.yml
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-chatwork
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tokada
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lita
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: chatwork
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-test
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '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.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.0
|
97
|
+
description: A ChatWork adapter for Lita.
|
98
|
+
email:
|
99
|
+
- ubiqnet@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- lib/lita-chatwork.rb
|
110
|
+
- lib/lita/adapters/chatwork.rb
|
111
|
+
- lib/lita/adapters/chatwork/connector.rb
|
112
|
+
- lib/lita/chatwork/version.rb
|
113
|
+
- lita-chatwork.gemspec
|
114
|
+
- locales/en.yml
|
115
|
+
- spec/lita/adapters/chatwork_spec.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
homepage: https://github.com/tokada/lita-chatwork
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata:
|
121
|
+
lita_plugin_type: adapter
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.0.2
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: A ChatWork adapter for Lita.
|
142
|
+
test_files:
|
143
|
+
- spec/lita/adapters/chatwork_spec.rb
|
144
|
+
- spec/spec_helper.rb
|