From 27b504012e3802dabddd6219d5bc36d4fa0a4ff4 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Wed, 29 Nov 2023 22:11:12 -0500 Subject: [PATCH] [INIT] started helper functions (incomplete) --- src/helpers.rs | 40 ++++++++++++++++++++++++++++++++++++++++ src/main.rs | 4 ++++ 2 files changed, 44 insertions(+) create mode 100644 src/helpers.rs diff --git a/src/helpers.rs b/src/helpers.rs new file mode 100644 index 0000000..97b5a63 --- /dev/null +++ b/src/helpers.rs @@ -0,0 +1,40 @@ + +use std::time::Instant; +pub struct RateLimiter { + channels_attr: Vec, +} + + +struct RlAttributes { + channel: String, + enabled: bool, + start_time: Instant, + msg_counter: u32, +} + + + +impl RateLimiter { + pub fn new() -> Self { + Self { + channels_attr: vec![], + } + } + + pub fn sending_msg_to(&mut self, channelname: String) -> bool { + self.channels_attr.push(RlAttributes { + channel: channelname, + enabled: true, + start_time: Instant::now(), + msg_counter: 0, + }); + + let chanRateLimiter = self.channels_attr + .into_iter() + .filter(|r| r.channel == "Hello") + .collect(); + + chanRateLimiter.is_empty() + + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 9e877ae..5926d6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ + + use twitch_irc::login::StaticLoginCredentials; use twitch_irc::ClientConfig; use twitch_irc::SecureTCPTransport; @@ -7,6 +9,8 @@ use std::env; use std::time::Instant; use rand::Rng; +// mod helpers; + #[tokio::main] pub async fn main() { let login_name = "modulatingforcebot".to_owned();