aboutsummaryrefslogtreecommitdiff
path: root/irc.rb
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-20 03:30:09 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-20 03:30:09 -0700
commit7e7aa3278a9e478b02eb152575fb00ee0802ac81 (patch)
tree4f7a6c1fafeae67500d3bfba5321ea5e2e571f18 /irc.rb
parented09327eac899b9d5a1f782616747ca13c4806b1 (diff)
downloaddinobot-7e7aa3278a9e478b02eb152575fb00ee0802ac81.tar.gz
dinobot-7e7aa3278a9e478b02eb152575fb00ee0802ac81.tar.xz
Add singleton logger class.
Diffstat (limited to 'irc.rb')
-rw-r--r--irc.rb40
1 files changed, 10 insertions, 30 deletions
diff --git a/irc.rb b/irc.rb
index 835694e..bb7146d 100644
--- a/irc.rb
+++ b/irc.rb
@@ -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