烦死了!哼!

This commit is contained in:
shenjack 2024-06-03 23:52:16 +08:00
parent 996d2a327f
commit 9ccb7ad02c
Signed by: shenjack
GPG Key ID: 7B1134A979775551
5 changed files with 29 additions and 66 deletions

View File

@ -87,7 +87,7 @@ class IcaSendMessage:
class IcaDeleteMessage:
def __str__(self):
def __str__(self) -> str:
...

View File

@ -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:
@ -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)

View File

@ -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");

View File

@ -48,8 +48,11 @@ async fn main() {
// none -> info
let level = {
let args = std::env::args();
if args.collect::<Vec<String>>().contains(&"-d".to_string()) {
let args = args.collect::<Vec<String>>();
if args.contains(&"-d".to_string()) {
Level::DEBUG
} else if args.contains(&"-t".to_string()) {
Level::TRACE
} else {
Level::INFO
}

View File

@ -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<Packet, Error> {
// 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