Skip to content

Instantly share code, notes, and snippets.

@cfcosta
Created October 7, 2011 04:13
Show Gist options
  • Save cfcosta/1269428 to your computer and use it in GitHub Desktop.
Save cfcosta/1269428 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'socket'
require_relative 'lib/stewie/irc_protocol_parser'
nick = 'stewiebot'
server = 'irc.freenode.org'
channel = '#moarbottest'
port = 6667
class Client
def privmsg(from, host, to, message)
puts "Received message from #{from} (on #{to}): #{message}"
end
end
parser = Stewie::IrcProtocolParser.new
client = Client.new
TCPSocket.open(server, port) do |sock|
sock.print("USER #{nick} #{nick} #{nick} :StewieBot :)\r\n")
sock.print("NICK #{nick}\r\n")
sock.print("JOIN #{channel}\r\n")
while !sock.closed?
line = sock.readline.chomp
begin
sexp = parser.parse line
if sexp and client.respond_to? sexp[0]
client.send *sexp
else
p ((sexp) or line)
end
rescue
p line
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment