diff --git a/src/service.rs b/src/service.rs index b202793..6d11801 100644 --- a/src/service.rs +++ b/src/service.rs @@ -38,7 +38,7 @@ impl Services { pub fn new(ctx: &Context, components: &Components, state: &State) -> Result { let keyboard = Keyboard::new(); let rt = Runtime::new()?; - let quoter = Quoter::new(&rt, state.chat.quote.clone()); + let quoter = Quoter::new(&rt, state.chat.quote.clone(), state.chat.input.clone()); let is_chatting = Arc::new(AtomicBool::new(false)); let chat = Chat::new( keyboard.clone(), diff --git a/src/service/quoter.rs b/src/service/quoter.rs index 411fc0e..2fa702b 100644 --- a/src/service/quoter.rs +++ b/src/service/quoter.rs @@ -9,14 +9,18 @@ use crate::component::quote::Quoter as QuoterC; #[derive(Debug)] pub struct Quoter(AbortHandle); impl Quoter { - pub fn new(rt: &Runtime, quote: Arc>) -> Self { + pub fn new(rt: &Runtime, quote: Arc>, input: Arc>) -> Self { + *quote.write() = QuoterC::DEFAULT.into(); + let quoter = QuoterC; let abort_handle = rt .spawn(async move { loop { - // TODO: skip if the chat input is not empty. - - *quote.write() = quoter.fetch().await.unwrap_or(QuoterC::DEFAULT.into()); + if input.read().is_empty() { + if let Ok(quote_) = quoter.fetch().await { + *quote.write() = quote_; + } + } time::sleep(Duration::from_millis(30_000)).await; }