summaryrefslogtreecommitdiff
path: root/twitchpubsub.rb
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk@action.fairlystable.org>2019-10-27 23:31:51 -0700
committerJoe Rayhawk <jrayhawk@action.fairlystable.org>2019-10-27 23:31:51 -0700
commit93aebe7498b3f3bf5079e4f218072b0ec5ad9b6c (patch)
tree00e7c6af4563b910a715c842baa3c4e8a68e4822 /twitchpubsub.rb
parentc11cd7da47327b423f40c9cd54d2c8f9612cea5a (diff)
downloadtwitchtools-93aebe7498b3f3bf5079e4f218072b0ec5ad9b6c.tar.gz
twitchtools-93aebe7498b3f3bf5079e4f218072b0ec5ad9b6c.zip
Minor and incomplete changes to cope with autolog path changes and kraken v3 shutdown
Diffstat (limited to 'twitchpubsub.rb')
-rwxr-xr-xtwitchpubsub.rb12
1 files changed, 7 insertions, 5 deletions
diff --git a/twitchpubsub.rb b/twitchpubsub.rb
index c3f3994..cd02c14 100755
--- a/twitchpubsub.rb
+++ b/twitchpubsub.rb
@@ -15,6 +15,7 @@ ENV['XDG_CONFIG_HOME'] && confdir = ENV['XDG_CONFIG_HOME'] + '/twitch/'
access_token = IO.read( confdir + 'access_token' ).chomp || true
channel = IO.read( confdir + 'channel' ).chomp
+channel_id = IO.read( confdir + 'channel_id' ).chomp
client_id = IO.read( confdir + 'client_id' ).chomp
unix_socket_path = confdir + 'chat_socket'
@@ -22,7 +23,8 @@ http = Net::HTTP.new('api.twitch.tv', 443)
http.use_ssl = true
http.read_timeout = 10
-channel_id = JSON.parse(http.request(Net::HTTP::Get.new("/kraken/channels/#{channel}?client_id=#{client_id}")).body)['_id'].to_s
+# kraken broke
+#channel_id = JSON.parse(http.request(Net::HTTP::Get.new("/kraken/channels/#{channel}?client_id=#{client_id}")).body)['_id'].to_s
def normalize_twitch_pubsub_bullshit_data_because_seriously_fuck_twitch( parsed )
# Twitch may or may not have JSON-encoded this JSON because Twitch.
@@ -46,9 +48,9 @@ end
def dispatch_message( message, unix_socket_path )
unix_socket = UNIXSocket.new( unix_socket_path )
if message['context'] == 'subgift' then # Gifted subscription
- unix_socket.print( message['recipient_user_name'] + ' has subscribed for ' + (message['months'].to_i+1).to_s + ' months at sub level #' + message['sub_plan'] + 'thanks to a gift from ' + message['user_name'] + ': "' + message['sub_message']['message'] + "\"\n" )
+ unix_socket.print( message['recipient_user_name'] + ' has subscribed for ' + (message['cumulative_months'].to_i+1).to_s + ' months at sub level #' + message['sub_plan'] + 'thanks to a gift from ' + message['user_name'] + ': "' + message['sub_message']['message'] + "\"\n" )
elsif message['sub_plan'] then # Subscription
- unix_socket.print( message['user_name'] + ' has ' + message['context'] + 'scribed for ' + (message['months'].to_i+1).to_s + ' months at sub level #' + message['sub_plan'] + ': "' + message['sub_message']['message'] + "\"\n" )
+ unix_socket.print( message['user_name'] + ' has ' + message['context'] + 'scribed for ' + (message['cumulative_months'].to_i+1).to_s + ' months at sub level #' + message['sub_plan'] + ': "' + message['sub_message']['message'] + "\"\n" )
elsif message['item_description'] then # commerce
unix_socket.print( message['user_name'] + ' has purchased ' + message['item_description'] + ': "' + message['purchase_message']['message'] + "\"\n" )
elsif message['bits_used'] then # bits
@@ -102,14 +104,14 @@ t3 = Thread.new {
dispatch_message( message, unix_socket_path )
end
end
- rescue IO::WaitReadable, OpenSSL::SSL::SSLErrorWaitReadable, JSON::ParserError
+ rescue IO::WaitReadable, OpenSSL::SSL::SSLErrorWaitReadable, JSON::ParserError, EOFError, OpenSSL::SSL::SSLError
IO.select([tcp_socket])
retry
end
}
# sub_frame = <<-'EOF'
-# {"type":"MESSAGE","data":{"topic":"channel-subscribe-events-v1.59895482","message":"{\"user_name\":\"tobiidk\",\"display_name\":\"TobiiDK\",\"channel_name\":\"bungmonkey\",\"user_id\":\"22413536\",\"channel_id\":\"59895482\",\"time\":\"2017-07-12T11:21:07.118989503Z\",\"sub_message\":{\"message\":\"\",\"emotes\":null},\"sub_plan\":\"1000\",\"sub_plan_name\":\"Throw money at Bung\",\"months\":0,\"context\":\"sub\"}"}}
+#{"type"=>"MESSAGE","data"=>{"topic"=>"channel-subscribe-events-v1.59895482","message"=>"{\"user_name\":\"totalsunny\",\"display_name\":\"TotalSunny\",\"channel_name\":\"bungmonkey\",\"user_id\":\"47871268\",\"channel_id\":\"59895482\",\"time\":\"2019-04-27T12:47:26.023643965Z\",\"sub_message\":{\"message\":\"Greetings\",\"emotes\":null},\"sub_plan\":\"1000\",\"sub_plan_name\":\"5\",\"months\":0,\"cumulative_months\":7,\"context\":\"resub\"}"}}
# EOF
#
# sub_frame = <<-'EOF'