ellen-slack 0.0.4 → 0.1.0

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
2
  SHA1:
3
- metadata.gz: 7311839b4deb8e6f54145805aa7940d68bf3bed3
4
- data.tar.gz: 4e427701eebba663b89132bd1d634ebde50a3642
3
+ metadata.gz: 591a05bb1956b8711b726716791ed7098fce98fc
4
+ data.tar.gz: b8b837ca25ef27bf03a484d457f139eb0d743db9
5
5
  SHA512:
6
- metadata.gz: 59cd9a4615cf88fc3f6dc0b3fffaa2df4447d3774531b27354aee74e6f53ae8b209af84b500f6e4da9f29e177b16efddf00ec4307af19ede8eb7444c11b461b7
7
- data.tar.gz: 7ef007dc98c6cd697d647be6281e0d44ee58274c27f614f63b24524a8472d3d68fbb439543ad2cd429861b1e6f86004bc66a26a8844ed641aa3aa621ccadb22a
6
+ metadata.gz: 46f6688855ad460932359bc82c1c4210654327e5c01063928622b90c3227b745360a7b45008042acb0c83e711b0f213f1dca8bffe3281da65badbe01291e695f
7
+ data.tar.gz: eb2c369c9e0c1aad2a2ddba033b352dcfacf8b975cf0b7ae0ca123af991653bdb48bf9aeaa2290c67c1b628d69f05b92830af044cf833fd49afcd89cb8c311ed
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.1.0
2
+ * Use XMPP Gateway instead of IRC
3
+
1
4
  ## 0.0.4
2
5
  * Support Ellen v0.2.0
3
6
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  Slack adapter for [Ellen](https://github.com/r7kamura/ellen).
3
3
 
4
4
  ## Usage
5
- Note that you must enable the IRC gateway at https://my.slack.com/admin/settings.
5
+ See https://my.slack.com/admin/settings to enable XMPP Gateway on Slack.
6
6
 
7
7
  ```ruby
8
8
  # Gemfile
@@ -11,9 +11,8 @@ gem "ellen-slack"
11
11
 
12
12
  ## ENV
13
13
  ```
14
- SLACK_CHANNEL - Channel name the bot logs in at first
15
- SLACK_PASSWORD - Account's IRC password (See https://my.slack.com/account/gateways)
16
- SLACK_TEAM - Account's team name
17
- SLACK_USERNAME - Account's username, which must match the name on Slack account
18
- SLACK_NO_SSL - Pass 1 if you don't want to use SSL connection (optional)
14
+ SLACK_PASSWORD - Account's XMPP password
15
+ SLACK_ROOM - Room name to join in at first (e.g. general)
16
+ SLACK_TEAM - Account's team name (e.g. wonderland)
17
+ SLACK_USERNAME - Account's username (e.g. alice)
19
18
  ```
data/ellen-slack.gemspec CHANGED
@@ -16,8 +16,8 @@ Gem::Specification.new do |spec|
16
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.add_dependency "ellen", ">= 0.2.0"
20
- spec.add_dependency "zircon", ">= 0.0.8"
19
+ spec.add_dependency "ellen", ">= 0.2.2"
20
+ spec.add_dependency "xrc", ">= 0.0.3"
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
22
  spec.add_development_dependency "rake"
23
23
  end
@@ -1,16 +1,12 @@
1
- require "zircon"
2
- require "yaml"
1
+ require "xrc"
3
2
 
4
3
  module Ellen
5
4
  module Adapters
6
5
  class Slack < Base
7
- INTERVAL = 0.1
8
-
9
- env :SLACK_CHANNEL, "Channel name the bot logs in at first"
10
- env :SLACK_PASSWORD, "Account's IRC password (See https://my.slack.com/account/gateways)"
11
- env :SLACK_TEAM, "Account's team name"
12
- env :SLACK_USERNAME, "Account's username, which must match the name on Slack account"
13
- env :SLACK_NO_SSL, "Pass 1 if you don't want to use SSL connection", optional: true
6
+ env :SLACK_PASSWORD, "Account's XMPP password (See https://tqhouse.slack.com/account/gateways)"
7
+ env :SLACK_ROOM, "Room name to join in at first (e.g. general)"
8
+ env :SLACK_TEAM, "Account's team name (e.g. wonderland)"
9
+ env :SLACK_USERNAME, "Account's username (e.g. alice)"
14
10
 
15
11
  def run
16
12
  bind
@@ -18,37 +14,43 @@ module Ellen
18
14
  end
19
15
 
20
16
  def say(message)
21
- to = message[:to]
22
- to = message[:from] if to == robot.name
23
- message[:body].split("\n").each do |line|
24
- client.privmsg(to, ":#{line}")
25
- wait
26
- end
17
+ client.say(
18
+ body: message[:body],
19
+ from: message[:from],
20
+ to: message[:original][:type] == "chat" ? message[:to] : message[:to] + "/resource",
21
+ type: message[:original][:type],
22
+ )
27
23
  end
28
24
 
29
25
  private
30
26
 
31
27
  def client
32
- @client ||= Zircon.new(
33
- channel: channel,
28
+ @client ||= Xrc::Client.new(
29
+ jid: jid,
30
+ nickname: username,
34
31
  password: password,
35
- port: port,
36
- server: server,
37
- username: username,
38
- use_ssl: ssl,
32
+ room_jid: room_jid,
39
33
  )
40
34
  end
41
35
 
42
- def channel
43
- ENV["SLACK_CHANNEL"]
36
+ def jid
37
+ "#{username}@#{host}"
44
38
  end
45
39
 
46
- def port
47
- "6667"
40
+ def room_jid
41
+ "#{room}@#{room_host}"
48
42
  end
49
43
 
50
- def server
51
- "#{team}.irc.slack.com"
44
+ def host
45
+ "#{team}.xmpp.slack.com"
46
+ end
47
+
48
+ def room_host
49
+ "conference.#{host}"
50
+ end
51
+
52
+ def room
53
+ ENV["SLACK_ROOM"]
52
54
  end
53
55
 
54
56
  def username
@@ -63,26 +65,22 @@ module Ellen
63
65
  ENV["SLACK_TEAM"]
64
66
  end
65
67
 
66
- def ssl
67
- !ENV["SLACK_NO_SSL"]
68
- end
69
-
70
68
  def bind
71
- client.on_privmsg do |message|
72
- body = message.body.force_encoding("UTF-8")
73
- robot.receive(body: body, from: message.from, to: message.to)
74
- end
69
+ client.on_private_message(&method(:on_message))
70
+ client.on_room_message(&method(:on_message))
75
71
  end
76
72
 
77
73
  def connect
78
- client.run!
74
+ client.connect
79
75
  end
80
76
 
81
- # Wait for Slack IRC Gateway to process message queue.
82
- # If we send 2 messages in too short time,
83
- # sometimes the slack double-renders the first message by mistake.
84
- def wait
85
- sleep(INTERVAL)
77
+ def on_message(message)
78
+ robot.receive(
79
+ body: message.body,
80
+ from: message.from,
81
+ to: message.to,
82
+ type: message.type,
83
+ )
86
84
  end
87
85
  end
88
86
  end
@@ -1,5 +1,5 @@
1
1
  module Ellen
2
2
  module Slack
3
- VERSION = "0.0.4"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ellen-slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-27 00:00:00.000000000 Z
11
+ date: 2014-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ellen
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.0
19
+ version: 0.2.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.0
26
+ version: 0.2.2
27
27
  - !ruby/object:Gem::Dependency
28
- name: zircon
28
+ name: xrc
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.8
33
+ version: 0.0.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.8
40
+ version: 0.0.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement