Skip to content

Commit 9128524

Browse files
authored
Merge branch 'FloatTech:master' into master
2 parents a7ba29c + cb0ffa0 commit 9128524

File tree

8 files changed

+95
-28
lines changed

8 files changed

+95
-28
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,10 @@ print("run[CQ:image,file="+j["img"]+"]")
10261026
- [x] 酷我点歌[xxx]
10271027

10281028
- [x] 酷狗点歌[xxx]
1029+
1030+
- [x] qq点歌[xxx]
1031+
1032+
- [x] 咪咕点歌[xxx]
10291033

10301034
</details>
10311035
<details>

console/console_windows.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,18 @@ func setConsoleTitle(title string) (err error) {
3838
}
3939

4040
func init() {
41+
debugMode := os.Getenv("DEBUG_MODE") == "1"
4142
stdin := windows.Handle(os.Stdin.Fd())
4243

4344
var mode uint32
4445
err := windows.GetConsoleMode(stdin, &mode)
4546
if err != nil {
46-
panic(err)
47+
if debugMode {
48+
logrus.Warnf("调试模式下忽略控制台模式获取失败: %v", err)
49+
return // 调试模式下直接返回,跳过后续配置
50+
} else {
51+
panic(err) // 非调试模式下 panic
52+
}
4753
}
4854

4955
mode &^= windows.ENABLE_QUICK_EDIT_MODE // 禁用快速编辑模式

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/FloatTech/sqlite v1.7.1
1313
github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562
1414
github.com/FloatTech/zbpctrl v1.7.0
15-
github.com/FloatTech/zbputils v1.7.2-0.20250601113004-1bee2a7cd4b6
15+
github.com/FloatTech/zbputils v1.7.2-0.20250614165821-95cf57cf2434
1616
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7
1717
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5
1818
github.com/Tnze/go-mc v1.20.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562 h1:snfw7FNFym1eNnLrQ
1717
github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
1818
github.com/FloatTech/zbpctrl v1.7.0 h1:Hxo6EIhJo+pHjcQP9QgIJgluaT1pHH99zkk3njqTNMo=
1919
github.com/FloatTech/zbpctrl v1.7.0/go.mod h1:xmM4dSwHA02Gei3ogCRiG+RTrw/7Z69PfrN5NYf8BPE=
20-
github.com/FloatTech/zbputils v1.7.2-0.20250601113004-1bee2a7cd4b6 h1:85LGKvgkWMZU065WOIEVaaeHDNYK01CwdNr/m+jzTKw=
21-
github.com/FloatTech/zbputils v1.7.2-0.20250601113004-1bee2a7cd4b6/go.mod h1:ArZ0fMAcmPEIXOqDmfzbSx+oYH8sssApQnbCu694iS8=
20+
github.com/FloatTech/zbputils v1.7.2-0.20250614165821-95cf57cf2434 h1:oEYQFQ2/qx10FtZKCNbW3Ohj/Iw71aM4RWpIu+LMmf8=
21+
github.com/FloatTech/zbputils v1.7.2-0.20250614165821-95cf57cf2434/go.mod h1:ArZ0fMAcmPEIXOqDmfzbSx+oYH8sssApQnbCu694iS8=
2222
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
2323
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7 h1:S/ferNiehVjNaBMNNBxUjLtVmP/YWD6Yh79RfPv4ehU=
2424
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7/go.mod h1:vD7Ra3Q9onRtojoY5sMCLQ7JBgjUsrXDnDKyFxqpf9w=

gomod2nix.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ schema = 3
2929
version = "v1.7.0"
3030
hash = "sha256-HDDnE0oktWJH1tkxuQwUUbeJhmVwY5fyc/vR72D2mkU="
3131
[mod."github.com/FloatTech/zbputils"]
32-
version = "v1.7.2-0.20250601113004-1bee2a7cd4b6"
33-
hash = "sha256-pNL591h1gGP60wKEuvvF3DoshbaphoLze7Pa7gDA9bQ="
32+
version = "v1.7.2-0.20250614165821-95cf57cf2434"
33+
hash = "sha256-9r2nbDAo/ZCDSAXuOHUKaQM5bEoSOAFb0FJTDxne/gQ="
3434
[mod."github.com/RomiChan/syncx"]
3535
version = "v0.0.0-20240418144900-b7402ffdebc7"
3636
hash = "sha256-L1j1vgiwqXpF9pjMoRRlrQUHzoULisw/01plaEAwxs4="

plugin/music/selecter.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import (
2121
"github.com/wdvxdr1123/ZeroBot/message"
2222
)
2323

24+
var (
25+
longZhuURL = "https://www.hhlqilongzhu.cn/api/joox/juhe_music.php?msg=%v"
26+
)
27+
2428
func init() {
2529
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
2630
DisableOnDefault: false,
@@ -29,7 +33,8 @@ func init() {
2933
"- 网易点歌[xxx]\n" +
3034
"- 酷我点歌[xxx]\n" +
3135
"- 酷狗点歌[xxx]\n" +
32-
"- 咪咕点歌[xxx]",
36+
"- 咪咕点歌[xxx]\n" +
37+
"- qq点歌[xxx]\n",
3338
}).OnRegex(`^(.{0,2})点歌\s?(.{1,25})$`).SetBlock(true).Limit(ctxext.LimitByUser).
3439
Handle(func(ctx *zero.Ctx) {
3540
// switch 平台
@@ -42,12 +47,37 @@ func init() {
4247
ctx.SendChain(kugou(ctx.State["regex_matched"].([]string)[2]))
4348
case "网易":
4449
ctx.SendChain(cloud163(ctx.State["regex_matched"].([]string)[2]))
45-
default: // 默认 QQ音乐
50+
case "qq":
4651
ctx.SendChain(qqmusic(ctx.State["regex_matched"].([]string)[2]))
52+
default: // 默认聚合点歌
53+
ctx.SendChain(longzhu(ctx.State["regex_matched"].([]string)[2]))
4754
}
4855
})
4956
}
5057

58+
// longzhu 聚合平台
59+
func longzhu(keyword string) message.Segment {
60+
data, _ := web.GetData(fmt.Sprintf(longZhuURL, url.QueryEscape(keyword)))
61+
// 假设 data 是包含整个 JSON 数组的字节切片
62+
results := gjson.ParseBytes(data).Array()
63+
for _, result := range results {
64+
if strings.Contains(strings.ToLower(result.Get("title").String()), strings.ToLower(keyword)) {
65+
if musicURL := result.Get("full_track").String(); musicURL != "" {
66+
return message.Record(musicURL)
67+
}
68+
}
69+
}
70+
71+
results = gjson.GetBytes(data, "#.full_track").Array()
72+
if len(results) > 0 {
73+
if musicURL := results[0].String(); musicURL != "" {
74+
return message.Record(musicURL)
75+
}
76+
}
77+
78+
return message.Text("点歌失败, 找不到 ", keyword, " 的相关结果")
79+
}
80+
5181
// migu 返回咪咕音乐卡片
5282
func migu(keyword string) message.Segment {
5383
headers := http.Header{

plugin/niuniu/main.go

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func init() {
6565
messages = append(messages, ctxext.FakeSenderForwardNode(ctx, message.Text("牛牛拍卖行有以下牛牛")))
6666
for _, info := range auction {
6767
msg := fmt.Sprintf("商品序号: %d\n牛牛原所属: %d\n牛牛价格: %d%s\n牛牛大小: %.2fcm",
68-
info.ID+1, info.UserID, info.Money, wallet.GetWalletName(), info.Length)
68+
info.ID, info.UserID, info.Money, wallet.GetWalletName(), info.Length)
6969
messages = append(messages, ctxext.FakeSenderForwardNode(ctx, message.Text(msg)))
7070
}
7171
if id := ctx.Send(messages).ID(); id == 0 {
@@ -81,7 +81,7 @@ func init() {
8181
for {
8282
select {
8383
case <-timer.C:
84-
ctx.SendChain(message.At(uid), message.Text(" 超时,已自动取消"))
84+
ctx.SendChain(message.At(uid), message.Text(" 超时已自动取消"))
8585
return
8686
case r := <-recv:
8787
answer = r.Event.Message.String()
@@ -90,7 +90,6 @@ func init() {
9090
ctx.SendChain(message.Text("ERROR: ", err))
9191
return
9292
}
93-
n--
9493
msg, err := niu.Auction(gid, uid, n)
9594
if err != nil {
9695
ctx.SendChain(message.Text("ERROR:", err))
@@ -109,6 +108,12 @@ func init() {
109108
ctx.SendChain(message.Text("ERROR:", err))
110109
return
111110
}
111+
// 数据库操作成功之后,及时删除残留的缓存
112+
key := fmt.Sprintf("%d_%d", gid, uid)
113+
_, ok := jjCount.Load(key)
114+
if ok {
115+
jjCount.Delete(key)
116+
}
112117
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(sell))
113118
})
114119
en.OnFullMatch("牛牛背包", zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
@@ -145,7 +150,7 @@ func init() {
145150

146151
var messages message.Message
147152
messages = append(messages, ctxext.FakeSenderForwardNode(ctx, message.Text("牛牛商店当前售卖的物品如下")))
148-
for id := range propMap {
153+
for id := 1; id <= len(propMap); id++ {
149154
product := propMap[id]
150155
productInfo := fmt.Sprintf("商品%d\n商品名: %s\n商品价格: %dATRI币\n商品作用域: %s\n商品描述: %s\n使用次数:%d",
151156
id, product.name, product.cost, product.scope, product.description, product.count)
@@ -165,7 +170,7 @@ func init() {
165170
for {
166171
select {
167172
case <-timer.C:
168-
ctx.SendChain(message.At(uid), message.Text(" 超时,已自动取消"))
173+
ctx.SendChain(message.At(uid), message.Text(" 超时已自动取消"))
169174
return
170175
case r := <-recv:
171176
answer = r.Event.Message.String()
@@ -196,16 +201,16 @@ func init() {
196201
}
197202

198203
if time.Since(last.TimeLimit) > time.Hour {
199-
ctx.SendChain(message.Text("时间已经过期了,牛牛已被收回!"))
204+
ctx.SendChain(message.Text("时间已经过期了牛牛已被收回!"))
200205
jjCount.Delete(fmt.Sprintf("%d_%d", gid, uid))
201206
return
202207
}
203208

204209
if last.Count < 4 {
205-
ctx.SendChain(message.Text("你还没有被厥够4次呢,不能赎牛牛"))
210+
ctx.SendChain(message.Text("你还没有被厥够4次呢不能赎牛牛"))
206211
return
207212
}
208-
ctx.SendChain(message.Text("再次确认一下哦,这次赎牛牛,牛牛长度将会变成", last.Length, "cm\n还需要嘛【是|否】"))
213+
ctx.SendChain(message.Text("再次确认一下哦这次赎牛牛,牛牛长度将会变成", last.Length, "cm\n还需要嘛【是|否】"))
209214
recv, cancel := zero.NewFutureEvent("message", 999, false, zero.CheckUser(uid), zero.CheckGroup(gid), zero.RegexRule(`^(是|否)$`)).Repeat()
210215
defer cancel()
211216
timer := time.NewTimer(2 * time.Minute)
@@ -222,11 +227,11 @@ func init() {
222227
return
223228
}
224229

225-
if err := niu.Redeem(gid, uid, last.Length); err == nil {
230+
if err := niu.Redeem(gid, uid, last.Length); err != nil {
226231
ctx.SendChain(message.Text("ERROR:", err))
227232
return
228233
}
229-
234+
// 成功赎回,删除残留的缓存。
230235
jjCount.Delete(fmt.Sprintf("%d_%d", gid, uid))
231236

232237
ctx.SendChain(message.At(uid), message.Text(fmt.Sprintf("恭喜你!成功赎回牛牛,当前长度为:%.2fcm", last.Length)))
@@ -342,8 +347,9 @@ func init() {
342347
j := fmt.Sprintf("%d_%d", gid, adduser)
343348
count, ok := jjCount.Load(j)
344349
var c lastLength
345-
// 按照最后一次被jj时的时间计算,超过60分钟则重置
350+
// 按照最后一次被 jj 时的时间计算,超过60分钟则重置
346351
if !ok {
352+
// 第一次被 jj
347353
c = lastLength{
348354
TimeLimit: time.Now(),
349355
Count: 1,
@@ -355,6 +361,7 @@ func init() {
355361
Count: count.Count + 1,
356362
Length: count.Length,
357363
}
364+
// 超时了,重置
358365
if time.Since(c.TimeLimit) > time.Hour {
359366
c = lastLength{
360367
TimeLimit: time.Now(),
@@ -372,6 +379,9 @@ func init() {
372379
)))
373380

374381
if c.Count >= 4 {
382+
if c.Count == 6 {
383+
return
384+
}
375385
id := ctx.SendPrivateMessage(adduser,
376386
message.Text(fmt.Sprintf("你在%d群里已经被厥冒烟了,快去群里赎回你原本的牛牛!\n发送:`赎牛牛`即可!", gid)))
377387
if id == 0 {
@@ -386,7 +396,7 @@ func init() {
386396
key := fmt.Sprintf("%d_%d", gid, uid)
387397
data, ok := register.Load(key)
388398
switch {
389-
case !ok || time.Since(data.TimeLimit) > time.Hour*12:
399+
case !ok || time.Since(data.TimeLimit) > time.Hour*24:
390400
data = &lastLength{
391401
TimeLimit: time.Now(),
392402
Count: 1,
@@ -396,6 +406,7 @@ func init() {
396406
ctx.SendChain(message.Text("你的钱不够你注销牛牛了,这次注销需要", data.Count*50, wallet.GetWalletName()))
397407
return
398408
}
409+
data.Count++
399410
}
400411
register.Store(key, data)
401412
msg, err := niu.Cancel(gid, uid)

plugin/score/model.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package score
22

33
import (
44
"os"
5+
"sync"
56
"time"
67

78
"github.com/jinzhu/gorm"
@@ -11,7 +12,10 @@ import (
1112
var sdb *scoredb
1213

1314
// scoredb 分数数据库
14-
type scoredb gorm.DB
15+
type scoredb struct {
16+
db *gorm.DB
17+
scoremu sync.Mutex
18+
}
1519

1620
// scoretable 分数结构体
1721
type scoretable struct {
@@ -52,25 +56,31 @@ func initialize(dbpath string) *scoredb {
5256
panic(err)
5357
}
5458
gdb.AutoMigrate(&scoretable{}).AutoMigrate(&signintable{})
55-
return (*scoredb)(gdb)
59+
return &scoredb{
60+
db: gdb,
61+
}
5662
}
5763

5864
// Close ...
5965
func (sdb *scoredb) Close() error {
60-
db := (*gorm.DB)(sdb)
66+
db := sdb.db
6167
return db.Close()
6268
}
6369

6470
// GetScoreByUID 取得分数
6571
func (sdb *scoredb) GetScoreByUID(uid int64) (s scoretable) {
66-
db := (*gorm.DB)(sdb)
72+
sdb.scoremu.Lock()
73+
defer sdb.scoremu.Unlock()
74+
db := sdb.db
6775
db.Model(&scoretable{}).FirstOrCreate(&s, "uid = ? ", uid)
6876
return s
6977
}
7078

7179
// InsertOrUpdateScoreByUID 插入或更新分数
7280
func (sdb *scoredb) InsertOrUpdateScoreByUID(uid int64, score int) (err error) {
73-
db := (*gorm.DB)(sdb)
81+
sdb.scoremu.Lock()
82+
defer sdb.scoremu.Unlock()
83+
db := sdb.db
7484
s := scoretable{
7585
UID: uid,
7686
Score: score,
@@ -91,14 +101,18 @@ func (sdb *scoredb) InsertOrUpdateScoreByUID(uid int64, score int) (err error) {
91101

92102
// GetSignInByUID 取得签到次数
93103
func (sdb *scoredb) GetSignInByUID(uid int64) (si signintable) {
94-
db := (*gorm.DB)(sdb)
104+
sdb.scoremu.Lock()
105+
defer sdb.scoremu.Unlock()
106+
db := sdb.db
95107
db.Model(&signintable{}).FirstOrCreate(&si, "uid = ? ", uid)
96108
return si
97109
}
98110

99111
// InsertOrUpdateSignInCountByUID 插入或更新签到次数
100112
func (sdb *scoredb) InsertOrUpdateSignInCountByUID(uid int64, count int) (err error) {
101-
db := (*gorm.DB)(sdb)
113+
sdb.scoremu.Lock()
114+
defer sdb.scoremu.Unlock()
115+
db := sdb.db
102116
si := signintable{
103117
UID: uid,
104118
Count: count,
@@ -118,7 +132,9 @@ func (sdb *scoredb) InsertOrUpdateSignInCountByUID(uid int64, count int) (err er
118132
}
119133

120134
func (sdb *scoredb) GetScoreRankByTopN(n int) (st []scoretable, err error) {
121-
db := (*gorm.DB)(sdb)
135+
sdb.scoremu.Lock()
136+
defer sdb.scoremu.Unlock()
137+
db := sdb.db
122138
err = db.Model(&scoretable{}).Order("score desc").Limit(n).Find(&st).Error
123139
return
124140
}

0 commit comments

Comments
 (0)