Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,10 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] 酷我点歌[xxx]

- [x] 酷狗点歌[xxx]

- [x] qq点歌[xxx]

- [x] 咪咕点歌[xxx]

</details>
<details>
Expand Down
8 changes: 7 additions & 1 deletion console/console_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ func setConsoleTitle(title string) (err error) {
}

func init() {
debugMode := os.Getenv("DEBUG_MODE") == "1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是调试时会自动设置吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

launch.json加个参数
image
在不影响主要功能的时候,加个调试开关,要不然每次都要注释。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哦,我还以为是debugger的功能呢😂

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 // 禁用快速编辑模式
Expand Down
34 changes: 32 additions & 2 deletions plugin/music/selecter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 平台
Expand All @@ -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{
Expand Down
32 changes: 24 additions & 8 deletions plugin/score/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package score

import (
"os"
"sync"
"time"

"github.com/jinzhu/gorm"
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
}
Expand Down
Loading