Created
January 6, 2011 01:52
-
-
Save wagenet/767382 to your computer and use it in GitHub Desktop.
Counts the number of users in an IRC room
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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