Skip to content

Commit dbfbc4e

Browse files
committed
Add RocketChat as input handler
1 parent 4d613fd commit dbfbc4e

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.gem
2+
Gemfile.lock
23
*.rbc
34
/.config
45
/coverage/

Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec

lib/xify.rb

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require 'xify/input/pipe'
44
require 'xify/input/prompt'
5+
require 'xify/input/rocket_chat'
56
require 'xify/input/shell'
67
require 'xify/output/stdout'
78
require 'xify/output/rocket_chat'

lib/xify/input/rocket_chat.rb

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'eventmachine'
2+
require 'json'
3+
require 'metybur'
4+
require 'net/https'
5+
require 'time'
6+
7+
require 'xify/base/rocket_chat'
8+
9+
module Input
10+
class RocketChat < Base::RocketChat
11+
def updates
12+
login
13+
14+
EM.run do
15+
config = @config
16+
uri = URI.parse config['uri']
17+
meteor = Metybur.connect "wss://#{uri.host}:#{uri.port}/websocket"
18+
meteor.login resume: @auth_data['authToken'] do
19+
meteor.subscribe 'stream-notify-user', "#{result[:id]}/rooms-changed", false
20+
messages = meteor.collection 'stream-notify-user'
21+
messages.on(:changed) do |id, attributes|
22+
event = attributes[:args].last
23+
room = event[:name]
24+
message = event[:lastMessage]
25+
26+
next if message[:editedAt] || room != config['channel'][1..-1]
27+
28+
author = message[:u][:name]
29+
text = message[:msg]
30+
time = message[:ts][:'$date']
31+
type = event[:t] == 'p' ? 'group' : 'channel'
32+
33+
yield Event.new author, text, parent: "##{room}", parent_link: "#{config['uri']}/#{type}/#{room}", time: Time.at(time / 1000)
34+
end
35+
end
36+
end
37+
end
38+
end
39+
end

xify.gemspec

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
Gem::Specification.new do |s|
22
s.name = 'xify'
3-
s.version = '0.1.0'
3+
s.version = '0.2.0'
44
s.date = '2018-05-11'
55
s.summary = 'Cross-post content from one service to another.'
66
s.description = 'Cross-post content from one service to another.'
77
s.author = 'Finn Glöe'
88
s.email = '[email protected]'
99
s.files = Dir['lib/**/*.rb']
1010
s.executables << 'xify'
11+
12+
s.add_runtime_dependency 'metybur'
1113
end

0 commit comments

Comments
 (0)