diff --git a/Cargo.lock b/Cargo.lock index d5584fb..6e03e58 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1720,6 +1720,7 @@ dependencies = [ "Inflector 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "codeforces 0.1.0 (git+https://github.com/natsukagami/rust-codeforces-api)", + "crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1776,6 +1777,7 @@ dependencies = [ name = "youmubot-prelude" version = "0.1.0" dependencies = [ + "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/youmubot-cf/Cargo.toml b/youmubot-cf/Cargo.toml index a2d0583..d3b8d33 100644 --- a/youmubot-cf/Cargo.toml +++ b/youmubot-cf/Cargo.toml @@ -15,6 +15,7 @@ regex = "1" lazy_static = "1" rayon = "1" chrono = { version = "0.4", features = ["serde"] } +crossbeam-channel = "0.4" youmubot-prelude = { path = "../youmubot-prelude" } youmubot-db = { path = "../youmubot-db" } diff --git a/youmubot-cf/src/announcer.rs b/youmubot-cf/src/announcer.rs index d1ce197..cefd788 100644 --- a/youmubot-cf/src/announcer.rs +++ b/youmubot-cf/src/announcer.rs @@ -39,6 +39,8 @@ fn update_user( user_id: UserId, cfu: &mut CfUser, ) -> CommandResult { + // Ensure this takes 200ms + let after = crossbeam_channel::after(std::time::Duration::from_secs_f32(0.2)); let info = User::info(reqwest, &[cfu.handle.as_str()])? .into_iter() .next() @@ -91,6 +93,7 @@ fn update_user( } } } + after.recv().ok(); Ok(()) } diff --git a/youmubot-osu/src/lib.rs b/youmubot-osu/src/lib.rs index 035cfea..0d453fa 100644 --- a/youmubot-osu/src/lib.rs +++ b/youmubot-osu/src/lib.rs @@ -41,7 +41,7 @@ impl Client { fn build_request(&self, r: RequestBuilder) -> Result { let v = r.query(&[("k", &*self.key)]).build()?; - dbg!(v.url()); + // dbg!(v.url()); Ok(self.client.execute(v)?) } diff --git a/youmubot-prelude/Cargo.toml b/youmubot-prelude/Cargo.toml index f15ce4a..bc2cf59 100644 --- a/youmubot-prelude/Cargo.toml +++ b/youmubot-prelude/Cargo.toml @@ -12,3 +12,4 @@ youmubot-db = { path = "../youmubot-db" } crossbeam-channel = "0.4" reqwest = "0.10" rayon = "1" +chrono = "0.4" diff --git a/youmubot-prelude/src/announcer.rs b/youmubot-prelude/src/announcer.rs index 62b50ab..99847bb 100644 --- a/youmubot-prelude/src/announcer.rs +++ b/youmubot-prelude/src/announcer.rs @@ -1,4 +1,5 @@ use crate::{AppData, GetCloned}; +use crossbeam_channel::after; use rayon::prelude::*; use serenity::{ framework::standard::{ @@ -153,12 +154,16 @@ impl AnnouncerHandler { let keys = self.announcers.keys().cloned().collect::>(); self.data.write().insert::(keys.clone()); spawn(move || loop { + eprintln!("{}: announcer started scanning", chrono::Utc::now()); + let after_timer = after(cooldown); for key in &keys { + eprintln!(" - scanning key `{}`", key); if let Err(e) = self.announce(key) { dbg!(e); } } - std::thread::sleep(cooldown); + eprintln!("{}: announcer finished scanning", chrono::Utc::now()); + after_timer.recv().ok(); }) } } diff --git a/youmubot/src/main.rs b/youmubot/src/main.rs index 307b490..8b35894 100644 --- a/youmubot/src/main.rs +++ b/youmubot/src/main.rs @@ -98,7 +98,7 @@ fn main() { println!("codeforces enabled."); client.with_framework(fw); - announcers.scan(std::time::Duration::from_secs(300)); + announcers.scan(std::time::Duration::from_secs(120)); println!("Starting..."); if let Err(v) = client.start() {