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

Commit

Permalink
feat: group methods
Browse files Browse the repository at this point in the history
- get group admins
- modify member name
- modify member special title
- modify member admin
See #17
  • Loading branch information
BlueGlassBlock committed May 2, 2023
1 parent 2b751ad commit 471a899
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 10 deletions.
8 changes: 6 additions & 2 deletions python/ichika/core/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,19 @@ class PlumbingClient:
async def get_group_raw(self, uin: int) -> Group: ...
async def find_group(self, uin: int) -> Group | None: ...
async def get_groups(self) -> VTuple[Group]: ...
async def get_group_admins(self, uin: int) -> list[tuple[int, int]]: ...
async def mute_group(self, uin: int, mute: bool) -> None: ...
async def quit_group(self, uin: int) -> None: ...
# [impl 4]
async def get_member(self, group_uin: int, uin: int) -> Member: ...
async def get_member_raw(self, group_uin: int, uin: int) -> Member: ...
async def nudge_member(self, group_uin: int, uin: int) -> None: ...
# Duration -> 0: Unmute
async def mute_member(self, group_uin: int, uin: int, duration: int) -> None: ...
async def mute_group(self, uin: int, mute: bool) -> None: ...
async def quit_group(self, uin: int) -> None: ...
async def kick_member(self, group_uin: int, uin: int, msg: str, block: bool) -> None: ...
async def modify_member_special_title(self, group_uin: int, uin: int, special_title: str) -> None: ...
async def modify_member_card(self, group_uin: int, uin: int, card_name: str) -> None: ...
async def modify_member_admin(self, group_uin: int, uin: int, admin: bool) -> None: ...
# [impl 5]
async def upload_friend_image(self, uin: int, data: bytes) -> dict[str, Any]: ...
async def send_friend_message(self, uin: int, chain: list[dict[str, Any]]) -> RawMessageReceipt: ...
Expand Down
75 changes: 67 additions & 8 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,35 @@ impl PlumbingClient {
}))
})
}

pub fn get_group_admins<'py>(&self, py: Python<'py>, uin: i64) -> PyResult<&'py PyAny> {
let client = self.client.clone();
py_future(py, async move {
let admins = client
.get_group_admin_list(uin)
.await?
.into_iter()
.map(|(member_uin, perm)| (member_uin, perm as u8))
.collect::<Vec<(i64, u8)>>(); // TODO: Better Perm handling
Ok(admins)
})
}

pub fn mute_group<'py>(&self, py: Python<'py>, uin: i64, mute: bool) -> PyResult<&'py PyAny> {
let client = self.client.clone();
py_future(py, async move {
client.group_mute_all(uin, mute).await?;
Ok(())
})
}

pub fn quit_group<'py>(&self, py: Python<'py>, uin: i64) -> PyResult<&'py PyAny> {
let client = self.client.clone();
py_future(py, async move {
client.group_quit(uin).await?;
Ok(())
})
}
}

#[pymethods]
Expand Down Expand Up @@ -327,33 +356,63 @@ impl PlumbingClient {
})
}

pub fn mute_group<'py>(&self, py: Python<'py>, uin: i64, mute: bool) -> PyResult<&'py PyAny> {
pub fn kick_member<'py>(
&self,
py: Python<'py>,
group_uin: i64,
uin: i64,
msg: String,
block: bool,
) -> PyResult<&'py PyAny> {
let client = self.client.clone();
py_future(py, async move {
client.group_mute_all(uin, mute).await?;
client.group_kick(group_uin, vec![uin], &msg, block).await?;
Ok(())
})
}

pub fn quit_group<'py>(&self, py: Python<'py>, uin: i64) -> PyResult<&'py PyAny> {
pub fn modify_member_special_title<'py>(
&self,
py: Python<'py>,
group_uin: i64,
uin: i64,
special_title: String,
) -> PyResult<&'py PyAny> {
let client = self.client.clone();
py_future(py, async move {
client.group_quit(uin).await?;
client
.group_edit_special_title(group_uin, uin, special_title)
.await?;
Ok(())
})
}

pub fn kick_member<'py>(
pub fn modify_member_card<'py>(
&self,
py: Python<'py>,
group_uin: i64,
uin: i64,
msg: String,
block: bool,
card_name: String,
) -> PyResult<&'py PyAny> {
let client = self.client.clone();
py_future(py, async move {
client.group_kick(group_uin, vec![uin], &msg, block).await?;
client
.edit_group_member_card(group_uin, uin, card_name)
.await?;
Ok(())
})
}

pub fn modify_member_admin<'py>(
&self,
py: Python<'py>,
group_uin: i64,
uin: i64,
admin: bool,
) -> PyResult<&'py PyAny> {
let client = self.client.clone();
py_future(py, async move {
client.group_set_admin(group_uin, uin, admin).await?;
Ok(())
})
}
Expand Down

0 comments on commit 471a899

Please sign in to comment.