Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
提供拓展api:get_cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
super1207 committed Nov 8, 2023
1 parent 2e67129 commit 13452ea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
12 changes: 8 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ secret:反向http需要的HMAC签名,用来验证上报的数据确实来自

#### get_group_list 获取群列表

成员数和最大成员数暂时为0,待研究。
成员数和最大成员数暂时为0,待研究。如果你拥有的频道数量大于150,则此api调用失败。

#### get_group_member_info 获取群成员信息

Expand Down Expand Up @@ -121,6 +121,10 @@ secret:反向http需要的HMAC签名,用来验证上报的数据确实来自

实际上获取在bot的私信列表上的人

#### get_cookies 获取机器人的cookies

`domain``token`,响应数据中的`cookies`为kook的token,你可以用这个api来实现一些其它非onebot标准的功能。


### 正在研究

Expand Down Expand Up @@ -159,11 +163,11 @@ get_record 获取语音(此api已经过时)

set_group_special_title 设置群组专属头衔(kook没有这个)

set_group_ban 群组单人禁言kook的权限机制不好实现这个
set_group_ban 群组单人禁言(kook的权限机制不好实现这个

set_group_whole_ban 群组全员禁言kook的权限机制不好实现这个
set_group_whole_ban 群组全员禁言(kook的权限机制不好实现这个

set_group_admin 群组设置管理员kook的权限机制不好实现这个
set_group_admin 群组设置管理员(kook的权限机制不好实现这个

set_group_add_request 处理加群邀请(kook的bot被邀请就会同意,不需要处理)

Expand Down
28 changes: 27 additions & 1 deletion src/kook_onebot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ impl KookOnebot {
// 查询分页数据
let meta = ret_json.get("meta").ok_or("meta not found")?;
let page_total = meta.get("page_total").ok_or("page_total not found")?.as_i64().ok_or("page_total not i32")?;
let total = meta.get("total").ok_or("total not found")?.as_i64().ok_or("total not i32")?;

// 太多guild,onebot无法处理这种情况
if total > 150 {
return None.ok_or("too many guild(>150),can't use get_group_list".to_owned())?;
}

for page in 1..page_total{
let guild_list = self.http_get_json(&format!("/guild/list?page={page}"),false).await?;
for it in guild_list.get("items").ok_or("items not found")?.as_array().ok_or("items not arr")? {
Expand Down Expand Up @@ -1499,6 +1506,22 @@ impl KookOnebot {
Ok(send_json)
}

async fn deal_ob_get_cookies(&self,params:&serde_json::Value,_js:&serde_json::Value,echo:&serde_json::Value) -> Result<serde_json::Value, Box<dyn std::error::Error + Send + Sync>> {
let domain = get_json_str(params,"domain");
if domain == "token" {
let send_json = serde_json::json!({
"status":"ok",
"retcode":0,
"data": {
"cookies":self.token
},
"echo":echo
});
return Ok(send_json);
}
return None.ok_or(format!("`{domain}` not support"))?;
}

async fn deal_onebot_sub(&self,text:&str,js:&serde_json::Value,echo:&serde_json::Value) -> Result<serde_json::Value, Box<dyn std::error::Error + Send + Sync>> {
let action = js.get("action").ok_or("action not found")?.as_str().ok_or("action not str")?;
let def = serde_json::json!({});
Expand Down Expand Up @@ -1555,7 +1578,10 @@ impl KookOnebot {
},
"get_group_member_list" => {
self.deal_ob_get_group_member_list(&params,&js,&echo).await?
}
},
"get_cookies" => {
self.deal_ob_get_cookies(&params,&js,&echo).await?
},
"can_send_image" => {
serde_json::json!({
"status":"ok",
Expand Down

0 comments on commit 13452ea

Please sign in to comment.