summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Worrall <Daniel.Worrall@hotmail.co.uk>2019-05-19 03:35:03 +0100
committerDaniel Worrall <Daniel.Worrall@hotmail.co.uk>2019-05-19 03:35:03 +0100
commit616c9608fc4ff6a5a1fd5f96e80e5682a3cdbee6 (patch)
tree6e7e530e9f0948138962e3ac847bdf8035bf5c33 /src
parent549a2cd77231b2317a7bbc1db5e7fda1bf2866fb (diff)
downloadtwitch-616c9608fc4ff6a5a1fd5f96e80e5682a3cdbee6.tar.gz
twitch-616c9608fc4ff6a5a1fd5f96e80e5682a3cdbee6.zip
message bucket and parts
Diffstat (limited to 'src')
-rw-r--r--src/twitch/irc.cr9
1 files changed, 9 insertions, 0 deletions
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"