Skip to content

Instantly share code, notes, and snippets.

@wagenet
Created January 6, 2011 01:52
Show Gist options
  • Save wagenet/767382 to your computer and use it in GitHub Desktop.
Save wagenet/767382 to your computer and use it in GitHub Desktop.
Counts the number of users in an IRC room
#!/usr/local/bin/ruby
require "socket"
irc = TCPSocket.open('irc.freenode.net', 6667)
irc.send("USER blah blah blah :blah blah\n", 0)
irc.send("NICK ChanScanBot\n", 0)
irc.send("JOIN #sproutcore\n", 0)
names = []
until irc.eof?
data = irc.gets
break if data =~ /^:\S+ 366/ # End of NAMES
if data =~ /^:\S+ 353/ # NAMES
names += data.split(':').last.split(' ')
end
end
names.delete_if{|n| n =~ /ChanScanBot/}
irc.send("QUIT\n", 0)
puts "#{names.count} Users"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment