Skip to content

Instantly share code, notes, and snippets.

@mediamagnet
Created July 22, 2018 20:08
Show Gist options
  • Save mediamagnet/216777171a5a096a73aa3db7ab1f03ec to your computer and use it in GitHub Desktop.
Save mediamagnet/216777171a5a096a73aa3db7ab1f03ec to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'eventmachine'
require 'websocket-eventmachine-client'
EM.run do
ws = WebSocket::EventMachine::Client.connect(:host => 'irc-ws.chat.twitch.tv', :port => 80, :ssl => false)
ws.onopen do
puts "Connected"
ws.send "CAP REQ :twitch.tv/tags twitch.tv/commands twitch.tv/membership"
ws.send "NICK justinfan#{rand(100000..999999)}"
ws.send "JOIN #dwangoac"
end
ws.onmessage do |msg, type|
if msg.include?('PING') == true
puts "Received message: #{msg.strip}"
ws.send "PONG :tmi.twitch.tv"
ws.pong
else
puts "Received message: #{msg.strip}"
end
end
ws.onclose do |code, reason|
puts "Disconnected with status code: #{code} #{reason}"
end
ws.onerror do |error|
puts "Error: #{error}"
end
ws.onping do |message|
puts "Ping received: #{message}"
ws.pong "PONG :tmi.twitch.tv"
end
ws.onpong do |message|
puts "Pong sent: #{message}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment