feat(music): 龙珠聚合搜索 (#1179)
Some checks failed
打包最新版为 Docker Image / build docker (push) Has been cancelled
最新版 / Build binary CI (386, linux) (push) Has been cancelled
最新版 / Build binary CI (386, windows) (push) Has been cancelled
最新版 / Build binary CI (amd64, linux) (push) Has been cancelled
最新版 / Build binary CI (amd64, windows) (push) Has been cancelled
最新版 / Build binary CI (arm, linux) (push) Has been cancelled
最新版 / Build binary CI (arm64, linux) (push) Has been cancelled
PushLint / lint (push) Has been cancelled

* 🐛 修改听歌问题

*  添加龙珠聚合搜索

* 🎨 优化聚合搜索

* 🐛 一定能点出歌

* 🎨 删除调试
This commit is contained in:
himawari 2025-07-05 17:05:28 +08:00 committed by GitHub
parent 0615993297
commit cb0ffa0c17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 67 additions and 11 deletions

View File

@ -1027,6 +1027,10 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] 酷狗点歌[xxx]
- [x] qq点歌[xxx]
- [x] 咪咕点歌[xxx]
</details>
<details>
<summary>本地涩图</summary>

View File

@ -38,12 +38,18 @@ func setConsoleTitle(title string) (err error) {
}
func init() {
debugMode := os.Getenv("DEBUG_MODE") == "1"
stdin := windows.Handle(os.Stdin.Fd())
var mode uint32
err := windows.GetConsoleMode(stdin, &mode)
if err != nil {
panic(err)
if debugMode {
logrus.Warnf("调试模式下忽略控制台模式获取失败: %v", err)
return // 调试模式下直接返回,跳过后续配置
} else {
panic(err) // 非调试模式下 panic
}
}
mode &^= windows.ENABLE_QUICK_EDIT_MODE // 禁用快速编辑模式

View File

@ -21,6 +21,10 @@ import (
"github.com/wdvxdr1123/ZeroBot/message"
)
var (
longZhuURL = "https://www.hhlqilongzhu.cn/api/joox/juhe_music.php?msg=%v"
)
func init() {
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
@ -29,7 +33,8 @@ func init() {
"- 网易点歌[xxx]\n" +
"- 酷我点歌[xxx]\n" +
"- 酷狗点歌[xxx]\n" +
"- 咪咕点歌[xxx]",
"- 咪咕点歌[xxx]\n" +
"- qq点歌[xxx]\n",
}).OnRegex(`^(.{0,2})点歌\s?(.{1,25})$`).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
// switch 平台
@ -42,12 +47,37 @@ func init() {
ctx.SendChain(kugou(ctx.State["regex_matched"].([]string)[2]))
case "网易":
ctx.SendChain(cloud163(ctx.State["regex_matched"].([]string)[2]))
default: // 默认 QQ音乐
case "qq":
ctx.SendChain(qqmusic(ctx.State["regex_matched"].([]string)[2]))
default: // 默认聚合点歌
ctx.SendChain(longzhu(ctx.State["regex_matched"].([]string)[2]))
}
})
}
// longzhu 聚合平台
func longzhu(keyword string) message.Segment {
data, _ := web.GetData(fmt.Sprintf(longZhuURL, url.QueryEscape(keyword)))
// 假设 data 是包含整个 JSON 数组的字节切片
results := gjson.ParseBytes(data).Array()
for _, result := range results {
if strings.Contains(strings.ToLower(result.Get("title").String()), strings.ToLower(keyword)) {
if musicURL := result.Get("full_track").String(); musicURL != "" {
return message.Record(musicURL)
}
}
}
results = gjson.GetBytes(data, "#.full_track").Array()
if len(results) > 0 {
if musicURL := results[0].String(); musicURL != "" {
return message.Record(musicURL)
}
}
return message.Text("点歌失败, 找不到 ", keyword, " 的相关结果")
}
// migu 返回咪咕音乐卡片
func migu(keyword string) message.Segment {
headers := http.Header{

View File

@ -2,6 +2,7 @@ package score
import (
"os"
"sync"
"time"
"github.com/jinzhu/gorm"
@ -11,7 +12,10 @@ import (
var sdb *scoredb
// scoredb 分数数据库
type scoredb gorm.DB
type scoredb struct {
db *gorm.DB
scoremu sync.Mutex
}
// scoretable 分数结构体
type scoretable struct {
@ -52,25 +56,31 @@ func initialize(dbpath string) *scoredb {
panic(err)
}
gdb.AutoMigrate(&scoretable{}).AutoMigrate(&signintable{})
return (*scoredb)(gdb)
return &scoredb{
db: gdb,
}
}
// Close ...
func (sdb *scoredb) Close() error {
db := (*gorm.DB)(sdb)
db := sdb.db
return db.Close()
}
// GetScoreByUID 取得分数
func (sdb *scoredb) GetScoreByUID(uid int64) (s scoretable) {
db := (*gorm.DB)(sdb)
sdb.scoremu.Lock()
defer sdb.scoremu.Unlock()
db := sdb.db
db.Model(&scoretable{}).FirstOrCreate(&s, "uid = ? ", uid)
return s
}
// InsertOrUpdateScoreByUID 插入或更新分数
func (sdb *scoredb) InsertOrUpdateScoreByUID(uid int64, score int) (err error) {
db := (*gorm.DB)(sdb)
sdb.scoremu.Lock()
defer sdb.scoremu.Unlock()
db := sdb.db
s := scoretable{
UID: uid,
Score: score,
@ -91,14 +101,18 @@ func (sdb *scoredb) InsertOrUpdateScoreByUID(uid int64, score int) (err error) {
// GetSignInByUID 取得签到次数
func (sdb *scoredb) GetSignInByUID(uid int64) (si signintable) {
db := (*gorm.DB)(sdb)
sdb.scoremu.Lock()
defer sdb.scoremu.Unlock()
db := sdb.db
db.Model(&signintable{}).FirstOrCreate(&si, "uid = ? ", uid)
return si
}
// InsertOrUpdateSignInCountByUID 插入或更新签到次数
func (sdb *scoredb) InsertOrUpdateSignInCountByUID(uid int64, count int) (err error) {
db := (*gorm.DB)(sdb)
sdb.scoremu.Lock()
defer sdb.scoremu.Unlock()
db := sdb.db
si := signintable{
UID: uid,
Count: count,
@ -118,7 +132,9 @@ func (sdb *scoredb) InsertOrUpdateSignInCountByUID(uid int64, count int) (err er
}
func (sdb *scoredb) GetScoreRankByTopN(n int) (st []scoretable, err error) {
db := (*gorm.DB)(sdb)
sdb.scoremu.Lock()
defer sdb.scoremu.Unlock()
db := sdb.db
err = db.Model(&scoretable{}).Order("score desc").Limit(n).Find(&st).Error
return
}