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]]
name = "ica-rs"
version = "0.7.0"
version = "0.7.1"
dependencies = [
"anyhow",
"base64 0.22.1",

View File

@ -1,6 +1,6 @@
[package]
name = "ica-rs"
version = "0.7.0"
version = "0.7.1"
edition = "2021"
# 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::online_data::OnlineData;
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) {
@ -57,7 +57,8 @@ pub async fn add_message(payload: Payload, client: Client) {
if MainStatus::global_config().ica().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)) {
// 尝试获取后面的信息
if let Some((_, name)) = message.content().split_once(" ") {
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(" ") {
let path_name = PathBuf::from(name);
match py::PyStatus::get_status(&path_name) {

View File

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

View File

@ -218,6 +218,10 @@ impl IcaClientPy {
#[getter]
pub fn get_version(&self) -> String { crate::VERSION.to_string() }
#[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() }
#[getter]
pub fn get_startup_time(&self) -> SystemTime { crate::MainStatus::get_startup_time() }

View File

@ -65,6 +65,10 @@ impl TailchatClientPy {
#[getter]
pub fn get_version(&self) -> String { crate::VERSION.to_string() }
#[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() }
#[getter]
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::status::{BotStatus, UpdateDMConverse};
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>) {
@ -79,14 +79,15 @@ pub async fn on_message(payload: Payload, client: Client, _status: Arc<BotStatus
if !message.is_reply() {
if message.content == "/bot-rs" {
let reply = message.reply_with(&format!(
"shenbot v{}\ntailchat-async-rs pong v{}",
VERSION, TAILCHAT_VERSION
"shenbot v{}-{}\ntailchat-rs pong v{}",
VERSION, client_id(), TAILCHAT_VERSION
));
send_message(&client, &reply).await;
} else if message.content == "/bot-ls" {
let reply = message.reply_with(&format!(
"shenbot-py v{}\n{}",
"shenbot-py v{}-{}\n{}",
VERSION,
client_id(),
if MainStatus::global_config().check_py() {
py::PyStatus::display()
} 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) {
// admin 区
if message.content.starts_with("/bot-enable") {
let client_id = client_id();
if message.content.starts_with(&format!("/bot-enable-{}", client_id)) {
// 先判定是否为 admin
// 尝试获取后面的信息
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(" ") {
let path_name = PathBuf::from(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
@ -49,7 +56,6 @@
- `wrap_callback``wrap_any_callback`
- 因为现在他俩已经进到 `rust_socketio` 里啦
- 添加了新的 macro
- ``
- 支持了 `TailchatReceiveMessagePy``is_from_self` 方法
- 用于判断是否是自己发的消息