classicube_helpers/
chat.rs1use std::cell::Cell;
2
3use classicube_sys::{Chat_Send, OwnedString};
4use tracing::info;
5
6thread_local!(
7 static SIMULATING: Cell<bool> = const { Cell::new(false) };
8);
9
10pub fn print<S: Into<String>>(s: S) {
11 let s: String = s.into();
12 info!("{}", s);
13
14 let s = if s.len() > 255 {
15 let mut s = s;
16 s.truncate(255);
17 s
18 } else {
19 s
20 };
21
22 SIMULATING.set(true);
23
24 let owned_string = OwnedString::new(s);
25 unsafe {
26 classicube_sys::Chat_Add(owned_string.as_cc_string());
27 }
28
29 SIMULATING.set(false);
30}
31
32pub fn send<S: Into<String>>(s: S) {
33 let s = s.into();
34 info!("{}", s);
35
36 let owned_string = OwnedString::new(s);
37 unsafe {
38 Chat_Send(owned_string.as_cc_string(), 0);
39 }
40}