From 112ad056559fd3c91558c0cd97f16377e8d27e06 Mon Sep 17 00:00:00 2001 From: lz1998 <875543533@qq.com> Date: Sun, 24 Jul 2022 22:17:41 +0800 Subject: [PATCH] api: send music --- idl/onebot_api.proto | 391 +++++++++++++++++++++-------------------- idl/onebot_frame.proto | 4 + src/api_handler.rs | 28 +++ 3 files changed, 235 insertions(+), 188 deletions(-) diff --git a/idl/onebot_api.proto b/idl/onebot_api.proto index bd9b0fd..5444c9b 100644 --- a/idl/onebot_api.proto +++ b/idl/onebot_api.proto @@ -4,185 +4,185 @@ import "onebot_base.proto"; message SendPrivateMsgReq{ - int64 user_id = 1; - repeated Message message = 2; - bool auto_escape = 3; + int64 user_id = 1; + repeated Message message = 2; + bool auto_escape = 3; } message SendPrivateMsgResp{ -// int32 message_id = 1; // 废弃 - MessageReceipt message_id = 2; + // int32 message_id = 1; // 废弃 + MessageReceipt message_id = 2; } message SendGroupMsgReq{ - int64 group_id = 1; - repeated Message message = 2; - bool auto_escape = 3; + int64 group_id = 1; + repeated Message message = 2; + bool auto_escape = 3; } message SendGroupMsgResp{ -// int32 message_id = 1; // 废弃 - MessageReceipt message_id = 2; + // int32 message_id = 1; // 废弃 + MessageReceipt message_id = 2; } message SendMsgReq{ - string message_type = 1; - int64 user_id = 2; - int64 group_id = 3; - repeated Message message = 4; - bool auto_escape = 5; + string message_type = 1; + int64 user_id = 2; + int64 group_id = 3; + repeated Message message = 4; + bool auto_escape = 5; } message SendMsgResp{ -// int32 message_id = 1; // 废弃 - MessageReceipt message_id = 2; + // int32 message_id = 1; // 废弃 + MessageReceipt message_id = 2; } message DeleteMsgReq{ -// int32 message_id = 1; - MessageReceipt message_id = 2; + // int32 message_id = 1; + MessageReceipt message_id = 2; } message DeleteMsgResp{ } message GetMsgReq{ - int32 message_id = 1; + int32 message_id = 1; } message GetMsgResp{ - int32 time = 1; - string message_type = 2; - int32 message_id = 3; - int32 real_id = 4; - Sender sender = 5; - repeated Message message = 6; - string raw_message = 7; - - - message Sender{ - int64 user_id = 1; - string nickname = 2; - string card = 3; - string sex = 4; - int32 age = 5; - string area = 6; - string level = 7; - string role = 8; - string title = 9; - } + int32 time = 1; + string message_type = 2; + int32 message_id = 3; + int32 real_id = 4; + Sender sender = 5; + repeated Message message = 6; + string raw_message = 7; + + + message Sender{ + int64 user_id = 1; + string nickname = 2; + string card = 3; + string sex = 4; + int32 age = 5; + string area = 6; + string level = 7; + string role = 8; + string title = 9; + } } // TODO 暂时不支持 message GetForwardMsgReq{ - string id = 1; + string id = 1; } message GetForwardMsgResp{ } message SendLikeReq{ - int64 user_id = 1; - int32 times = 2; + int64 user_id = 1; + int32 times = 2; } message SendLikeResp{ } message SetGroupKickReq{ - int64 group_id = 1; - int64 user_id = 2; - bool reject_add_request = 3; - repeated int64 user_ids = 4; + int64 group_id = 1; + int64 user_id = 2; + bool reject_add_request = 3; + repeated int64 user_ids = 4; } message SetGroupKickResp{ } message SetGroupBanReq{ - int64 group_id = 1; - int64 user_id = 2; - int32 duration = 3; + int64 group_id = 1; + int64 user_id = 2; + int32 duration = 3; } message SetGroupBanResp{ } message SetGroupAnonymousBanReq{ - int64 group_id = 1; - Anonymous anonymous = 2; - string anonymous_flag = 3; - string flag = 4; - int64 duration = 5; + int64 group_id = 1; + Anonymous anonymous = 2; + string anonymous_flag = 3; + string flag = 4; + int64 duration = 5; - message Anonymous{ - int64 id = 1; - string name = 2; - string flag = 3; - } + message Anonymous{ + int64 id = 1; + string name = 2; + string flag = 3; + } } message SetGroupAnonymousBanResp{ } message SetGroupWholeBanReq{ - int64 group_id = 1; - bool enable = 2; + int64 group_id = 1; + bool enable = 2; } message SetGroupWholeBanResp{ } message SetGroupAdminReq{ - int64 group_id = 1; - int64 user_id = 2; - bool enable = 3; + int64 group_id = 1; + int64 user_id = 2; + bool enable = 3; } message SetGroupAdminResp{ } message SetGroupAnonymousReq{ - int64 group_id = 1; - bool enable = 2; + int64 group_id = 1; + bool enable = 2; } message SetGroupAnonymousResp{ } message SetGroupCardReq{ - int64 group_id = 1; - int64 user_id = 2; - string card = 3; + int64 group_id = 1; + int64 user_id = 2; + string card = 3; } message SetGroupCardResp{ } message SetGroupNameReq{ - int64 group_id = 1; - string group_name = 2; + int64 group_id = 1; + string group_name = 2; } message SetGroupNameResp{ } message SetGroupLeaveReq{ - int64 group_id = 1; - bool is_dismiss = 2; + int64 group_id = 1; + bool is_dismiss = 2; } message SetGroupLeaveResp{ } message SetGroupSpecialTitleReq{ - int64 group_id = 1; - int64 user_id = 2; - string special_title = 3; - int64 duration = 4; + int64 group_id = 1; + int64 user_id = 2; + string special_title = 3; + int64 duration = 4; } message SetGroupSpecialTitleResp{ } message SetFriendAddRequestReq{ - string flag = 1; - bool approve = 2; - string remark = 3; + string flag = 1; + bool approve = 2; + string remark = 3; } message SetFriendAddRequestResp{ } message SetGroupAddRequestReq{ - string flag = 1; - string sub_type = 2; - string type = 3; - bool approve = 4; - string reason = 5; + string flag = 1; + string sub_type = 2; + string type = 3; + bool approve = 4; + string reason = 5; } message SetGroupAddRequestResp{ } @@ -190,67 +190,92 @@ message SetGroupAddRequestResp{ message GetLoginInfoReq{ } message GetLoginInfoResp{ - int64 user_id = 1; - string nickname = 2; + int64 user_id = 1; + string nickname = 2; } message GetStrangerInfoReq{ - int64 user_id = 1; - bool no_cache = 2; + int64 user_id = 1; + bool no_cache = 2; } message GetStrangerInfoResp{ - int64 user_id = 1; - string nickname = 2; - string sex = 3; - int32 age = 4; - int32 level = 5; // 扩展 - int64 login_days = 6; // 扩展 + int64 user_id = 1; + string nickname = 2; + string sex = 3; + int32 age = 4; + int32 level = 5; // 扩展 + int64 login_days = 6; // 扩展 } message GetFriendListReq{ } message GetFriendListResp{ - repeated Friend friend = 1; + repeated Friend friend = 1; - message Friend{ - int64 user_id = 1; - string nickname = 2; - string remark = 3; - } + message Friend{ + int64 user_id = 1; + string nickname = 2; + string remark = 3; + } } message GetGroupInfoReq{ - int64 group_id = 1; - bool no_cache = 2; + int64 group_id = 1; + bool no_cache = 2; } message GetGroupInfoResp{ - int64 group_id = 1; - string group_name = 2; - int32 member_count = 3; - int32 max_member_count = 4; + int64 group_id = 1; + string group_name = 2; + int32 member_count = 3; + int32 max_member_count = 4; } message GetGroupListReq{ } message GetGroupListResp{ - repeated Group group = 1; + repeated Group group = 1; - message Group{ - int64 group_id = 1; - string group_name = 2; - int32 member_count = 3; - int32 max_member_count = 4; - } + message Group{ + int64 group_id = 1; + string group_name = 2; + int32 member_count = 3; + int32 max_member_count = 4; + } } message GetGroupMemberInfoReq{ - int64 group_id = 1; - int64 user_id = 2; - bool no_cache = 3; + int64 group_id = 1; + int64 user_id = 2; + bool no_cache = 3; } message GetGroupMemberInfoResp{ + int64 group_id = 1; + int64 user_id = 2; + string nickname = 3; + string card = 4; + string sex = 5; + int32 age = 6; + string area = 7; + int64 join_time = 8; + int64 last_sent_time = 9; + string level = 10; + string role = 11; + bool unfriendly = 12; + string title = 13; + int64 title_expire_time = 14; + bool card_changeable = 15; +} + +message GetGroupMemberListReq{ + int64 group_id = 1; +} +message GetGroupMemberListResp{ + repeated GroupMember group_member = 1; + + + message GroupMember{ int64 group_id = 1; int64 user_id = 2; string nickname = 3; @@ -266,128 +291,103 @@ message GetGroupMemberInfoResp{ string title = 13; int64 title_expire_time = 14; bool card_changeable = 15; -} - -message GetGroupMemberListReq{ - int64 group_id = 1; -} -message GetGroupMemberListResp{ - repeated GroupMember group_member = 1; - - - message GroupMember{ - int64 group_id = 1; - int64 user_id = 2; - string nickname = 3; - string card = 4; - string sex = 5; - int32 age = 6; - string area = 7; - int64 join_time = 8; - int64 last_sent_time = 9; - string level = 10; - string role = 11; - bool unfriendly = 12; - string title = 13; - int64 title_expire_time = 14; - bool card_changeable = 15; - } + } } message GetGroupHonorInfoReq{ - int64 group_id = 1; - string type = 2; + int64 group_id = 1; + string type = 2; } message GetGroupHonorInfoResp{ - int64 group_id = 1; - CurrentTalkative current_talkative = 2; - repeated Honor talkative = 3; - repeated Honor performer = 4; - repeated Honor legend = 5; - repeated Honor strong_newbie = 6; - repeated Honor emotion = 7; - - - message CurrentTalkative{ - int64 user_id = 1; - string nickname = 2; - string avatar = 3; - int32 day_count = 4; - } - message Honor{ - int64 user_id = 1; - string nickname = 2; - string avatar = 3; - string description = 4; - } + int64 group_id = 1; + CurrentTalkative current_talkative = 2; + repeated Honor talkative = 3; + repeated Honor performer = 4; + repeated Honor legend = 5; + repeated Honor strong_newbie = 6; + repeated Honor emotion = 7; + + + message CurrentTalkative{ + int64 user_id = 1; + string nickname = 2; + string avatar = 3; + int32 day_count = 4; + } + message Honor{ + int64 user_id = 1; + string nickname = 2; + string avatar = 3; + string description = 4; + } } message GetCookiesReq{ - string domain = 1; + string domain = 1; } message GetCookiesResp{ - string cookies = 1; + string cookies = 1; } message GetCsrfTokenReq{ } message GetCsrfTokenResp{ - int32 token = 1; + int32 token = 1; } message GetCredentialsReq{ - string domain = 1; + string domain = 1; } message GetCredentialsResp{ - string cookies = 1; - int32 csrf_token = 2; + string cookies = 1; + int32 csrf_token = 2; } message GetRecordReq{ - string file = 1; - string out_format = 2; + string file = 1; + string out_format = 2; } message GetRecordResp{ - string file = 1; + string file = 1; } message GetImageReq{ - string file = 1; + string file = 1; } message GetImageResp{ - string file = 1; + string file = 1; } message CanSendImageReq{ } message CanSendImageResp{ - bool yes = 1; + bool yes = 1; } message CanSendRecordReq{ } message CanSendRecordResp{ - bool yes = 1; + bool yes = 1; } message GetStatusReq{ } message GetStatusResp{ - bool online = 1; - bool good = 2; + bool online = 1; + bool good = 2; } message GetVersionInfoReq{ } message GetVersionInfoResp{ - string app_name = 1; - string app_version = 2; - string protocol_version = 3; - map extra = 4; + string app_name = 1; + string app_version = 2; + string protocol_version = 3; + map extra = 4; } message SetRestartReq{ - int32 delay = 1; + int32 delay = 1; } message SetRestartResp{ } @@ -398,7 +398,22 @@ message CleanCacheResp{ } message SetGroupSignInReq{ - int64 group_id = 1; + int64 group_id = 1; } message SetGroupSignInResp{ } + +message SendMusicReq{ + int64 group_id = 1; + int64 user_id = 2; + string type = 3; + string title = 4; + string brief = 5; + string summary = 6; + string url = 7; + string picture_url = 8; + string music_url = 9; +} +message SendMusicResp{ + +} \ No newline at end of file diff --git a/idl/onebot_frame.proto b/idl/onebot_frame.proto index 96110dd..4a11daf 100644 --- a/idl/onebot_frame.proto +++ b/idl/onebot_frame.proto @@ -63,6 +63,7 @@ message Frame{ SetRestartReq set_restart_req = 237; CleanCacheReq clean_cache_req = 238; SetGroupSignInReq set_group_sign_in_req = 239; + SendMusicReq send_music_req = 240; SendPrivateMsgResp send_private_msg_resp = 301; SendGroupMsgResp send_group_msg_resp = 302; @@ -103,6 +104,7 @@ message Frame{ SetRestartResp set_restart_resp = 337; CleanCacheResp clean_cache_resp = 338; SetGroupSignInResp set_group_sign_in_resp = 339; + SendMusicResp send_music_resp = 340; } enum FrameType{ @@ -160,6 +162,7 @@ message Frame{ TSetRestartReq = 237; TCleanCacheReq = 238; TSetGroupSignInReq = 239; + TSendMusicReq = 240; TSendPrivateMsgResp = 301; @@ -201,5 +204,6 @@ message Frame{ TSetRestartResp = 337; TCleanCacheResp = 338; TSetGroupSignInResp = 339; + TSendMusicResp = 340; } } diff --git a/src/api_handler.rs b/src/api_handler.rs index 6bf143f..b09d987 100644 --- a/src/api_handler.rs +++ b/src/api_handler.rs @@ -2,6 +2,7 @@ use std::sync::Arc; use std::time::Duration; use ricq::structs::GroupMemberPermission; +use ricq_core::command::oidb_svc::music::{MusicShare, MusicType}; use crate::bot::Bot; use crate::error::{RCError, RCResult}; @@ -108,6 +109,7 @@ pub async fn handle_api_data(bot: &Arc, data: Data) -> Option { Data::SetGroupSignInReq(req) => handle_set_group_sign_in(bot, req) .await .map(Data::SetGroupSignInResp), + Data::SendMusicReq(req) => handle_send_music(bot, req).await.map(Data::SendMusicResp), _ => Err(RCError::None("api_req not supported")), } .ok() @@ -482,3 +484,29 @@ pub async fn handle_set_group_sign_in( bot.client.group_sign_in(req.group_id).await?; Ok(SetGroupSignInResp {}) } + +pub async fn handle_send_music(bot: &Arc, req: SendMusicReq) -> RCResult { + let music_share = MusicShare { + title: req.title, + brief: req.brief, + summary: req.summary, + url: req.url, + picture_url: req.picture_url, + music_url: req.music_url, + }; + let music_type = match req.r#type.as_str() { + "qq" => MusicType::QQ, + "cloud" => MusicType::Cloud, + _ => MusicType::QQ, + }; + if req.group_id != 0 { + bot.client + .send_friend_music_share(req.user_id, music_share, music_type) + .await?; + } else { + bot.client + .send_group_music_share(req.group_id, music_share, music_type) + .await?; + } + Ok(SendMusicResp {}) +}