diff --git a/ica-rs/ica_typing.py b/ica-rs/ica_typing.py index f710feb..b355ec1 100644 --- a/ica-rs/ica_typing.py +++ b/ica-rs/ica_typing.py @@ -87,7 +87,7 @@ class IcaSendMessage: class IcaDeleteMessage: - def __str__(self): + def __str__(self) -> str: ... @@ -153,7 +153,7 @@ class IcaClient: return self.send_message(message) def delete_message(self, message: IcaDeleteMessage) -> bool: ... - + @property def status(self) -> IcaStatus: ... @@ -200,7 +200,7 @@ class TailchatReciveMessage: @property def converse_id(self) -> TailchatType.ConverseId: ... - + class TailchatClient: diff --git a/ica-rs/plugins/bmcl.py b/ica-rs/plugins/bmcl.py index 8ee298b..9722165 100644 --- a/ica-rs/plugins/bmcl.py +++ b/ica-rs/plugins/bmcl.py @@ -4,6 +4,14 @@ import requests import traceback import urllib.parse +have_regexrs = False +try: + import regexrs + have_regexrs = True +except ImportError: + print("未找到 regexrs 模块, 将回退到字符串 in 操作") + have_regexrs = False + # import PIL from typing import TYPE_CHECKING, TypeVar, Optional, Tuple, List @@ -16,7 +24,7 @@ else: IcaNewMessage = TypeVar("NewMessage") IcaClient = TypeVar("IcaClient") -_version_ = "2.5.0-rs" +_version_ = "2.6.0-rs" backend_version = "unknown" def format_data_size(data_bytes: float) -> str: @@ -103,7 +111,7 @@ def bmcl_dashboard(msg: IcaNewMessage, client: IcaClient) -> None: online_bandwidth: int = data["bandwidth"] data_len = format_data_size(data_bytes) hits_count = format_hit_count(data_hits) - + report_msg = ( f"OpenBMCLAPI 面板v{_version_}-状态\n" f"api版本 {backend_version} commit:{backend_commit}\n" @@ -225,7 +233,12 @@ def bmcl_rank(msg: IcaNewMessage, client: IcaClient, name: str) -> None: r['index'] = i # 搜索是否有这个名字的节点 names: List[str] = [r["name"].lower() for r in rank_data] - finds = [name.lower() in n for n in names] + try: + import regexrs + pattern = regexrs.compile(name) + finds = [pattern.match(n) for n in names] + except Exception as e: + finds = [name.lower() in n for n in names] if not any(finds): reply = msg.reply_with(f"未找到名为{name}的节点") client.send_message(reply) diff --git a/ica-rs/src/ica.rs b/ica-rs/src/ica.rs index 0847297..39daf5e 100644 --- a/ica-rs/src/ica.rs +++ b/ica-rs/src/ica.rs @@ -10,7 +10,7 @@ use crate::config::IcaConfig; use crate::error::{ClientResult, IcaError}; use crate::{wrap_any_callback, wrap_callback, StopGetter}; -const ICA_PROTOCOL_VERSION: &str = "2.12.0"; +const ICA_PROTOCOL_VERSION: &str = "2.12.2"; pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientResult<(), IcaError> { let span = span!(Level::INFO, "Icalingua Client"); diff --git a/ica-rs/src/main.rs b/ica-rs/src/main.rs index 23cfe08..ab391e2 100644 --- a/ica-rs/src/main.rs +++ b/ica-rs/src/main.rs @@ -48,8 +48,11 @@ async fn main() { // none -> info let level = { let args = std::env::args(); - if args.collect::>().contains(&"-d".to_string()) { + let args = args.collect::>(); + if args.contains(&"-d".to_string()) { Level::DEBUG + } else if args.contains(&"-t".to_string()) { + Level::TRACE } else { Level::INFO } diff --git a/ica-rs/src/tailchat.rs b/ica-rs/src/tailchat.rs index 4f85e1b..403681a 100644 --- a/ica-rs/src/tailchat.rs +++ b/ica-rs/src/tailchat.rs @@ -3,9 +3,8 @@ pub mod events; use futures_util::FutureExt; use md5::{Digest, Md5}; -use reqwest::{Body, ClientBuilder as reqwest_ClientBuilder}; +use reqwest::ClientBuilder as reqwest_ClientBuilder; use rust_socketio::asynchronous::{Client, ClientBuilder}; -// use rust_socketio::packet::PacketParser; use rust_socketio::{Event, Payload, TransportType}; use serde_json::{from_str, from_value, json, Value}; use tracing::{event, span, Level}; @@ -15,48 +14,6 @@ use crate::data_struct::tailchat::status::LoginData; use crate::error::{ClientResult, TailchatError}; use crate::{wrap_any_callback, wrap_callback, StopGetter}; -// mod packet_parser { -// use bytes::{buf, Bytes}; -// use rust_socketio::error::Error; -// use rust_socketio::packet::{Packet, PacketId}; -// use serde::{Deserialize, Serialize}; -// use serde_json::Value as JsonValue; -// use msgpack_simple::{MsgPack, MapElement} - -// // #[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] -// // #[serde(rename = "map")] -// // struct SerdeValue { -// // #[serde(rename = "@type")] -// // r#type: i64, -// // data: rmpv::Value, -// // nsp: String, -// // } - -// pub fn encode(packet: &Packet) -> Bytes { -// let raw_str = packet.data.as_ref().map(|v| v.to_string()).unwrap_or("{}".to_string()); -// let raw_value: rmpv::Value = serde_json::from_str(&raw_str).unwrap(); -// let value = SerdeValue { -// r#type: packet.packet_type as u8 as i64, -// data: raw_value, -// nsp: packet.nsp.clone(), -// }; -// let mut buffer = rmp_serde::to_vec(&value).unwrap(); -// println!("encoding packet: {:?} {:?}", packet, value); - -// buffer.reverse(); -// // 前面加上 \x83\xa4 -// buffer.push(0xa4); -// buffer.push(0x83); -// buffer.reverse(); -// Bytes::from(buffer) -// } - -// pub fn default_decode(payload: &Bytes) -> Result { -// println!("decoding bytes {:?}", payload); -// todo!() -// } -// } - pub async fn start_tailchat( config: TailchatConfig, stop_reciver: StopGetter, @@ -101,31 +58,21 @@ pub async fn start_tailchat( Err(e) => return Err(TailchatError::LoginFailed(e.to_string())), }; - // header_map.append("X-Token", status.jwt.clone().parse().unwrap()); - - // let packet_parser = - // PacketParser::new(Box::new(packet_parser::encode), Box::new(packet_parser::default_decode)); - let socket = ClientBuilder::new(config.host) .auth(json!({"token": status.jwt.clone()})) .transport_type(TransportType::Websocket) .on_any(wrap_any_callback!(events::any_event)) - // .on("connect", wrap_callback!(events::on_connect)) - // .on("chat.message.sendMessage", wrap_callback!(events::on_message)) + .on("chat.message.sendMessage", wrap_callback!(events::on_message)) .connect() .await .unwrap(); event!(Level::INFO, "tailchat connected"); + // sleep for 1 sec + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + socket.emit("chat.converse.findAndJoinRoom", json!([])).await.unwrap(); - socket - .emit( - "chat.message.sendMessage", - json!({"content": "shenbot v 0.1.0", "roomId": 1, "type": 1}), - ) - .await - .unwrap(); event!(Level::INFO, "tailchat joined room"); // notify:chat.message.delete