use super::{VerbContext, UserVerb, UserVerbRef, UResult, ItemSearchParams, user_error, get_player_item_or_fail, is_likely_explicit, search_item_for_user, parsing::parse_to_space}; use async_trait::async_trait; use ansi::{ignore_special_characters, ansi}; pub struct Verb; #[async_trait] impl UserVerb for Verb { async fn handle(self: &Self, ctx: &mut VerbContext, verb: &str, remaining: &str) -> UResult<()> { let (to_whom_name, say_what_raw) = if verb.starts_with("r") { let last_page_from = match ctx.user_dat.as_ref().and_then(|u| u.last_page_from.as_ref()) { None => user_error("No one has paged you, so you can't reply.".to_owned())?, Some(m) => (*m).clone() }; (last_page_from, remaining) } else { let (to_whom, say_what) = parse_to_space(remaining); (to_whom.to_owned(), say_what) }; let say_what = ignore_special_characters(&say_what_raw); if say_what == "" { user_error("You need to provide a message to send.".to_owned())?; } let player_item = get_player_item_or_fail(ctx).await?; if player_item.death_data.is_some() { user_error("Shush, the dead can't talk!".to_string())?; } let to_whom = search_item_for_user(ctx, &ItemSearchParams { include_active_players: true, limit: 1, ..ItemSearchParams::base(&player_item, &to_whom_name) }).await?; match to_whom.item_type.as_str() { "player" => {}, _ => user_error("Only players accept pages".to_string())? } ctx.trans.queue_for_session(ctx.session, Some(&format!( ansi!("You page {} on your wristpad: \"{}\"\n"), to_whom.display_for_session(&ctx.session_dat), say_what ))).await?; if player_item == to_whom { return Ok(()); } match to_whom.item_type.as_str() { "player" => { match ctx.trans.find_session_for_player(&to_whom.item_code).await? { None => user_error("That character is asleep.".to_string())?, Some((other_session, other_session_dets)) => { if other_session_dets.less_explicit_mode && is_likely_explicit(&say_what) { user_error("That player is on a client that doesn't allow explicit \ content, and your message looked explicit, so it wasn't sent." .to_owned())? } else { if let Some(mut user) = ctx.trans.find_by_username(&to_whom.item_code).await? { user.last_page_from = Some(player_item.item_code.clone()); ctx.trans.save_user_model(&user).await?; } ctx.trans.queue_for_session(&other_session, Some(&format!( ansi!("Your wristpad beeps with page from {}: \"{}\"\n"), player_item.display_for_session(&ctx.session_dat), say_what ))).await?; } } } }, _ => {} } Ok(()) } } static VERB_INT: Verb = Verb; pub static VERB: UserVerbRef = &VERB_INT as UserVerbRef;