Skip to content

Commit

Permalink
api: send_music
Browse files Browse the repository at this point in the history
  • Loading branch information
lz1998 committed Aug 12, 2022
1 parent 0d32be0 commit 7a08c12
Show file tree
Hide file tree
Showing 5 changed files with 1,258 additions and 347 deletions.
2 changes: 1 addition & 1 deletion onebot_idl
30 changes: 30 additions & 0 deletions pkg/bot/api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,36 @@ func HandleSetGroupSignIn(cli *client.QQClient, req *onebot.SetGroupSignInReq) *
return nil
}

func HandleSendMusic(cli *client.QQClient, req *onebot.SendMusicReq) *onebot.SendMusicResp {
musicType := map[string]int{
"qq": message.QQMusic,
"163": message.CloudMusic,
"migu": message.MiguMusic,
"kugou": message.KugouMusic,
"kuwo": message.KuwoMusic,
}
music := &message.MusicShareElement{
MusicType: musicType[req.Type],
Title: req.Title,
Brief: req.Brief,
Summary: req.Summary,
Url: req.Url,
PictureUrl: req.PictureUrl,
MusicUrl: req.MusicUrl,
}
if req.GroupId != 0 {
if _, err := cli.SendGroupMusicShare(req.GroupId, music); err != nil {
return nil
}
return &onebot.SendMusicResp{}
}
if req.UserId != 0 {
cli.SendFriendMusicShare(req.UserId, music)
return &onebot.SendMusicResp{}
}
return nil
}

func HandleSendGroupPoke(cli *client.QQClient, req *onebot.SendGroupPokeReq) *onebot.SendGroupPokeResp {
group := cli.FindGroup(req.GroupId)
if group == nil {
Expand Down
8 changes: 8 additions & 0 deletions pkg/bot/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,14 @@ func handleApiFrame(cli *client.QQClient, req *onebot.Frame, isApiAllow func(one
resp.Data = &onebot.Frame_SetGroupSignInResp{
SetGroupSignInResp: HandleSetGroupSignIn(cli, data.SetGroupSignInReq),
}
case *onebot.Frame_SendMusicReq:
resp.FrameType = onebot.Frame_TSendMusicResp
if resp.Ok = isApiAllow(onebot.Frame_TSendMusicReq); !resp.Ok {
return
}
resp.Data = &onebot.Frame_SendMusicResp{
SendMusicResp: HandleSendMusic(cli, data.SendMusicReq),
}
case *onebot.Frame_SendGroupPokeReq:
resp.FrameType = onebot.Frame_TSendGroupPokeResp
if resp.Ok = isApiAllow(onebot.Frame_TSendGroupPokeReq); !resp.Ok {
Expand Down
Loading

0 comments on commit 7a08c12

Please sign in to comment.