mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 04:31:05 +08:00
逆天
This commit is contained in:
parent
680934ad3f
commit
113a1518d1
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -659,7 +659,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ica-rs"
|
||||
version = "0.6.11"
|
||||
version = "0.7.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64 0.22.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ica-rs"
|
||||
version = "0.6.11"
|
||||
version = "0.7.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
|
@ -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::{py, MainStatus, ICA_VERSION, VERSION};
|
||||
use crate::{py, version_str, MainStatus, VERSION};
|
||||
|
||||
/// 获取在线数据
|
||||
pub async fn get_online_data(payload: Payload, _client: Client) {
|
||||
|
@ -22,7 +22,7 @@ pub async fn get_online_data(payload: Payload, _client: Client) {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::collapsible_if)]
|
||||
// #[allow(clippy::collapsible_if)]
|
||||
/// 接收消息
|
||||
pub async fn add_message(payload: Payload, client: Client) {
|
||||
if let Payload::Text(values) = payload {
|
||||
|
@ -38,10 +38,7 @@ pub async fn add_message(payload: Payload, client: Client) {
|
|||
// 之后的处理交给插件
|
||||
if !message.is_from_self() && !message.is_reply() {
|
||||
if message.content() == "/bot-rs" {
|
||||
let reply = message.reply_with(&format!(
|
||||
"shenbot v{}\nica-async-rs pong v{}",
|
||||
VERSION, ICA_VERSION
|
||||
));
|
||||
let reply = message.reply_with(&version_str());
|
||||
send_message(&client, &reply).await;
|
||||
} else if message.content() == "/bot-ls" {
|
||||
let reply = message.reply_with(&format!(
|
||||
|
@ -64,19 +61,20 @@ pub async fn add_message(payload: Payload, client: Client) {
|
|||
content.next();
|
||||
if let Some(name) = content.next() {
|
||||
let path_name = PathBuf::from(name);
|
||||
if py::PyStatus::get_map().contains_key(&path_name) {
|
||||
if py::PyStatus::get_config().get_status(path_name.as_path()) {
|
||||
match py::PyStatus::get_status(&path_name) {
|
||||
None => {
|
||||
let reply = message.reply_with("未找到插件");
|
||||
send_message(&client, &reply).await;
|
||||
}
|
||||
Some(true) => {
|
||||
let reply = message.reply_with("无变化, 插件已经启用");
|
||||
send_message(&client, &reply).await;
|
||||
return;
|
||||
}
|
||||
py::PyStatus::get_config_mut()
|
||||
.set_status(path_name.as_path(), true);
|
||||
let reply = message.reply_with("启用插件完成");
|
||||
send_message(&client, &reply).await;
|
||||
} else {
|
||||
let reply = message.reply_with("未找到插件");
|
||||
send_message(&client, &reply).await;
|
||||
Some(false) => {
|
||||
py::PyStatus::set_status(&path_name, true);
|
||||
let reply = message.reply_with("启用插件完成");
|
||||
send_message(&client, &reply).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if message.content().starts_with("/bot-disable") {
|
||||
|
@ -84,19 +82,20 @@ pub async fn add_message(payload: Payload, client: Client) {
|
|||
content.next();
|
||||
if let Some(name) = content.next() {
|
||||
let path_name = PathBuf::from(name);
|
||||
if py::PyStatus::get_map().contains_key(&path_name) {
|
||||
if !py::PyStatus::get_config().get_status(path_name.as_path()) {
|
||||
match py::PyStatus::get_status(&path_name) {
|
||||
None => {
|
||||
let reply = message.reply_with("未找到插件");
|
||||
send_message(&client, &reply).await;
|
||||
}
|
||||
Some(false) => {
|
||||
let reply = message.reply_with("无变化, 插件已经禁用");
|
||||
send_message(&client, &reply).await;
|
||||
return;
|
||||
}
|
||||
py::PyStatus::get_config_mut()
|
||||
.set_status(path_name.as_path(), false);
|
||||
let reply = message.reply_with("已经禁用插件");
|
||||
send_message(&client, &reply).await;
|
||||
} else {
|
||||
let reply = message.reply_with("未找到插件");
|
||||
send_message(&client, &reply).await;
|
||||
Some(true) => {
|
||||
py::PyStatus::set_status(&path_name, false);
|
||||
let reply = message.reply_with("禁用插件完成");
|
||||
send_message(&client, &reply).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,11 +31,12 @@ pub const TAILCHAT_VERSION: &str = "1.2.1";
|
|||
|
||||
pub fn version_str() -> String {
|
||||
format!(
|
||||
"shenbot-rs v{}-{} ica v{} tailchat v{}",
|
||||
"shenbot-rs v{}-{} ica v{}({}) tailchat v{}",
|
||||
VERSION,
|
||||
if STABLE { "" } else { "开发版" },
|
||||
ICA_VERSION,
|
||||
TAILCHAT_VERSION
|
||||
ica::ICA_PROTOCOL_VERSION,
|
||||
TAILCHAT_VERSION,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -95,17 +95,25 @@ impl PyStatus {
|
|||
|
||||
/// 获取某个插件的状态
|
||||
/// 以 config 优先
|
||||
pub fn get_status(path: &PathBuf) -> Option<bool> {
|
||||
let local_plugin = Self::get_map_mut().get_mut(path).map(|p| p.enabled)?;
|
||||
pub fn get_status(path: &PathBuf) -> Option<bool> {
|
||||
Self::get_config_mut().sync_status_from_config();
|
||||
Self::get_map().get(path).map(|plugin| plugin.enabled)
|
||||
}
|
||||
|
||||
pub fn set_status(path: &Path, status: bool) { Self::get_config_mut().set_status(path, status); }
|
||||
pub fn set_status(path: &Path, status: bool) {
|
||||
let cfg = Self::get_config_mut();
|
||||
cfg.set_status(path, status);
|
||||
cfg.sync_status_from_config();
|
||||
}
|
||||
|
||||
pub fn display() -> String {
|
||||
let map = Self::get_map();
|
||||
format!(
|
||||
"Python 插件 {{ {} }}",
|
||||
map.iter().map(|(k, v)| format!("{:?}-{}", k, v.enabled)).collect::<Vec<String>>().join("\n")
|
||||
map.iter()
|
||||
.map(|(k, v)| format!("{:?}-{}", k, v.enabled))
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use colored::Colorize;
|
||||
|
@ -62,7 +63,6 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client, _status:
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::collapsible_if)]
|
||||
pub async fn on_message(payload: Payload, client: Client, _status: Arc<BotStatus>) {
|
||||
if let Payload::Text(values) = payload {
|
||||
if let Some(value) = values.first() {
|
||||
|
@ -95,6 +95,54 @@ pub async fn on_message(payload: Payload, client: Client, _status: Arc<BotStatus
|
|||
));
|
||||
send_message(&client, &reply).await;
|
||||
}
|
||||
if MainStatus::global_config().tailchat().admin_list.contains(&message.sender_id) {
|
||||
// admin 区
|
||||
if message.content.starts_with("/bot-enable") {
|
||||
// 先判定是否为 admin
|
||||
// 尝试获取后面的信息
|
||||
let mut content = message.content.split_whitespace();
|
||||
content.next();
|
||||
if let Some(name) = content.next() {
|
||||
let path_name = PathBuf::from(name);
|
||||
match py::PyStatus::get_status(&path_name) {
|
||||
None => {
|
||||
let reply = message.reply_with("未找到插件");
|
||||
send_message(&client, &reply).await;
|
||||
}
|
||||
Some(true) => {
|
||||
let reply = message.reply_with("无变化, 插件已经启用");
|
||||
send_message(&client, &reply).await;
|
||||
}
|
||||
Some(false) => {
|
||||
py::PyStatus::set_status(&path_name, true);
|
||||
let reply = message.reply_with("启用插件完成");
|
||||
send_message(&client, &reply).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if message.content.starts_with("/bot-disable") {
|
||||
let mut content = message.content.split_whitespace();
|
||||
content.next();
|
||||
if let Some(name) = content.next() {
|
||||
let path_name = PathBuf::from(name);
|
||||
match py::PyStatus::get_status(&path_name) {
|
||||
None => {
|
||||
let reply = message.reply_with("未找到插件");
|
||||
send_message(&client, &reply).await;
|
||||
}
|
||||
Some(false) => {
|
||||
let reply = message.reply_with("无变化, 插件已经禁用");
|
||||
send_message(&client, &reply).await;
|
||||
}
|
||||
Some(true) => {
|
||||
py::PyStatus::set_status(&path_name, false);
|
||||
let reply = message.reply_with("禁用插件完成");
|
||||
send_message(&client, &reply).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
py::call::tailchat_new_message_py(&message, &client).await;
|
||||
}
|
||||
|
|
15
news.md
15
news.md
|
@ -1,6 +1,9 @@
|
|||
# 更新日志
|
||||
|
||||
## 0.6.11
|
||||
## 0.7.0
|
||||
|
||||
> 我决定叫他 0.7.0
|
||||
> 因为修改太多了.png
|
||||
|
||||
- 加入了 禁用/启用 插件功能
|
||||
- 现在会在插件加载时警告你的插件原来定义了 `CONFIG_DATA` 这一项
|
||||
|
@ -8,8 +11,14 @@
|
|||
- `get_sender_name` 获取发送人昵称
|
||||
- `ica` 兼容版本号 `2.12.11` -> `2.12.12`
|
||||
- 加入了 `STABLE` 信息, 用于标记稳定版本
|
||||
- 去掉了 `enable_py` 选项
|
||||
- 原来这玩意压根没读取过
|
||||
- 添加了 `version_str() -> String` 用于方便的获取版本信息
|
||||
- 同样在 `py` 侧也有 `version_str` 方法
|
||||
- 加入了 `/help` 命令
|
||||
- 用于获取帮助信息
|
||||
- 加入了 `/bot-ls`
|
||||
- 用于展示所有插件的信息
|
||||
- 加入了 `/bot-enable` 和 `/bot-disable`
|
||||
- 用于启用/禁用插件
|
||||
|
||||
## 0.6.10
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user