From 616c9608fc4ff6a5a1fd5f96e80e5682a3cdbee6 Mon Sep 17 00:00:00 2001 From: Daniel Worrall Date: Sun, 19 May 2019 03:35:03 +0100 Subject: message bucket and parts --- src/twitch/irc.cr | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/twitch/irc.cr b/src/twitch/irc.cr index 0aa42ea..d6033e4 100644 --- a/src/twitch/irc.cr +++ b/src/twitch/irc.cr @@ -15,6 +15,7 @@ class Twitch::IRC @limiter = RateLimiter(String).new @tags = [] of String limiter.bucket(:join, 50_u32, 15.seconds) + limiter.bucket(:message, 20_u32, 30.seconds) end def run(channels : Array(String)) @@ -27,6 +28,9 @@ class Twitch::IRC end def message(channel : String, message : String) + return unless @connected + wait = limiter.rate_limited?(:message, channel) + sleep(wait) if wait.is_a?(Time::Span) raw_write("PRIVMSG", [channel, message]) end @@ -40,6 +44,11 @@ class Twitch::IRC raw_write("JOIN", ["##{channel}"]) end + def leave_channel(channel : String) + return unless @connected + raw_write("PART", ["##{channel}"]) + end + def dispatch(message : FastIRC::Message) case message.command when "PING" -- cgit v1.2.3