mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-18 20:50:12 +08:00
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
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:
parent
0615993297
commit
cb0ffa0c17
@ -1026,6 +1026,10 @@ print("run[CQ:image,file="+j["img"]+"]")
|
|||||||
- [x] 酷我点歌[xxx]
|
- [x] 酷我点歌[xxx]
|
||||||
|
|
||||||
- [x] 酷狗点歌[xxx]
|
- [x] 酷狗点歌[xxx]
|
||||||
|
|
||||||
|
- [x] qq点歌[xxx]
|
||||||
|
|
||||||
|
- [x] 咪咕点歌[xxx]
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
<details>
|
<details>
|
||||||
|
|||||||
@ -38,12 +38,18 @@ func setConsoleTitle(title string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
debugMode := os.Getenv("DEBUG_MODE") == "1"
|
||||||
stdin := windows.Handle(os.Stdin.Fd())
|
stdin := windows.Handle(os.Stdin.Fd())
|
||||||
|
|
||||||
var mode uint32
|
var mode uint32
|
||||||
err := windows.GetConsoleMode(stdin, &mode)
|
err := windows.GetConsoleMode(stdin, &mode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
if debugMode {
|
||||||
|
logrus.Warnf("调试模式下忽略控制台模式获取失败: %v", err)
|
||||||
|
return // 调试模式下直接返回,跳过后续配置
|
||||||
|
} else {
|
||||||
|
panic(err) // 非调试模式下 panic
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mode &^= windows.ENABLE_QUICK_EDIT_MODE // 禁用快速编辑模式
|
mode &^= windows.ENABLE_QUICK_EDIT_MODE // 禁用快速编辑模式
|
||||||
|
|||||||
@ -21,6 +21,10 @@ import (
|
|||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
longZhuURL = "https://www.hhlqilongzhu.cn/api/joox/juhe_music.php?msg=%v"
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
@ -29,7 +33,8 @@ func init() {
|
|||||||
"- 网易点歌[xxx]\n" +
|
"- 网易点歌[xxx]\n" +
|
||||||
"- 酷我点歌[xxx]\n" +
|
"- 酷我点歌[xxx]\n" +
|
||||||
"- 酷狗点歌[xxx]\n" +
|
"- 酷狗点歌[xxx]\n" +
|
||||||
"- 咪咕点歌[xxx]",
|
"- 咪咕点歌[xxx]\n" +
|
||||||
|
"- qq点歌[xxx]\n",
|
||||||
}).OnRegex(`^(.{0,2})点歌\s?(.{1,25})$`).SetBlock(true).Limit(ctxext.LimitByUser).
|
}).OnRegex(`^(.{0,2})点歌\s?(.{1,25})$`).SetBlock(true).Limit(ctxext.LimitByUser).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
// switch 平台
|
// switch 平台
|
||||||
@ -42,12 +47,37 @@ func init() {
|
|||||||
ctx.SendChain(kugou(ctx.State["regex_matched"].([]string)[2]))
|
ctx.SendChain(kugou(ctx.State["regex_matched"].([]string)[2]))
|
||||||
case "网易":
|
case "网易":
|
||||||
ctx.SendChain(cloud163(ctx.State["regex_matched"].([]string)[2]))
|
ctx.SendChain(cloud163(ctx.State["regex_matched"].([]string)[2]))
|
||||||
default: // 默认 QQ音乐
|
case "qq":
|
||||||
ctx.SendChain(qqmusic(ctx.State["regex_matched"].([]string)[2]))
|
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 返回咪咕音乐卡片
|
// migu 返回咪咕音乐卡片
|
||||||
func migu(keyword string) message.Segment {
|
func migu(keyword string) message.Segment {
|
||||||
headers := http.Header{
|
headers := http.Header{
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package score
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
@ -11,7 +12,10 @@ import (
|
|||||||
var sdb *scoredb
|
var sdb *scoredb
|
||||||
|
|
||||||
// scoredb 分数数据库
|
// scoredb 分数数据库
|
||||||
type scoredb gorm.DB
|
type scoredb struct {
|
||||||
|
db *gorm.DB
|
||||||
|
scoremu sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
// scoretable 分数结构体
|
// scoretable 分数结构体
|
||||||
type scoretable struct {
|
type scoretable struct {
|
||||||
@ -52,25 +56,31 @@ func initialize(dbpath string) *scoredb {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
gdb.AutoMigrate(&scoretable{}).AutoMigrate(&signintable{})
|
gdb.AutoMigrate(&scoretable{}).AutoMigrate(&signintable{})
|
||||||
return (*scoredb)(gdb)
|
return &scoredb{
|
||||||
|
db: gdb,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close ...
|
// Close ...
|
||||||
func (sdb *scoredb) Close() error {
|
func (sdb *scoredb) Close() error {
|
||||||
db := (*gorm.DB)(sdb)
|
db := sdb.db
|
||||||
return db.Close()
|
return db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetScoreByUID 取得分数
|
// GetScoreByUID 取得分数
|
||||||
func (sdb *scoredb) GetScoreByUID(uid int64) (s scoretable) {
|
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)
|
db.Model(&scoretable{}).FirstOrCreate(&s, "uid = ? ", uid)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// InsertOrUpdateScoreByUID 插入或更新分数
|
// InsertOrUpdateScoreByUID 插入或更新分数
|
||||||
func (sdb *scoredb) InsertOrUpdateScoreByUID(uid int64, score int) (err error) {
|
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{
|
s := scoretable{
|
||||||
UID: uid,
|
UID: uid,
|
||||||
Score: score,
|
Score: score,
|
||||||
@ -91,14 +101,18 @@ func (sdb *scoredb) InsertOrUpdateScoreByUID(uid int64, score int) (err error) {
|
|||||||
|
|
||||||
// GetSignInByUID 取得签到次数
|
// GetSignInByUID 取得签到次数
|
||||||
func (sdb *scoredb) GetSignInByUID(uid int64) (si signintable) {
|
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)
|
db.Model(&signintable{}).FirstOrCreate(&si, "uid = ? ", uid)
|
||||||
return si
|
return si
|
||||||
}
|
}
|
||||||
|
|
||||||
// InsertOrUpdateSignInCountByUID 插入或更新签到次数
|
// InsertOrUpdateSignInCountByUID 插入或更新签到次数
|
||||||
func (sdb *scoredb) InsertOrUpdateSignInCountByUID(uid int64, count int) (err error) {
|
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{
|
si := signintable{
|
||||||
UID: uid,
|
UID: uid,
|
||||||
Count: count,
|
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) {
|
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
|
err = db.Model(&scoretable{}).Order("score desc").Limit(n).Find(&st).Error
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user