//! /sentance/ use super::*; pub async fn body(state: State, num: Option, mut output: mpsc::Sender) -> Result<(), gen::GenBodyError> { let string = { let chain = state.chain().read().await; if chain.is_empty() { return Ok(()); } match num { None => chain.generate_str(), Some(num) => (0..num).map(|_| chain.generate_str()).join("\n"), } }; debug!("Taking {:?} from {:?}" ,num, string); let filter = state.outbound_filter(); if let Some(num) = num { for sen in sanitise::Sentance::new_iter(&string).take(num) { output.send(filter.filter_owned(sen.to_owned())).await.map_err(|e| gen::GenBodyError(e.0))?; } } else { output.send(filter.filter_owned(match sanitise::Sentance::new_iter(&string) .max_by_key(|x| x.len()) { Some(x) => x, #[cold] None => return Ok(()), }.to_owned())).await.map_err(|e| gen::GenBodyError(e.0))?; } Ok(()) }