Compare commits

...

3 Commits

Author SHA1 Message Date
f8332f7761
a? 2024-05-12 21:12:27 +08:00
80c5c18bdb
添加api 2024-05-12 21:09:15 +08:00
b349cdf4af
还是在new里面去掉 sticker 2024-05-12 20:00:38 +08:00
5 changed files with 32 additions and 12 deletions

2
Cargo.lock generated
View File

@ -653,7 +653,7 @@ dependencies = [
[[package]]
name = "ica-rs"
version = "0.6.2"
version = "0.6.3"
dependencies = [
"anyhow",
"base64 0.22.1",

View File

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

View File

@ -1,8 +1,10 @@
import io
import re
import time
import base64
import requests
import traceback
import urllib.parse
# import PIL
@ -16,7 +18,7 @@ else:
IcaNewMessage = TypeVar("NewMessage")
IcaClient = TypeVar("IcaClient")
_version_ = "2.3.1-rs"
_version_ = "2.4.0-rs"
backend_version = "unknown"
def format_data_size(data_bytes: float) -> str:
@ -254,9 +256,30 @@ def bmcl_rank(msg: IcaNewMessage, client: IcaClient, name: str) -> None:
client.send_message(reply)
def bangbang_img(msg: IcaNewMessage, client: IcaClient) -> None:
data = requests.get("https://api.bangbang93.top/api/link")
if data.status_code != 200:
reply = msg.reply_with(f"请求失败 {data.status_code} {data.reason}")
client.send_message(reply)
return
raw_name = data.url.split("/")[-1]
img_suffix = raw_name.split(".")[-1]
# mine 映射一下
if img_suffix.lower() in ("jpeg", "jpg"):
img_suffix = "jpeg"
img_name = raw_name[:-len(img_suffix) - 1]
img_name = urllib.parse.unquote(img_name)
mime_format = f"image/{img_suffix}"
client.info(f"获取到随机怪图: {img_name} {img_suffix}")
reply = msg.reply_with(img_name)
reply.set_img(data.content, mime_format, True)
client.send_message(reply)
help = """/bmcl -> dashboard
/bmcl rank -> all rank
/bmcl rank <name> -> rank of <name>
/bm93 -> 随机怪图
/brrs <name> -> rank of <name>
搜索限制:
1- 3 显示全部信息
@ -296,6 +319,8 @@ def on_ica_message(msg: IcaNewMessage, client: IcaClient) -> None:
if len(name) > 1:
name = name[1]
bmcl_rank(msg, client, name)
elif msg.content == "/bm93":
bangbang_img(msg, client)
except: # noqa
report_msg = f"bmcl插件发生错误,请呼叫shenjack\n{traceback.format_exc()}"
reply = msg.reply_with(report_msg)

View File

@ -275,7 +275,7 @@ impl NewMessage {
/// 创建一条对这条消息的回复
pub fn reply_with(&self, content: &String) -> SendMessage {
SendMessage::new(content.clone(), self.room_id, Some(self.msg.as_reply()), false)
SendMessage::new(content.clone(), self.room_id, Some(self.msg.as_reply()))
}
/// 作为被删除的消息
@ -310,19 +310,14 @@ pub struct SendMessage {
}
impl SendMessage {
pub fn new(
content: String,
room_id: RoomId,
reply_to: Option<ReplyMessage>,
sticker: bool,
) -> Self {
pub fn new(content: String, room_id: RoomId, reply_to: Option<ReplyMessage>) -> Self {
Self {
content,
room_id,
reply_to,
at: json!([]),
file_data: None,
sticker,
sticker: false,
}
}
@ -341,6 +336,7 @@ impl SendMessage {
}
}
/// 被删除的消息
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeleteMessage {
#[serde(rename = "roomId")]

View File

@ -51,7 +51,6 @@ pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientRe
format!("shenbot v {}\nica-async-rs v{}", crate::VERSION, crate::ICA_VERSION),
*room,
None,
false,
);
tokio::time::sleep(std::time::Duration::from_secs(1)).await;