diff options
author | Daniel Worrall <Daniel.Worrall@hotmail.co.uk> | 2019-05-20 19:28:36 +0100 |
---|---|---|
committer | Daniel Worrall <Daniel.Worrall@hotmail.co.uk> | 2019-05-20 19:28:36 +0100 |
commit | 873780d9374f5e5e31e66ab86fb021aafab9608d (patch) | |
tree | 280bb641da2ffe974b2b2d104af10701817cddae /src | |
parent | 616c9608fc4ff6a5a1fd5f96e80e5682a3cdbee6 (diff) | |
download | twitch-873780d9374f5e5e31e66ab86fb021aafab9608d.tar.gz twitch-873780d9374f5e5e31e66ab86fb021aafab9608d.zip |
add minor logs and fix tags
Diffstat (limited to 'src')
-rw-r--r-- | src/twitch/irc.cr | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/twitch/irc.cr b/src/twitch/irc.cr index d6033e4..8fe0d22 100644 --- a/src/twitch/irc.cr +++ b/src/twitch/irc.cr @@ -6,12 +6,13 @@ class Twitch::IRC private getter socket : IO private getter limiter : RateLimiter(String) private getter tags : Array(String) + private getter log_mode : Bool - def self.new(nick : String, token : String) - new(TCPSocket.new("irc.chat.twitch.tv", 6667), nick, token) + def self.new(nick : String, token : String, log_mode = false) + new(TCPSocket.new("irc.chat.twitch.tv", 6667), nick, token, log_mode: log_mode) end - def initialize(@socket : IO, @nick : String, @token : String) + def initialize(@socket : IO, @nick : String, @token : String, @log_mode : Bool) @limiter = RateLimiter(String).new @tags = [] of String limiter.bucket(:join, 50_u32, 15.seconds) @@ -50,6 +51,7 @@ class Twitch::IRC end def dispatch(message : FastIRC::Message) + puts "> " + message.to_s if log_mode case message.command when "PING" pong @@ -70,7 +72,7 @@ class Twitch::IRC private def request_tags @tags.each do |tag| - raw_write("CAP REQ", [":twitch.tv/#{tag}"]) + raw_write("CAP", ["REQ", "twitch.tv/#{tag}"]) end end @@ -85,6 +87,7 @@ class Twitch::IRC end private def raw_write(command, params, prefix = nil, tags = nil) + puts "< " + FastIRC::Message.new(command, params, prefix: prefix, tags: tags).to_s if log_mode FastIRC::Message.new(command, params, prefix: prefix, tags: tags).to_s(socket) end end |