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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
require "http/web_socket"
require "json"
require "pretty_print"
settings = Hash(String, String).new
settings["home"] = Path.home.to_s
settings["access_token"] = File.read( settings["home"] + "/.config/twitch/access_token" ).chomp
settings["client_id"] = File.read( settings["home"] + "/.config/twitch/client_id" ).chomp
settings["channel"] = File.read( settings["home"] + "/.config/twitch/channel" ).chomp
settings["channel_id"] = File.read( settings["home"] + "/.config/twitch/channel_id" ).chomp
def pubsub_send ( settings, pubsub : HTTP::WebSocket, msg )
pubsub.send( msg )
puts( ("SENT : " + msg).gsub(/#{settings["access_token"]}/,"NOPE").gsub(/#{settings["client_id"]}/, "NOPE") )
end
def ircmsg( home : String, channel : String, msg : String)
if msg !~ /(\r|\n)/
sock = Socket.unix
# sock.connect Socket::UNIXAddress.new( home + "/.irssi/twitch-socket".to_s, type: Socket::Type::DGRAM )
sock.connect Socket::UNIXAddress.new( home + "/.irssi/twitch-socket".to_s )
sock.puts( "#" + channel + " " + msg )
sock.close
end
end
def effectsmsg( msg : String )
sock = Socket.unix
sock.connect Socket::UNIXAddress.new( "/etc/twitch/effects-socket" )
sock.puts( msg )
sock.close
rescue ex
STDERR.puts( ex )
end
msg_ping = {
"type" => "PING"
}.to_json.to_s
struct Nil
def as_s?
self
end
end
spawn do
loop do
begin
obs_pubsub = HTTP::WebSocket.new( URI.parse( "ws://127.0.0.1:4444/" ), HTTP::Headers{"Cookie" => "SESSIONID=1234"} )
obs_pubsub.on_message do | message |
print( "RECEIVED: ")
json = JSON.parse( message )
print( json.to_pretty_json )
print( "\n")
case json["update-type"]?
when "SwitchScenes"
ircmsg( settings["home"], settings["channel"], "| obs: switched scene to " + ( json["scene-name"]?.as_s? || "unknown" ) )
end
end
obs_pubsub.run
rescue ex
ircmsg( settings["home"], settings["channel"], "obs.cr: " + ex.to_s.gsub(/\r|\n/, ' ') )
puts ex
obs_pubsub && obs_pubsub.close
end
sleep 10
next
end
end
loop do
sleep 10
end
#RECEIVED: {
# "type": "MESSAGE",
# "data": {
# "topic": "channel-subscribe-events-v1.59895482",
# "message": "{\"benefit_end_month\":0,\"user_name\":\"orangesherbet\",\"display_name\":\"orangesherbet\",\"channel_name\":\"bungmonkey\",\"user_id\":\"36184711\",\"channel_id\":\"59895482\",\"time\":\"2020-05-06T06:55:31.362125005Z\",\"sub_message\":{\"message\":\"seqDag bungmoButt bungmoFart\",\"emotes\":[{\"start\":0,\"end\":5,\"id\":\"496082\"},{\"start\":7,\"end\":16,\"id\":\"300780134\"},{\"start\":18,\"end\":27,\"id\":\"301501910\"}]},\"sub_plan\":\"1000\",\"sub_plan_name\":\"5\",\"months\":0,\"cumulative_months\":21,\"context\":\"resub\"}"
# }
#}
#
|