diff --git a/src/commands.rs b/src/commands.rs index 455c227..ecb40a3 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -24,12 +24,11 @@ impl CommandSource { .chunks(if self.ncr_options.is_some() { 150 } else { 236 }) .map(|chars| chars.iter().collect::()) { - if let (Some(options), Ok(encrypt)) = ( - &self.ncr_options, - self.state.lua.globals().get::("ncr_encrypt"), - ) && let Ok(encrypted) = encrypt.call::((options, prepend_header(&chunk))) + if let Some(options) = &self.ncr_options + && let Ok(encrypt) = self.state.lua.globals().get::("ncr_encrypt") + && let Ok(ciphertext) = encrypt.call::((options, prepend_header(&chunk))) { - chunk = encrypted; + chunk = ciphertext; } self.client.chat( &(if self.message.is_whisper() diff --git a/src/events.rs b/src/events.rs index 2c34bef..6e26b76 100644 --- a/src/events.rs +++ b/src/events.rs @@ -28,15 +28,16 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow: if let Some(sender) = sender { let mut ncr_options = None; - if let (Ok(options), Ok(decrypt)) = ( - globals.get::("NcrOptions"), - globals.get::("ncr_decrypt"), - ) && let Ok(decrypted) = - decrypt.call::((options.clone(), content.clone())) - && let Ok(trimmed) = trim_header(&decrypted) + if let Ok(options) = globals.get::
("NcrOptions") + && let Ok(decrypt) = globals.get::("ncr_decrypt") + && let Some(plaintext) = decrypt + .call::((options.clone(), content.clone())) + .ok() + .as_deref() + .and_then(|s| trim_header(s).ok()) { ncr_options = Some(options); - trimmed.clone_into(&mut content); + plaintext.clone_into(&mut content); info!("decrypted message from {sender}: {content}"); }