mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2025-04-20 11:59:53 +08:00
Compare commits
No commits in common. "780c9aee8de89c35dd5d867eb188091df6671549" and "b286765213d1b557c2c3c061db00bb766f93b29d" have entirely different histories.
780c9aee8d
...
b286765213
|
@ -51,13 +51,11 @@ pub struct UpdateDMConverse {
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub type Writeable<T> = Arc<RwLock<T>>;
|
pub type Writeable<T> = Arc<RwLock<T>>;
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct BotStatus {
|
pub struct BotStatus {
|
||||||
user_id: UserId,
|
user_id: UserId,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
impl BotStatus {
|
impl BotStatus {
|
||||||
pub fn new(user_id: UserId) -> Self { Self { user_id } }
|
pub fn new(user_id: UserId) -> Self { Self { user_id } }
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::error::{ClientResult, IcaError};
|
||||||
use crate::{version_str, StopGetter};
|
use crate::{version_str, StopGetter};
|
||||||
|
|
||||||
/// icalingua 客户端的兼容版本号
|
/// icalingua 客户端的兼容版本号
|
||||||
pub const ICA_PROTOCOL_VERSION: &str = "2.12.21";
|
pub const ICA_PROTOCOL_VERSION: &str = "2.12.20";
|
||||||
|
|
||||||
pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientResult<(), IcaError> {
|
pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientResult<(), IcaError> {
|
||||||
let span = span!(Level::INFO, "Icalingua Client");
|
let span = span!(Level::INFO, "Icalingua Client");
|
||||||
|
|
|
@ -43,6 +43,7 @@ pub async fn delete_message(client: &Client, message: &DeleteMessage) -> bool {
|
||||||
/// ```
|
/// ```
|
||||||
// #[allow(dead_code)]
|
// #[allow(dead_code)]
|
||||||
// pub async fn fetch_history(client: &Client, roomd_id: RoomId) -> bool { false }
|
// pub async fn fetch_history(client: &Client, roomd_id: RoomId) -> bool { false }
|
||||||
|
|
||||||
async fn inner_sign(payload: Payload, client: Client) -> ClientResult<(), IcaError> {
|
async fn inner_sign(payload: Payload, client: Client) -> ClientResult<(), IcaError> {
|
||||||
let span = span!(Level::INFO, "signing icalingua");
|
let span = span!(Level::INFO, "signing icalingua");
|
||||||
let _guard = span.enter();
|
let _guard = span.enter();
|
||||||
|
|
|
@ -187,7 +187,7 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client) {
|
||||||
"closeLoading", // 发送消息/加载新聊天 有一个 loading
|
"closeLoading", // 发送消息/加载新聊天 有一个 loading
|
||||||
"renewMessage", // 我也不确定到底是啥事件
|
"renewMessage", // 我也不确定到底是啥事件
|
||||||
"requestSetup", // 需要登录
|
"requestSetup", // 需要登录
|
||||||
"updateRoom", // 更新房间
|
"updateRoom",
|
||||||
];
|
];
|
||||||
match &event {
|
match &event {
|
||||||
Event::Custom(event_name) => {
|
Event::Custom(event_name) => {
|
||||||
|
|
|
@ -95,15 +95,8 @@ macro_rules! async_any_callback_with_state {
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
#[tokio::main]
|
||||||
tokio::runtime::Builder::new_multi_thread()
|
async fn main() -> anyhow::Result<()> { inner_main().await }
|
||||||
.enable_all()
|
|
||||||
.thread_name("shenbot-rs")
|
|
||||||
.worker_threads(4)
|
|
||||||
.build()
|
|
||||||
.unwrap()
|
|
||||||
.block_on(inner_main())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn inner_main() -> anyhow::Result<()> {
|
async fn inner_main() -> anyhow::Result<()> {
|
||||||
// -d -> debug
|
// -d -> debug
|
||||||
|
|
|
@ -64,14 +64,6 @@ pub fn verify_and_reload_plugins() {
|
||||||
let mut need_reload_files: Vec<PathBuf> = Vec::new();
|
let mut need_reload_files: Vec<PathBuf> = Vec::new();
|
||||||
let plugin_path = MainStatus::global_config().py().plugin_path.clone();
|
let plugin_path = MainStatus::global_config().py().plugin_path.clone();
|
||||||
|
|
||||||
// 先检查是否有插件被删除
|
|
||||||
for path in PyStatus::get_map_mut().keys() {
|
|
||||||
if !path.exists() {
|
|
||||||
event!(Level::INFO, "Python 插件: {:?} 已被删除", path);
|
|
||||||
PyStatus::delete_file(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for entry in std::fs::read_dir(plugin_path).unwrap().flatten() {
|
for entry in std::fs::read_dir(plugin_path).unwrap().flatten() {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
if let Some(ext) = path.extension() {
|
if let Some(ext) = path.extension() {
|
||||||
|
@ -84,7 +76,7 @@ pub fn verify_and_reload_plugins() {
|
||||||
if need_reload_files.is_empty() {
|
if need_reload_files.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event!(Level::INFO, "更改列表: {:?}", need_reload_files);
|
info!("file change list: {:?}", need_reload_files);
|
||||||
let exist_plugins = PyStatus::get_map_mut();
|
let exist_plugins = PyStatus::get_map_mut();
|
||||||
for reload_file in need_reload_files {
|
for reload_file in need_reload_files {
|
||||||
if let Some(plugin) = exist_plugins.get_mut(&reload_file) {
|
if let Some(plugin) = exist_plugins.get_mut(&reload_file) {
|
||||||
|
|
|
@ -73,12 +73,7 @@ impl TailchatClientPy {
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_startup_time(&self) -> SystemTime { crate::MainStatus::get_startup_time() }
|
pub fn get_startup_time(&self) -> SystemTime { crate::MainStatus::get_startup_time() }
|
||||||
#[pyo3(signature = (content, converse_id, group_id = None))]
|
#[pyo3(signature = (content, converse_id, group_id = None))]
|
||||||
pub fn new_message(
|
pub fn new_message(&self, content: String, converse_id: ConverseId, group_id: Option<GroupId>) -> TailchatSendingMessagePy {
|
||||||
&self,
|
|
||||||
content: String,
|
|
||||||
converse_id: ConverseId,
|
|
||||||
group_id: Option<GroupId>,
|
|
||||||
) -> TailchatSendingMessagePy {
|
|
||||||
TailchatSendingMessagePy {
|
TailchatSendingMessagePy {
|
||||||
message: SendingMessage::new(content, converse_id, group_id, None),
|
message: SendingMessage::new(content, converse_id, group_id, None),
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,9 @@ impl PyStatus {
|
||||||
pub fn add_file(path: PathBuf, plugin: PyPlugin) { Self::get_map_mut().insert(path, plugin); }
|
pub fn add_file(path: PathBuf, plugin: PyPlugin) { Self::get_map_mut().insert(path, plugin); }
|
||||||
|
|
||||||
/// 删除一个插件
|
/// 删除一个插件
|
||||||
pub fn delete_file(path: &PathBuf) -> Option<PyPlugin> { Self::get_map_mut().remove(path) }
|
pub fn delete_file(path: &PathBuf) -> Option<PyPlugin> {
|
||||||
|
Self::get_map_mut().remove(path)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn verify_file(path: &PathBuf) -> bool {
|
pub fn verify_file(path: &PathBuf) -> bool {
|
||||||
Self::get_map().get(path).map_or(false, |plugin| plugin.verifiy())
|
Self::get_map().get(path).map_or(false, |plugin| plugin.verifiy())
|
||||||
|
@ -50,13 +52,11 @@ impl PyStatus {
|
||||||
|
|
||||||
pub fn get_map() -> &'static PyPlugins {
|
pub fn get_map() -> &'static PyPlugins {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = &raw const PYSTATUS.files;
|
match PYSTATUS.files.as_ref() {
|
||||||
let ptr = &*ptr;
|
|
||||||
match ptr.as_ref() {
|
|
||||||
Some(files) => files,
|
Some(files) => files,
|
||||||
None => {
|
None => {
|
||||||
Self::init();
|
Self::init();
|
||||||
ptr.as_ref().unwrap()
|
PYSTATUS.files.as_ref().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,13 +64,11 @@ impl PyStatus {
|
||||||
|
|
||||||
pub fn get_map_mut() -> &'static mut PyPlugins {
|
pub fn get_map_mut() -> &'static mut PyPlugins {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = &raw mut PYSTATUS.files;
|
match PYSTATUS.files.as_mut() {
|
||||||
let ptr = &mut *ptr;
|
|
||||||
match ptr {
|
|
||||||
Some(files) => files,
|
Some(files) => files,
|
||||||
None => {
|
None => {
|
||||||
Self::init();
|
Self::init();
|
||||||
ptr.as_mut().unwrap()
|
PYSTATUS.files.as_mut().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,13 +76,11 @@ impl PyStatus {
|
||||||
|
|
||||||
pub fn get_config() -> &'static config::PluginConfigFile {
|
pub fn get_config() -> &'static config::PluginConfigFile {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = &raw const PYSTATUS.config;
|
match PYSTATUS.config.as_ref() {
|
||||||
let ptr = &*ptr;
|
|
||||||
match ptr {
|
|
||||||
Some(config) => config,
|
Some(config) => config,
|
||||||
None => {
|
None => {
|
||||||
Self::init();
|
Self::init();
|
||||||
ptr.as_ref().unwrap()
|
PYSTATUS.config.as_ref().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,13 +88,11 @@ impl PyStatus {
|
||||||
|
|
||||||
pub fn get_config_mut() -> &'static mut config::PluginConfigFile {
|
pub fn get_config_mut() -> &'static mut config::PluginConfigFile {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = &raw mut PYSTATUS.config;
|
match PYSTATUS.config.as_mut() {
|
||||||
let ptr = &mut *ptr;
|
|
||||||
match ptr {
|
|
||||||
Some(config) => config,
|
Some(config) => config,
|
||||||
None => {
|
None => {
|
||||||
Self::init();
|
Self::init();
|
||||||
ptr.as_mut().unwrap()
|
PYSTATUS.config.as_mut().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,37 +44,20 @@ impl BotStatus {
|
||||||
unsafe { MAIN_STATUS.startup_time.unwrap() }
|
unsafe { MAIN_STATUS.startup_time.unwrap() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn global_config() -> &'static BotConfig {
|
pub fn global_config() -> &'static BotConfig { unsafe { MAIN_STATUS.config.as_ref().unwrap() } }
|
||||||
unsafe {
|
|
||||||
let ptr = &raw const MAIN_STATUS.config;
|
|
||||||
(*ptr).as_ref().unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn global_ica_status() -> &'static ica::MainStatus {
|
pub fn global_ica_status() -> &'static ica::MainStatus {
|
||||||
unsafe {
|
unsafe { MAIN_STATUS.ica_status.as_ref().unwrap() }
|
||||||
let ptr = &raw const MAIN_STATUS.ica_status;
|
|
||||||
(*ptr).as_ref().unwrap()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn global_tailchat_status() -> &'static tailchat::MainStatus {
|
pub fn global_tailchat_status() -> &'static tailchat::MainStatus {
|
||||||
unsafe {
|
unsafe { MAIN_STATUS.tailchat_status.as_ref().unwrap() }
|
||||||
let ptr = &raw const MAIN_STATUS.tailchat_status;
|
|
||||||
(*ptr).as_ref().unwrap()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn global_ica_status_mut() -> &'static mut ica::MainStatus {
|
pub fn global_ica_status_mut() -> &'static mut ica::MainStatus {
|
||||||
unsafe {
|
unsafe { MAIN_STATUS.ica_status.as_mut().unwrap() }
|
||||||
let ptr = &raw mut MAIN_STATUS.ica_status;
|
|
||||||
(*ptr).as_mut().unwrap()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn global_tailchat_status_mut() -> &'static mut tailchat::MainStatus {
|
pub fn global_tailchat_status_mut() -> &'static mut tailchat::MainStatus {
|
||||||
unsafe {
|
unsafe { MAIN_STATUS.tailchat_status.as_mut().unwrap() }
|
||||||
let ptr = &raw mut MAIN_STATUS.tailchat_status;
|
|
||||||
(*ptr).as_mut().unwrap()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user