几乎完活
This commit is contained in:
parent
ff255426f6
commit
3451424544
@ -200,6 +200,12 @@ class TailchatReciveMessage:
|
||||
@property
|
||||
def converse_id(self) -> TailchatType.ConverseId:
|
||||
...
|
||||
def reply_with(self, message: str) -> "TailchatSendingMessage":
|
||||
"""回复这条消息"""
|
||||
...
|
||||
def as_reply(self, message: str) -> "TailchatSendingMessage":
|
||||
"""回复这条消息"""
|
||||
...
|
||||
|
||||
|
||||
class TailchatSendingMessage:
|
||||
@ -237,7 +243,13 @@ class TailchatClient:
|
||||
"""发送消息, 并在日志中输出警告信息"""
|
||||
self.warn(message.content)
|
||||
return self.send_message(message)
|
||||
|
||||
@property
|
||||
def version(self) -> str:
|
||||
...
|
||||
@property
|
||||
def tailchat_version(self) -> str:
|
||||
"""tailchat 的版本号"""
|
||||
...
|
||||
def debug(self, message: str) -> None:
|
||||
"""向日志中输出调试信息"""
|
||||
def info(self, message: str) -> None:
|
||||
|
@ -2,9 +2,12 @@ from typing import TYPE_CHECKING, TypeVar
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ica_typing import IcaNewMessage, IcaClient
|
||||
from ica_typing import TailchatReciveMessage, TailchatClient
|
||||
else:
|
||||
IcaNewMessage = TypeVar("NewMessage")
|
||||
IcaClient = TypeVar("IcaClient")
|
||||
TailchatReciveMessage = TypeVar("TailchatReciveMessage")
|
||||
TailchatClient = TypeVar("TailchatClient")
|
||||
|
||||
def on_ica_message(msg: IcaNewMessage, client: IcaClient) -> None:
|
||||
if not (msg.is_from_self or msg.is_reply):
|
||||
@ -13,3 +16,9 @@ def on_ica_message(msg: IcaNewMessage, client: IcaClient) -> None:
|
||||
client.send_message(reply)
|
||||
|
||||
|
||||
def on_tailchat_message(msg: TailchatReciveMessage, client: TailchatClient) -> None:
|
||||
# if not (msg.is_from_self or msg.is_reply):
|
||||
if not (msg.is_reply):
|
||||
if msg.content == "/bot":
|
||||
reply = msg.reply_with(f"ica-async-rs({client.version})-sync-py {client.tailchat_version}")
|
||||
client.send_message(reply)
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value as JsonValue};
|
||||
|
||||
@ -52,9 +54,9 @@ impl ReciveMessage {
|
||||
}
|
||||
|
||||
/// 回复这条消息
|
||||
pub fn reply_with(&self, content: String) -> SendingMessage {
|
||||
pub fn reply_with(&self, content: &String) -> SendingMessage {
|
||||
SendingMessage::new(
|
||||
content,
|
||||
content.clone(),
|
||||
self.converse_id.clone(),
|
||||
self.group_id.clone(),
|
||||
Some(ReplyMeta::from_recive_message(self)),
|
||||
@ -62,6 +64,17 @@ impl ReciveMessage {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for ReciveMessage {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
// msgid|groupid-converseid|senderid|content
|
||||
write!(
|
||||
f,
|
||||
"{}|{}-{}|{}|{}",
|
||||
self.msg_id, self.group_id, self.converse_id, self.sender_id, self.content
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
/// 将要发送的消息
|
||||
///
|
||||
|
@ -133,8 +133,7 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client) {
|
||||
}
|
||||
}
|
||||
Event::Message => {
|
||||
match payload {
|
||||
Payload::Text(values) => {
|
||||
if let Payload::Text(values) = payload {
|
||||
if let Some(value) = values.first() {
|
||||
if handled.contains(&value.as_str().unwrap()) {
|
||||
return;
|
||||
@ -142,8 +141,6 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client) {
|
||||
info!("收到消息 {}", value.to_string().yellow());
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
return;
|
||||
}
|
||||
_ => (),
|
||||
@ -165,8 +162,7 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client) {
|
||||
pub async fn connect_callback(payload: Payload, _client: Client) {
|
||||
let span = span!(Level::INFO, "ica connect_callback");
|
||||
let _enter = span.enter();
|
||||
match payload {
|
||||
Payload::Text(values) => {
|
||||
if let Payload::Text(values) = payload {
|
||||
if let Some(value) = values.first() {
|
||||
match value.as_str() {
|
||||
Some("authSucceed") => {
|
||||
@ -186,6 +182,4 @@ pub async fn connect_callback(payload: Payload, _client: Client) {
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ pub type StopGetter = tokio::sync::oneshot::Receiver<()>;
|
||||
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
pub const ICA_VERSION: &str = "1.5.0";
|
||||
pub const TAILCHAT_VERSION: &str = "0.2.0";
|
||||
pub const TAILCHAT_VERSION: &str = "1.0.0";
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! wrap_callback {
|
||||
|
@ -99,7 +99,7 @@ impl NewMessagePy {
|
||||
#[getter]
|
||||
pub fn get_is_chat_msg(&self) -> bool { self.msg.room_id.is_chat() }
|
||||
#[getter]
|
||||
pub fn get_room_id(&self) -> RoomId { self.msg.room_id.clone() }
|
||||
pub fn get_room_id(&self) -> RoomId { self.msg.room_id }
|
||||
}
|
||||
|
||||
impl NewMessagePy {
|
||||
|
@ -3,7 +3,7 @@ use pyo3::prelude::*;
|
||||
use rust_socketio::asynchronous::Client;
|
||||
use tracing::{debug, info, warn};
|
||||
|
||||
use crate::data_struct::tailchat::messages::{ReciveMessage, ReplyMeta, SendingMessage};
|
||||
use crate::data_struct::tailchat::messages::{ReciveMessage, SendingMessage};
|
||||
use crate::data_struct::tailchat::{ConverseId, GroupId, MessageId, UserId};
|
||||
use crate::tailchat::client::send_message;
|
||||
|
||||
@ -60,7 +60,10 @@ impl TailchatClientPy {
|
||||
warn!("{}", message.message.content);
|
||||
self.send_message(message)
|
||||
}
|
||||
|
||||
#[getter]
|
||||
pub fn get_version(&self) -> String { crate::VERSION.to_string() }
|
||||
#[getter]
|
||||
pub fn get_tailchat_version(&self) -> String { crate::TAILCHAT_VERSION.to_string() }
|
||||
pub fn debug(&self, content: String) {
|
||||
debug!("{}", content);
|
||||
}
|
||||
@ -94,7 +97,7 @@ impl TailchatReciveMessagePy {
|
||||
}
|
||||
pub fn reply_with(&self, content: String) -> TailchatSendingMessagePy {
|
||||
TailchatSendingMessagePy {
|
||||
message: self.message.reply_with(content),
|
||||
message: self.message.reply_with(&content),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ use rust_socketio::{Event, Payload};
|
||||
use tracing::info;
|
||||
|
||||
use crate::data_struct::tailchat::messages::ReciveMessage;
|
||||
use crate::tailchat::client::send_message;
|
||||
|
||||
/// 所有
|
||||
pub async fn any_event(event: Event, payload: Payload, _client: Client) {
|
||||
@ -60,7 +61,18 @@ pub async fn on_message(payload: Payload, client: Client) {
|
||||
if let Payload::Text(values) = payload {
|
||||
if let Some(value) = values.first() {
|
||||
let message: ReciveMessage = serde_json::from_value(value.clone()).unwrap();
|
||||
info!("收到消息 {:?}", message);
|
||||
info!("tailchat_msg {}", message.to_string().cyan());
|
||||
|
||||
if !message.is_reply() {
|
||||
if message.content == "/bot-rs" {
|
||||
let reply = message.reply_with(&format!(
|
||||
"shenbot v{}\ntailchat-async-rs pong v{}",
|
||||
crate::VERSION,
|
||||
crate::TAILCHAT_VERSION
|
||||
));
|
||||
send_message(&client, &reply).await;
|
||||
}
|
||||
}
|
||||
crate::py::call::tailchat_new_message_py(&message, &client).await;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user