diff options
Diffstat (limited to 'irc.rb')
-rw-r--r-- | irc.rb | 40 |
1 files changed, 10 insertions, 30 deletions
@@ -1,5 +1,7 @@ require 'socket' +require_relative 'logger' + module Dinobot class IRC def initialize(server, port, nick, pass=nil) @@ -9,10 +11,11 @@ module Dinobot @pass = pass @socket = nil + @logger = Dinobot::Logger.instance end def connect - log :info, "Connecting to #{@server}:#{@port}." + @logger.info "Connecting to #{@server}:#{@port}." @socket = TCPSocket.new(@server, @port) @@ -32,17 +35,21 @@ module Dinobot def gets str = @socket.gets - log :in, str.inspect + @logger.in str.inspect str end def puts(str) - log :out, str.inspect + @logger.out str.inspect @socket.puts str end + def pong(message) + puts "PONG #{message}" + end + def join(channel) puts "JOIN #{channel}" end @@ -54,32 +61,5 @@ module Dinobot def privmsg(channel, message) puts "PRIVMSG #{channel} :#{message}" end - - def pong(message) - puts "PONG #{message}" - end - - private - - def log(type, *lines) - str = lines.join("\n") - - case type - when :in - prefix = "\e[32m<<\e[0m " - when :out - prefix = "\e[36m>>\e[0m " - when :error - prefix = "\e[31m!!\e[0m " - when :info - prefix = "\e[33m==\e[0m " - when :indent - prefix = ' ' - else - raise "unknown type specified -- #{type}" - end - - Kernel.puts str.gsub(/^/, prefix) - end end end |