Skip to content

Instantly share code, notes, and snippets.

@shurizzle
Forked from leejarvis/gist:889167
Created March 29, 2011 11:14
Show Gist options
  • Save shurizzle/892172 to your computer and use it in GitHub Desktop.
Save shurizzle/892172 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# who the fuck said Ruby couldn't be hacky, NEVER DO THIS IT IS STUPID
# AND DOING IT WRONG TOO
require 'socket'
# DEBUG {{{
class TCPSocket
alias __gets__ gets
def gets(*args)
$DEBUG ? [__gets__(*args)].each {|m| STDOUT.puts '<< ' + m }[0] : __gets__(*args)
end
alias __write__ write
def write(*args)
args.each {|m| STDOUT.puts '>> ' + m.to_s } if $DEBUG
__write__(*args)
end
end
# }}}
($s = TCPSocket.new(*ARGV[1, 2].map {|a| Integer(a) rescue a }) rescue nil) or puts("Usage: #$0 <nick> <server> <port>") or exit(1)
define_singleton_method(:w) {|*a| $s.write a.join("\r\n") + "\r\n"} && w("NICK #{ARGV[0]}", "USER #{ARGV[0]} 0 * :#{ARGV[0]}")
$s.gets[/PING :(.+)/] && w('PONG ' + $1) until $s.eof?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment