diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-08-17 23:31:45 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-08-17 23:31:45 -0700 |
commit | e633d656e00fdac51f077eff827518848235e916 (patch) | |
tree | 0b40a60f95b219545d40fe709e11583ab9e3df6b /bocelli/core | |
download | bocelli-e633d656e00fdac51f077eff827518848235e916.tar.gz bocelli-e633d656e00fdac51f077eff827518848235e916.tar.xz |
Initial commit.
Diffstat (limited to 'bocelli/core')
-rw-r--r-- | bocelli/core/irc.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/bocelli/core/irc.rb b/bocelli/core/irc.rb new file mode 100644 index 0000000..4264e2d --- /dev/null +++ b/bocelli/core/irc.rb @@ -0,0 +1,53 @@ +require 'socket' + +module Bocelli + module Core + module IRC + def configure(host, port, nick, pass = nil) + @host = host + @port = port + @nick = nick + @pass = pass + + @socket = nil + end + + def connect(&block) + @socket = TCPSocket.new(@host, @port) + + sputs("PASS #{@pass}") if @pass + sputs("NICK #{@nick}") + sputs("USER #{@nick} 0 * :#{@nick}") + + instance_eval(&block) if block_given? + end + + def sgets + str = @socket.gets + str.chomp! unless str.nil? + + puts '<< ' + str.inspect + + str + end + + def sputs(str) + puts '>> ' + str.inspect + + @socket.puts(str) + end + + def pong(message) + sputs("PONG #{message}") + end + + def join(channel) + sputs("JOIN #{channel}") + end + + def privmsg(channel, message) + sputs("PRIVMSG #{channel} :#{message}") + end + end + end +end |