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

Commit

Permalink
feat: group essence & online status
Browse files Browse the repository at this point in the history
See #17
  • Loading branch information
BlueGlassBlock committed May 2, 2023
1 parent 01690f2 commit d5fa121
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 4 deletions.
47 changes: 44 additions & 3 deletions python/ichika/core/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import datetime
from dataclasses import dataclass
from types import ModuleType
from typing import Callable, Sequence, TypedDict, TypeVar
from typing_extensions import Any
from typing import Callable, Literal, TypedDict, TypeVar
from typing_extensions import Any, TypeAlias

from ..client import Client
from ..login import (
Expand Down Expand Up @@ -156,6 +155,46 @@ class RawMessageReceipt:
kind: str
target: int

__OnlineStatus: TypeAlias = ( # TODO: Wrapper
tuple[int, str] # (face_index, wording)
| tuple[
Literal[False],
Literal[
11, # 在线
21, # 离线,效果未知
31, # 离开
41, # 隐身
50, # 忙
60, # Q 我吧
70, # 请勿打扰
],
]
| tuple[
Literal[True],
Literal[
1000, # 当前电量
1028, # 听歌中
1040, # 星座运势
1030, # 今日天气
1069, # 遇见春天
1027, # Timi中
1064, # 吃鸡中
1051, # 恋爱中
1053, # 汪汪汪
1019, # 干饭中
1018, # 学习中
1032, # 熬夜中
1050, # 打球中
1011, # 信号弱
1024, # 在线学习
1017, # 游戏中
1022, # 度假中
1021, # 追剧中
1020, # 健身中
],
]
)

class PlumbingClient:
# [impl 1]
@property
Expand All @@ -176,6 +215,7 @@ class PlumbingClient:
signature: str = ...,
) -> None: ...
async def get_other_clients(self) -> VTuple[OtherClientInfo]: ...
async def modify_online_status(self, status: __OnlineStatus) -> None: ...
# [impl 2]
async def get_friend_list(self) -> FriendList: ...
async def get_friend_list_raw(self) -> FriendList: ...
Expand Down Expand Up @@ -210,6 +250,7 @@ class PlumbingClient:
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) -> None: ...
async def recall_group_message(self, uin: int, seq: int, rand: int) -> None: ...
async def modify_group_essence(self, uin: int, seq: int, rand: int, flag: bool) -> None: ...

# endregion: client

Expand Down
29 changes: 28 additions & 1 deletion src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use pyo3::exceptions::PyRuntimeError;
use pyo3::prelude::*;
use pyo3::types::*;
use ricq::msg::elem::RQElem;
use ricq::structs::ProfileDetailUpdate;
use ricq::structs::{ProfileDetailUpdate, Status};
use structs::*;
use tokio::task::JoinHandle;

Expand Down Expand Up @@ -167,6 +167,18 @@ impl PlumbingClient {
})
})
}

pub fn set_online_status<'py>(
&self,
py: Python<'py>,
status: OnlineStatusParam,
) -> PyResult<&'py PyAny> {
let client = self.client.clone();
py_future(py, async move {
client.update_online_status(Status::from(status)).await?;
Ok(())
})
}
}

#[pymethods]
Expand Down Expand Up @@ -554,5 +566,20 @@ impl PlumbingClient {
Ok(())
})
}

pub fn modify_group_essence<'py>(
&self,
py: Python<'py>,
uin: i64,
seq: i32,
rand: i32,
flag: bool,
) -> PyResult<&'py PyAny> {
let client = self.client.clone();
py_future(py, async move {
client.operate_group_essence(uin, seq, rand, flag).await?;
Ok(())
})
}
// TODO: Send audio
}
29 changes: 29 additions & 0 deletions src/client/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,32 @@ pub struct RawMessageReceipt {
pub kind: String,
pub target: i64,
}

#[derive(FromPyObject)]
pub enum OnlineStatusParam {
#[pyo3(annotation = "tuple[bool, int]")]
Normal(bool, u64),
#[pyo3(annotation = "tuple[int, str]")]
Custom(u64, String),
}

impl From<OnlineStatusParam> for ricq::structs::Status {
fn from(value: OnlineStatusParam) -> Self {
use ricq::structs::{CustomOnlineStatus, Status};
match value {
OnlineStatusParam::Custom(face_index, wording) => Status {
online_status: 11,
ext_online_status: 2000,
custom_status: Some(CustomOnlineStatus {
face_index,
wording,
}),
},
OnlineStatusParam::Normal(is_ext, index) => Status {
online_status: if is_ext { 11 } else { index as i32 },
ext_online_status: if is_ext { index as i64 } else { 0 },
custom_status: None,
},
}
}
}

0 comments on commit d5fa121

Please sign in to comment.