Skip to content

Commit 7a08c12

Browse files
committed
api: send_music
1 parent 0d32be0 commit 7a08c12

File tree

5 files changed

+1258
-347
lines changed

5 files changed

+1258
-347
lines changed

onebot_idl

pkg/bot/api_handler.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,36 @@ func HandleSetGroupSignIn(cli *client.QQClient, req *onebot.SetGroupSignInReq) *
591591
return nil
592592
}
593593

594+
func HandleSendMusic(cli *client.QQClient, req *onebot.SendMusicReq) *onebot.SendMusicResp {
595+
musicType := map[string]int{
596+
"qq": message.QQMusic,
597+
"163": message.CloudMusic,
598+
"migu": message.MiguMusic,
599+
"kugou": message.KugouMusic,
600+
"kuwo": message.KuwoMusic,
601+
}
602+
music := &message.MusicShareElement{
603+
MusicType: musicType[req.Type],
604+
Title: req.Title,
605+
Brief: req.Brief,
606+
Summary: req.Summary,
607+
Url: req.Url,
608+
PictureUrl: req.PictureUrl,
609+
MusicUrl: req.MusicUrl,
610+
}
611+
if req.GroupId != 0 {
612+
if _, err := cli.SendGroupMusicShare(req.GroupId, music); err != nil {
613+
return nil
614+
}
615+
return &onebot.SendMusicResp{}
616+
}
617+
if req.UserId != 0 {
618+
cli.SendFriendMusicShare(req.UserId, music)
619+
return &onebot.SendMusicResp{}
620+
}
621+
return nil
622+
}
623+
594624
func HandleSendGroupPoke(cli *client.QQClient, req *onebot.SendGroupPokeReq) *onebot.SendGroupPokeResp {
595625
group := cli.FindGroup(req.GroupId)
596626
if group == nil {

pkg/bot/remote.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,14 @@ func handleApiFrame(cli *client.QQClient, req *onebot.Frame, isApiAllow func(one
380380
resp.Data = &onebot.Frame_SetGroupSignInResp{
381381
SetGroupSignInResp: HandleSetGroupSignIn(cli, data.SetGroupSignInReq),
382382
}
383+
case *onebot.Frame_SendMusicReq:
384+
resp.FrameType = onebot.Frame_TSendMusicResp
385+
if resp.Ok = isApiAllow(onebot.Frame_TSendMusicReq); !resp.Ok {
386+
return
387+
}
388+
resp.Data = &onebot.Frame_SendMusicResp{
389+
SendMusicResp: HandleSendMusic(cli, data.SendMusicReq),
390+
}
383391
case *onebot.Frame_SendGroupPokeReq:
384392
resp.FrameType = onebot.Frame_TSendGroupPokeResp
385393
if resp.Ok = isApiAllow(onebot.Frame_TSendGroupPokeReq); !resp.Ok {

0 commit comments

Comments
 (0)