mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-13 02:30:26 +00:00
🎨 改进代码结构
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
package setutime
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"bot/music/utils"
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
)
|
||||
|
||||
func init() {
|
||||
zero.RegisterPlugin(musicSelector{}) // 注册插件
|
||||
}
|
||||
|
||||
type musicSelector struct{} // musicSelector 点歌
|
||||
|
||||
func (_ musicSelector) GetPluginInfo() zero.PluginInfo { // 返回插件信息
|
||||
return zero.PluginInfo{
|
||||
Author: "kanri",
|
||||
PluginName: "MusicSelector",
|
||||
Version: "0.0.1",
|
||||
Details: "点歌",
|
||||
}
|
||||
}
|
||||
|
||||
func (_ musicSelector) Start() { // 插件主体
|
||||
// TODO 根据PID搜图
|
||||
zero.OnRegex(`点歌(.*)`).SetBlock(true).SetPriority(50).
|
||||
Handle(func(matcher *zero.Matcher, event zero.Event, state zero.State) zero.Response {
|
||||
music, err := utils.CloudMusic(state["regex_matched"].([]string)[1])
|
||||
if err != nil {
|
||||
utils.SendError(event, err)
|
||||
return zero.FinishResponse
|
||||
}
|
||||
// TODO 发送搜索结果
|
||||
zero.Send(
|
||||
event,
|
||||
fmt.Sprintf(
|
||||
"[CQ:music,type=%s,url=%s,audio=%s,title=%s,content=%s,image=%s]",
|
||||
music.Type,
|
||||
music.Url,
|
||||
music.Audio,
|
||||
music.Title,
|
||||
music.Content,
|
||||
music.Image,
|
||||
),
|
||||
)
|
||||
return zero.FinishResponse
|
||||
})
|
||||
}
|
||||
34
music/music_selecter.go
Normal file
34
music/music_selecter.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package setutime
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"bot/music/utils"
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
// TODO 根据PID搜图
|
||||
zero.OnRegex(`点歌(.*)`).SetBlock(true).SetPriority(50).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
music, err := utils.CloudMusic(ctx.State["regex_matched"].([]string)[1])
|
||||
if err != nil {
|
||||
ctx.Send(fmt.Sprintf("ERROR: %v", err))
|
||||
return
|
||||
}
|
||||
// TODO 发送搜索结果
|
||||
ctx.Send(
|
||||
fmt.Sprintf(
|
||||
"[CQ:music,type=%s,url=%s,audio=%s,title=%s,content=%s,image=%s]",
|
||||
music.Type,
|
||||
music.Url,
|
||||
music.Audio,
|
||||
music.Title,
|
||||
music.Content,
|
||||
music.Image,
|
||||
),
|
||||
)
|
||||
return
|
||||
})
|
||||
}
|
||||
@@ -1,11 +1,5 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
)
|
||||
|
||||
type CQMusic struct {
|
||||
Type string
|
||||
Url string
|
||||
@@ -14,7 +8,3 @@ type CQMusic struct {
|
||||
Content string
|
||||
Image string
|
||||
}
|
||||
|
||||
func SendError(event zero.Event, err error) {
|
||||
zero.Send(event, fmt.Sprintf("ERROR: %v", err))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user