2024-03-14 01:12:08 +08:00
|
|
|
use crate::config::BotConfig;
|
2024-03-15 00:40:22 +08:00
|
|
|
use crate::MAIN_STATUS;
|
2024-03-14 01:12:08 +08:00
|
|
|
|
2024-03-15 00:40:22 +08:00
|
|
|
#[derive(Debug, Clone)]
|
2024-03-14 01:12:08 +08:00
|
|
|
pub struct BotStatus {
|
|
|
|
pub config: Option<BotConfig>,
|
|
|
|
pub ica_status: Option<ica::MainStatus>,
|
2024-03-30 16:59:06 +08:00
|
|
|
pub tailchat_status: Option<tailchat::MainStatus>,
|
2024-07-23 23:27:08 +08:00
|
|
|
pub startup_time: Option<std::time::SystemTime>,
|
2024-03-14 01:12:08 +08:00
|
|
|
}
|
|
|
|
|
2024-03-15 00:40:22 +08:00
|
|
|
impl BotStatus {
|
|
|
|
pub fn update_static_config(config: BotConfig) {
|
|
|
|
unsafe {
|
|
|
|
MAIN_STATUS.config = Some(config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub fn update_ica_status(status: ica::MainStatus) {
|
|
|
|
unsafe {
|
|
|
|
MAIN_STATUS.ica_status = Some(status);
|
|
|
|
}
|
|
|
|
}
|
2024-03-30 16:59:06 +08:00
|
|
|
pub fn update_tailchat_status(status: tailchat::MainStatus) {
|
|
|
|
unsafe {
|
|
|
|
MAIN_STATUS.tailchat_status = Some(status);
|
|
|
|
}
|
|
|
|
}
|
2024-03-15 00:40:22 +08:00
|
|
|
|
|
|
|
pub fn static_init(config: BotConfig) {
|
|
|
|
unsafe {
|
2024-03-15 01:03:24 +08:00
|
|
|
MAIN_STATUS.ica_status = Some(ica::MainStatus {
|
|
|
|
enable: config.check_ica(),
|
|
|
|
qq_login: false,
|
|
|
|
current_loaded_messages_count: 0,
|
|
|
|
rooms: Vec::new(),
|
|
|
|
online_status: ica::OnlineData::default(),
|
|
|
|
});
|
2024-03-15 00:40:22 +08:00
|
|
|
MAIN_STATUS.config = Some(config);
|
2024-07-23 23:27:08 +08:00
|
|
|
MAIN_STATUS.startup_time = Some(std::time::SystemTime::now());
|
2024-03-15 00:40:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-23 23:27:08 +08:00
|
|
|
pub fn get_startup_time() -> std::time::SystemTime {
|
|
|
|
unsafe { MAIN_STATUS.startup_time.unwrap() }
|
|
|
|
}
|
|
|
|
|
2024-10-01 19:13:28 +08:00
|
|
|
pub fn global_config() -> &'static BotConfig {
|
|
|
|
unsafe {
|
|
|
|
let ptr = &raw const MAIN_STATUS.config;
|
|
|
|
(*ptr).as_ref().unwrap()
|
|
|
|
}
|
|
|
|
}
|
2024-03-30 16:59:06 +08:00
|
|
|
|
2024-03-15 00:40:22 +08:00
|
|
|
pub fn global_ica_status() -> &'static ica::MainStatus {
|
2024-10-01 19:13:28 +08:00
|
|
|
unsafe {
|
|
|
|
let ptr = &raw const MAIN_STATUS.ica_status;
|
|
|
|
(*ptr).as_ref().unwrap()
|
|
|
|
}
|
2024-03-15 00:40:22 +08:00
|
|
|
}
|
2024-03-30 16:59:06 +08:00
|
|
|
pub fn global_tailchat_status() -> &'static tailchat::MainStatus {
|
2024-10-01 19:13:28 +08:00
|
|
|
unsafe {
|
|
|
|
let ptr = &raw const MAIN_STATUS.tailchat_status;
|
|
|
|
(*ptr).as_ref().unwrap()
|
|
|
|
}
|
2024-03-30 16:59:06 +08:00
|
|
|
}
|
2024-03-15 01:03:24 +08:00
|
|
|
|
|
|
|
pub fn global_ica_status_mut() -> &'static mut ica::MainStatus {
|
2024-10-01 19:13:28 +08:00
|
|
|
unsafe {
|
|
|
|
let ptr = &raw mut MAIN_STATUS.ica_status;
|
|
|
|
(*ptr).as_mut().unwrap()
|
|
|
|
}
|
2024-03-15 01:03:24 +08:00
|
|
|
}
|
2024-03-30 16:59:06 +08:00
|
|
|
pub fn global_tailchat_status_mut() -> &'static mut tailchat::MainStatus {
|
2024-10-01 19:13:28 +08:00
|
|
|
unsafe {
|
|
|
|
let ptr = &raw mut MAIN_STATUS.tailchat_status;
|
|
|
|
(*ptr).as_mut().unwrap()
|
|
|
|
}
|
2024-03-30 16:59:06 +08:00
|
|
|
}
|
2024-03-15 00:40:22 +08:00
|
|
|
}
|
|
|
|
|
2024-03-14 01:12:08 +08:00
|
|
|
pub mod ica {
|
2024-03-15 00:40:22 +08:00
|
|
|
use crate::data_struct::ica::all_rooms::Room;
|
2024-03-15 01:03:24 +08:00
|
|
|
pub use crate::data_struct::ica::online_data::OnlineData;
|
2024-03-15 00:40:22 +08:00
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct MainStatus {
|
|
|
|
/// 是否启用 ica
|
|
|
|
pub enable: bool,
|
|
|
|
/// qq 是否登录
|
|
|
|
pub qq_login: bool,
|
|
|
|
/// 当前已加载的消息数量
|
|
|
|
pub current_loaded_messages_count: u64,
|
|
|
|
/// 房间数据
|
|
|
|
pub rooms: Vec<Room>,
|
|
|
|
/// 在线数据 (Icalingua 信息)
|
|
|
|
pub online_status: OnlineData,
|
|
|
|
}
|
2024-03-15 01:03:24 +08:00
|
|
|
|
|
|
|
impl MainStatus {
|
|
|
|
pub fn update_rooms(&mut self, room: Vec<Room>) { self.rooms = room; }
|
|
|
|
pub fn update_online_status(&mut self, status: OnlineData) { self.online_status = status; }
|
|
|
|
}
|
2024-03-14 01:12:08 +08:00
|
|
|
}
|
2024-03-30 16:59:06 +08:00
|
|
|
|
|
|
|
pub mod tailchat {
|
|
|
|
use crate::data_struct::tailchat::UserId;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct MainStatus {
|
|
|
|
/// 是否启用 tailchat
|
|
|
|
pub enable: bool,
|
|
|
|
/// 是否登录
|
|
|
|
pub login: bool,
|
|
|
|
/// 用户 ID
|
|
|
|
pub user_id: UserId,
|
|
|
|
/// 昵称
|
|
|
|
pub nick_name: String,
|
|
|
|
/// 邮箱
|
|
|
|
pub email: String,
|
|
|
|
/// JWT Token
|
|
|
|
pub jwt_token: String,
|
|
|
|
/// avatar
|
|
|
|
pub avatar: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MainStatus {
|
|
|
|
pub fn update_user_id(&mut self, user_id: UserId) { self.user_id = user_id; }
|
|
|
|
pub fn update_nick_name(&mut self, nick_name: String) { self.nick_name = nick_name; }
|
|
|
|
pub fn update_email(&mut self, email: String) { self.email = email; }
|
|
|
|
pub fn update_jwt_token(&mut self, jwt_token: String) { self.jwt_token = jwt_token; }
|
|
|
|
pub fn update_avatar(&mut self, avatar: String) { self.avatar = avatar; }
|
|
|
|
}
|
|
|
|
}
|