perf(commands): move ncr data to binding

This commit is contained in:
Ryan 2025-04-28 20:49:14 -04:00
parent 505b1a26af
commit 64c96450a4
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3

View File

@ -19,14 +19,17 @@ pub struct CommandSource {
impl CommandSource { impl CommandSource {
pub fn reply(&self, message: &str) { pub fn reply(&self, message: &str) {
let ncr_data = self
.ncr_options
.as_ref()
.zip(self.state.lua.globals().get::<Function>("ncr_encrypt").ok());
for mut chunk in message for mut chunk in message
.chars() .chars()
.collect::<Vec<char>>() .collect::<Vec<char>>()
.chunks(if self.ncr_options.is_some() { 150 } else { 236 }) .chunks(if self.ncr_options.is_some() { 150 } else { 236 })
.map(|chars| chars.iter().collect::<String>()) .map(|chars| chars.iter().collect::<String>())
{ {
if let Some(options) = &self.ncr_options if let Some((options, ref encrypt)) = ncr_data
&& let Ok(encrypt) = self.state.lua.globals().get::<Function>("ncr_encrypt")
&& let Ok(ciphertext) = encrypt.call::<String>((options, prepend_header(&chunk))) && let Ok(ciphertext) = encrypt.call::<String>((options, prepend_header(&chunk)))
{ {
chunk = ciphertext; chunk = ciphertext;