Created
July 26, 2023 15:55
-
-
Save antaz/78382e64dac62cf6e4c5e2cf2615df40 to your computer and use it in GitHub Desktop.
Throttle for IIRC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module IIRC | |
| module Throttle | |
| # ratio in seconds / messages | |
| def throttle_ratio | |
| 1/1r | |
| end | |
| def time | |
| @time ||= Time.now | |
| end | |
| module Verbs | |
| def msg(target, msg) | |
| sleep(throttle_ratio) while (Time.now - time) <= throttle_ratio | |
| super | |
| @time = Time.now | |
| end | |
| alias :say :msg | |
| end | |
| include Verbs | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment