Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

Commit

Permalink
feat: basic message recall
Browse files Browse the repository at this point in the history
See #17
  • Loading branch information
BlueGlassBlock committed Mar 13, 2023
1 parent 87fc16a commit 5cb2ebd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
4 changes: 4 additions & 0 deletions python/ichika/core/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class RawMessageReceipt:
seqs: VTuple[int]
rands: VTuple[int]
time: int
kind: str
target: int

class PlumbingClient:
# [impl 1]
Expand Down Expand Up @@ -184,6 +186,8 @@ class PlumbingClient:
async def send_friend_message(self, uin: int, chain: list[dict[str, Any]]) -> RawMessageReceipt: ...
async def upload_group_image(self, uin: int, data: bytes) -> dict[str, Any]: ...
async def send_group_message(self, uin: int, chain: list[dict[str, Any]]) -> RawMessageReceipt: ...
async def recall_friend_message(self, uin: int, time: int, seq: int, rand: int): ...
async def recall_group_message(self, uin: int, seq: int, rand: int): ...

# endregion: client

Expand Down
37 changes: 36 additions & 1 deletion src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ impl PlumbingClient {
seqs: PyTuple::new(py, seqs).into_py(py),
rands: PyTuple::new(py, rands).into_py(py),
time,
kind: "friend".into(),
target: uin,
}))
})
}
Expand Down Expand Up @@ -324,17 +326,50 @@ impl PlumbingClient {
) -> PyResult<&'py PyAny> {
let client = self.client.clone();
let chain = deserialize_message_chain(chain)?;
tracing::info!("{:?}", chain);
py_future(py, async move {
let ricq::structs::MessageReceipt { seqs, rands, time } =
client.send_group_message(uin, chain).await?;
Ok(Python::with_gil(|py| RawMessageReceipt {
seqs: PyTuple::new(py, seqs).into_py(py),
rands: PyTuple::new(py, rands).into_py(py),
time,
kind: "group".into(),
target: uin,
}))
})
}

pub fn recall_friend_message<'py>(
&self,
py: Python<'py>,
uin: i64,
time: i64,
seq: i32,
rand: i32,
) -> PyResult<&'py PyAny> {
let client = self.client.clone();
py_future(py, async move {
client
.recall_friend_message(uin, time, vec![seq], vec![rand])
.await?;
Ok(())
})
}

pub fn recall_group_message<'py>(
&self,
py: Python<'py>,
uin: i64,
seq: i32,
rand: i32,
) -> PyResult<&'py PyAny> {
let client = self.client.clone();
py_future(py, async move {
client
.recall_group_message(uin, vec![seq], vec![rand])
.await?;
Ok(())
})
}
// TODO: Send audio
}
2 changes: 2 additions & 0 deletions src/client/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ pub struct RawMessageReceipt {
pub seqs: Py<PyTuple>,
pub rands: Py<PyTuple>,
pub time: i64,
pub kind: String,
pub target: i64,
}

0 comments on commit 5cb2ebd

Please sign in to comment.