forked from Akkiesoft/mikutodon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream.rb
34 lines (30 loc) · 952 Bytes
/
stream.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def stream(account, tl, tl_name, toots)
EM.run do
ws = Faye::WebSocket::Client.new(
"wss://#{account[:host]}/api/v1/streaming?access_token=#{account[:token]}&stream=#{tl}",
)
ws.on :open do |e|
activity :mikutodon_debug_message, "こねくと!"
$tl_close = false
end
ws.on :error do |e|
activity :mikutodon_debug_message, "えらー!\n#{e}"
end
ws.on :close do |e|
puts "connection close."
puts e
activity :mikutodon_debug_message, "こねくしょんくろーず!"
$tl_close = true
end
ws.on :message do |msg|
toot = JSON.parse(msg.data)
if toot["event"] == "update"
Plugin.call :extract_receive_message, tl_name, create_toot(toot["payload"])
elsif toot["event"] == "notification"
create_notification(toot["payload"])
else
puts toot
end
end
end
end