Skip to content

Instantly share code, notes, and snippets.

@shunirr
Created January 13, 2014 05:22
Show Gist options
  • Save shunirr/8395152 to your computer and use it in GitHub Desktop.
Save shunirr/8395152 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'ircp'
require 'pit'
require 'eventmachine'
class IrcClient < EM::Connection
def initialize(options)
@nick = options[:nick]
@user = options[:user] || @nick
@real = options[:real] || @nick
@pass = options[:pass]
end
def send(*args)
msg = Ircp::Message.new(*args)
puts msg.to_s
send_data msg.to_irc
end
def post_init
send 'PASS', @pass if @pass
send 'NICK', @nick
send 'USER', @user, '*', '*', @real
end
def unbind
end
def receive_data(data)
msg = Ircp.parse data
method = "on_#{msg.command.to_s.downcase}"
__send__ method, msg if respond_to? method
end
def on_ping(msg)
send 'PONG'
end
def on_privmsg(msg)
puts msg.to_s
end
def on_notice(msg)
puts msg.to_s
end
end
options = {
host: '127.0.0.1',
port: 6667,
nick: 'shunirr',
}
EM.run do
Signal.trap("INT") { EM.stop }
Signal.trap("TERM") { EM.stop }
EM.connect(options[:host], options[:port], IrcClient, options)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment