Created
October 7, 2011 04:13
-
-
Save cfcosta/1269428 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/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