feat: add support for NoChatReports encryption

This commit is contained in:
2025-03-04 20:23:41 -05:00
parent 426c19304d
commit c4454fe217
9 changed files with 341 additions and 25 deletions

View File

@@ -4,6 +4,8 @@ use crate::{
};
use azalea::{brigadier::prelude::*, chat::ChatPacket, prelude::*};
use futures::lock::Mutex;
use mlua::{Function, Table};
use ncr::utils::prepend_header;
pub type Ctx = CommandContext<Mutex<CommandSource>>;
@@ -11,16 +13,24 @@ pub struct CommandSource {
pub client: Client,
pub message: ChatPacket,
pub state: State,
pub ncr_options: Option<Table>,
}
impl CommandSource {
pub fn reply(&self, message: &str) {
for chunk in message
for mut chunk in message
.chars()
.collect::<Vec<char>>()
.chunks(236)
.chunks(if self.ncr_options.is_some() { 150 } else { 236 })
.map(|chars| chars.iter().collect::<String>())
{
if let (Some(options), Ok(encrypt)) = (
&self.ncr_options,
self.state.lua.globals().get::<Function>("ncr_encrypt"),
) && let Ok(encrypted) = encrypt.call::<String>((options, prepend_header(&chunk)))
{
chunk = encrypted
}
self.client.chat(
&(if self.message.is_whisper()
&& let Some(username) = self.message.username()