This commit is contained in:
shenjack 2024-08-18 13:13:52 +08:00
parent 32f1797edc
commit 880fc4c5dd
Signed by: shenjack
GPG Key ID: 7B1134A979775551
8 changed files with 35 additions and 17 deletions

2
Cargo.lock generated
View File

@ -659,7 +659,7 @@ dependencies = [
[[package]] [[package]]
name = "ica-rs" name = "ica-rs"
version = "0.7.0" version = "0.7.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64 0.22.1", "base64 0.22.1",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "ica-rs" name = "ica-rs"
version = "0.7.0" version = "0.7.1"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -9,7 +9,7 @@ use crate::data_struct::ica::all_rooms::Room;
use crate::data_struct::ica::messages::{Message, MessageTrait, NewMessage}; use crate::data_struct::ica::messages::{Message, MessageTrait, NewMessage};
use crate::data_struct::ica::online_data::OnlineData; use crate::data_struct::ica::online_data::OnlineData;
use crate::ica::client::send_message; use crate::ica::client::send_message;
use crate::{help_msg, py, version_str, MainStatus, VERSION}; use crate::{client_id, help_msg, py, version_str, MainStatus, VERSION};
/// 获取在线数据 /// 获取在线数据
pub async fn get_online_data(payload: Payload, _client: Client) { pub async fn get_online_data(payload: Payload, _client: Client) {
@ -57,7 +57,8 @@ pub async fn add_message(payload: Payload, client: Client) {
if MainStatus::global_config().ica().admin_list.contains(&message.sender_id()) { if MainStatus::global_config().ica().admin_list.contains(&message.sender_id()) {
// admin 区 // admin 区
// 先判定是否为 admin // 先判定是否为 admin
if message.content().starts_with("/bot-enable") { let client_id = client_id();
if message.content().starts_with(&format!("/bot-enable-{}", client_id)) {
// 尝试获取后面的信息 // 尝试获取后面的信息
if let Some((_, name)) = message.content().split_once(" ") { if let Some((_, name)) = message.content().split_once(" ") {
let path_name = PathBuf::from(name); let path_name = PathBuf::from(name);
@ -77,7 +78,7 @@ pub async fn add_message(payload: Payload, client: Client) {
} }
} }
} }
} else if message.content().starts_with("/bot-disable") { } else if message.content().starts_with(&format!("/bot-disable-{}", client_id)) {
if let Some((_, name)) = message.content().split_once(" ") { if let Some((_, name)) = message.content().split_once(" ") {
let path_name = PathBuf::from(name); let path_name = PathBuf::from(name);
match py::PyStatus::get_status(&path_name) { match py::PyStatus::get_status(&path_name) {

View File

@ -35,10 +35,10 @@ const HELP_MSG: &str = r#"/bot-rs
python (python插件启用了的话) python (python插件启用了的话)
/bot-ls /bot-ls
/bot-enable <plugin> /bot-enable-<client-id> <plugin>
()
/bot-disable <plugin> /bot-disable-<client-id> <plugin>
()
by shenjackyuanjie"#; by shenjackyuanjie"#;
@ -58,9 +58,10 @@ pub fn client_id() -> String {
/// 获取版本信息 /// 获取版本信息
pub fn version_str() -> String { pub fn version_str() -> String {
format!( format!(
"shenbot-rs v{}-{} ica v{}({}) tailchat v{}", "shenbot-rs v{}-{}-[{}] ica v{}({}) tailchat v{}",
VERSION, VERSION,
if STABLE { "" } else { "开发版" }, if STABLE { "" } else { "开发版" },
client_id(),
ICA_VERSION, ICA_VERSION,
ica::ICA_PROTOCOL_VERSION, ica::ICA_PROTOCOL_VERSION,
TAILCHAT_VERSION, TAILCHAT_VERSION,

View File

@ -218,6 +218,10 @@ impl IcaClientPy {
#[getter] #[getter]
pub fn get_version(&self) -> String { crate::VERSION.to_string() } pub fn get_version(&self) -> String { crate::VERSION.to_string() }
#[getter] #[getter]
pub fn get_version_str(&self) -> String { crate::version_str() }
#[getter]
pub fn get_client_id(&self) -> String { crate::client_id() }
#[getter]
pub fn get_ica_version(&self) -> String { crate::ICA_VERSION.to_string() } pub fn get_ica_version(&self) -> String { crate::ICA_VERSION.to_string() }
#[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() }

View File

@ -65,6 +65,10 @@ impl TailchatClientPy {
#[getter] #[getter]
pub fn get_version(&self) -> String { crate::VERSION.to_string() } pub fn get_version(&self) -> String { crate::VERSION.to_string() }
#[getter] #[getter]
pub fn get_version_str(&self) -> String { crate::version_str() }
#[getter]
pub fn get_client_id(&self) -> String { crate::client_id() }
#[getter]
pub fn get_tailchat_version(&self) -> String { crate::TAILCHAT_VERSION.to_string() } pub fn get_tailchat_version(&self) -> String { crate::TAILCHAT_VERSION.to_string() }
#[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() }

View File

@ -9,7 +9,7 @@ use tracing::{event, info, Level};
use crate::data_struct::tailchat::messages::ReceiveMessage; use crate::data_struct::tailchat::messages::ReceiveMessage;
use crate::data_struct::tailchat::status::{BotStatus, UpdateDMConverse}; use crate::data_struct::tailchat::status::{BotStatus, UpdateDMConverse};
use crate::tailchat::client::{emit_join_room, send_message}; use crate::tailchat::client::{emit_join_room, send_message};
use crate::{help_msg, py, MainStatus, TAILCHAT_VERSION, VERSION}; use crate::{client_id, help_msg, py, MainStatus, TAILCHAT_VERSION, VERSION};
/// 所有 /// 所有
pub async fn any_event(event: Event, payload: Payload, _client: Client, _status: Arc<BotStatus>) { pub async fn any_event(event: Event, payload: Payload, _client: Client, _status: Arc<BotStatus>) {
@ -79,14 +79,15 @@ pub async fn on_message(payload: Payload, client: Client, _status: Arc<BotStatus
if !message.is_reply() { if !message.is_reply() {
if message.content == "/bot-rs" { if message.content == "/bot-rs" {
let reply = message.reply_with(&format!( let reply = message.reply_with(&format!(
"shenbot v{}\ntailchat-async-rs pong v{}", "shenbot v{}-{}\ntailchat-rs pong v{}",
VERSION, TAILCHAT_VERSION VERSION, client_id(), TAILCHAT_VERSION
)); ));
send_message(&client, &reply).await; send_message(&client, &reply).await;
} else if message.content == "/bot-ls" { } else if message.content == "/bot-ls" {
let reply = message.reply_with(&format!( let reply = message.reply_with(&format!(
"shenbot-py v{}\n{}", "shenbot-py v{}-{}\n{}",
VERSION, VERSION,
client_id(),
if MainStatus::global_config().check_py() { if MainStatus::global_config().check_py() {
py::PyStatus::display() py::PyStatus::display()
} else { } else {
@ -100,7 +101,8 @@ pub async fn on_message(payload: Payload, client: Client, _status: Arc<BotStatus
} }
if MainStatus::global_config().tailchat().admin_list.contains(&message.sender_id) { if MainStatus::global_config().tailchat().admin_list.contains(&message.sender_id) {
// admin 区 // admin 区
if message.content.starts_with("/bot-enable") { let client_id = client_id();
if message.content.starts_with(&format!("/bot-enable-{}", client_id)) {
// 先判定是否为 admin // 先判定是否为 admin
// 尝试获取后面的信息 // 尝试获取后面的信息
if let Some((_, name)) = message.content.split_once(" ") { if let Some((_, name)) = message.content.split_once(" ") {
@ -121,7 +123,7 @@ pub async fn on_message(payload: Payload, client: Client, _status: Arc<BotStatus
} }
} }
} }
} else if message.content.starts_with("/bot-disable") { } else if message.content.starts_with(&format!("/bot-disable-{}", client_id)) {
if let Some((_, name)) = message.content.split_once(" ") { if let Some((_, name)) = message.content.split_once(" ") {
let path_name = PathBuf::from(name); let path_name = PathBuf::from(name);
match py::PyStatus::get_status(&path_name) { match py::PyStatus::get_status(&path_name) {

View File

@ -1,5 +1,12 @@
# 更新日志 # 更新日志
## 0.7.1
- 加入了 `client_id`
- 用的 startup time hash 一遍取后六位
- 以及也有 python 侧的 `client_id` api
- 修复了上个版本其实没有写 python 侧 `version_str` api 的问题
## 0.7.0 ## 0.7.0
> 我决定叫他 0.7.0 > 我决定叫他 0.7.0
@ -49,7 +56,6 @@
- `wrap_callback``wrap_any_callback` - `wrap_callback``wrap_any_callback`
- 因为现在他俩已经进到 `rust_socketio` 里啦 - 因为现在他俩已经进到 `rust_socketio` 里啦
- 添加了新的 macro - 添加了新的 macro
- ``
- 支持了 `TailchatReceiveMessagePy``is_from_self` 方法 - 支持了 `TailchatReceiveMessagePy``is_from_self` 方法
- 用于判断是否是自己发的消息 - 用于判断是否是自己发的消息