Skip to content

Commit 62894dd

Browse files
committed
* https://github.com/FloatTech/ZeroBot-Plugin: feat: add plugin 抽扑克牌 (FloatTech#906) fix(workflow): pr not work properly Revert "feat: add plugin 抽扑克! (FloatTech#903)" (FloatTech#905) feat: add plugin 抽扑克! (FloatTech#903) [dish] fix: 关键词搜寻功能 (FloatTech#904) 修复 FullMatchRule 中调用 ctx.NickName() 的 panic 问题 (FloatTech#902) optimize: gif plugin for image cache (FloatTech#901) (fix FloatTech#900) Update guessmusic plugin (FloatTech#898) make lint happy add robbery plugin (FloatTech#893) [mcfish] Add one click selling (FloatTech#894)
2 parents c86ca47 + 3faabc4 commit 62894dd

15 files changed

Lines changed: 406 additions & 44 deletions

File tree

.github/workflows/pull.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ jobs:
2929
go-version: '1.20'
3030

3131
- name: Check out code into the Go module directory
32-
uses: actions/checkout@master
32+
uses: actions/checkout@v4
33+
with:
34+
ref: ${{ github.event.pull_request.head.sha }}
3335

3436
- name: golangci-lint
3537
uses: golangci/golangci-lint-action@master

.golangci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ run:
6161

6262
# output configuration options
6363
output:
64-
formats: ["colored-line-number"]
64+
formats:
65+
- format: "colored-line-number"
6566
print-issued-lines: true
6667
print-linter-name: true
6768
uniq-by-line: true

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ print("run[CQ:image,file="+j["img"]+"]")
900900

901901
- [x] 钓鱼商店
902902
- [x] 购买xxx [数量]
903-
- [x] 出售xxx [数量]
903+
- [x] 出售[xxx [数量]|所有垃圾]
904904
- [x] 钓鱼背包
905905
- [x] 装备[xx竿|三叉戟|美西螈]
906906
- [x] 附魔[诱钓|海之眷顾]
@@ -1069,6 +1069,14 @@ print("run[CQ:image,file="+j["img"]+"]")
10691069

10701070
- [x] 解签
10711071

1072+
</details>
1073+
<details>
1074+
<summary>抽扑克</summary>
1075+
1076+
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/poker"`
1077+
1078+
- [x] 抽扑克牌
1079+
10721080
</details>
10731081
<details>
10741082
<summary>一群一天一夫一妻制群老婆</summary>
@@ -1135,6 +1143,14 @@ print("run[CQ:image,file="+j["img"]+"]")
11351143

11361144
- 注:本插件来源于[tgbot](https://github.com/YukariChiba/tgbot/blob/main/modules/Reborn.py)
11371145

1146+
</details>
1147+
<details>
1148+
<summary>打劫</summary>
1149+
1150+
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/robbery"`
1151+
1152+
- [x] 打劫[对方Q号|@对方QQ]
1153+
11381154
</details>
11391155
<details>
11401156
<summary>在线代码运行</summary>

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,12 @@ import (
115115
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/nsfw" // nsfw图片识别
116116
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/nwife" // 本地老婆
117117
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/omikuji" // 浅草寺求签
118+
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/poker" // 抽扑克
118119
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/qqwife" // 一群一天一夫一妻制群老婆
119120
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/qzone" // qq空间表白墙
120121
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/realcugan" // realcugan清晰术
121122
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/reborn" // 投胎
123+
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/robbery" // 打劫群友的ATRI币
122124
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/runcode" // 在线运行代码
123125
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/saucenao" // 以图搜图
124126
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/score" // 分数

plugin/dish/dish.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ func init() {
7777
}
7878

7979
var d dish
80-
if err := db.Find("dish", &d, fmt.Sprintf("WHERE name like %%%s%%", dishName)); err != nil {
80+
if err := db.Find("dish", &d, fmt.Sprintf("WHERE name like '%%%s%%'", dishName)); err != nil {
81+
ctx.SendChain(message.Text("客官,本店没有" + dishName))
8182
return
8283
}
8384

@@ -86,7 +87,7 @@ func init() {
8687
"原材料:%s\n"+
8788
"步骤:\n"+
8889
"%s",
89-
name, dishName, d.Materials, d.Steps),
90+
name, d.Name, d.Materials, d.Steps),
9091
))
9192
})
9293

@@ -96,7 +97,7 @@ func init() {
9697
return
9798
}
9899

99-
name := ctx.NickName()
100+
name := ctx.CardOrNickName(ctx.Event.UserID)
100101
var d dish
101102
if err := db.Pick("dish", &d); err != nil {
102103
ctx.SendChain(message.Text("小店好像出错了,暂时端不出菜来惹"))

plugin/gif/context.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ func dlrange(prefix string, end int, wg *sync.WaitGroup, exit func(error)) []str
8787
}
8888

8989
// 新的上下文
90-
func newContext(user int64) *context {
90+
func newContext(user int64, atUser int64) *context {
9191
c := new(context)
92-
c.usrdir = datapath + "users/" + strconv.FormatInt(user, 10) + `/`
92+
c.usrdir = datapath + "users/" + strconv.FormatInt(atUser, 10) + `/`
9393
_ = os.MkdirAll(c.usrdir, 0755)
9494
c.headimgsdir = make([]string, 2)
95-
c.headimgsdir[0] = c.usrdir + "0.gif"
96-
c.headimgsdir[1] = c.usrdir + "1.gif"
95+
c.headimgsdir[0] = datapath + "users/" + strconv.FormatInt(atUser, 10) + ".gif"
96+
c.headimgsdir[1] = datapath + "users/" + strconv.FormatInt(user, 10) + ".gif"
9797
return c
9898
}
9999

plugin/gif/logo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ func (cc *context) prepareLogos(s ...string) error {
1414
for i, v := range s {
1515
_, err := strconv.Atoi(v)
1616
if err != nil {
17-
err = file.DownloadTo("https://gchat.qpic.cn/gchatpic_new//--"+strings.ToUpper(v)+"/0", cc.usrdir+strconv.Itoa(i)+".gif")
17+
err = file.DownloadTo("https://gchat.qpic.cn/gchatpic_new//--"+strings.ToUpper(v)+"/0", cc.headimgsdir[i])
1818
} else {
19-
err = file.DownloadTo("http://q4.qlogo.cn/g?b=qq&nk="+v+"&s=640", cc.usrdir+strconv.Itoa(i)+".gif")
19+
err = file.DownloadTo("http://q4.qlogo.cn/g?b=qq&nk="+v+"&s=640", cc.headimgsdir[i])
2020
}
2121
if err != nil {
2222
return err

plugin/gif/run.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ func init() { // 插件主体
152152
datapath = file.BOTPATH + "/" + en.DataFolder()
153153
en.OnRegex(`^(` + strings.Join(cmd, "|") + `)[\s\S]*?(\[CQ:(image\,file=([0-9a-zA-Z]{32}).*|at.+?(\d{5,11}))\].*|(\d+))$`).
154154
SetBlock(true).Handle(func(ctx *zero.Ctx) {
155-
c := newContext(ctx.Event.UserID)
156155
list := ctx.State["regex_matched"].([]string)
156+
atUserID, _ := strconv.ParseInt(list[4]+list[5]+list[6], 10, 64)
157+
c := newContext(ctx.Event.UserID, atUserID)
157158
err := c.prepareLogos(list[4]+list[5]+list[6], strconv.FormatInt(ctx.Event.UserID, 10))
158159
if err != nil {
159160
ctx.SendChain(message.Text("ERROR: ", err))

plugin/guessmusic/guessmusic.go

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ func init() {
109109
ctx.SendChain(message.Text(err))
110110
return
111111
}
112+
// 猜歌环节-提供猜歌选项
113+
files, err := os.ReadDir(pathOfMusic)
114+
if err != nil {
115+
return
116+
}
117+
getMusicSelect(ctx, files, musicName)
112118
// 进行猜歌环节
113119
ctx.SendChain(message.Record("file:///" + file.BOTPATH + "/" + outputPath + "0.wav"))
114120
var next *zero.FutureEvent
@@ -221,26 +227,8 @@ func musicLottery(musicPath, listName string) (pathOfMusic, musicName string, er
221227
}
222228
return
223229
}
224-
// 进行随机抽取
225-
if playlistID == 0 || !cfg.API {
226-
musicName = getLocalMusic(files, 10)
227-
} else {
228-
switch rand.Intn(3) { // 三分二概率抽取API的
229-
case 1:
230-
musicName = getLocalMusic(files, 10)
231-
default:
232-
if cfg.APIURL == "" {
233-
// 如果没有配置过API地址,尝试连接独角兽
234-
musicName, err = downloadByOvooa(playlistID, pathOfMusic)
235-
} else {
236-
// 从API中抽取歌曲
237-
musicName, err = drawByAPI(playlistID, pathOfMusic)
238-
}
239-
if err != nil {
240-
musicName = getLocalMusic(files, 10)
241-
}
242-
}
243-
}
230+
// 只猜本地已经下好的歌曲
231+
musicName = getLocalMusic(files, 10)
244232
if musicName == "" {
245233
err = errors.New("抽取歌曲轮空了,请重试")
246234
}
@@ -295,15 +283,13 @@ func cutMusic(musicName, pathOfMusic, outputPath string) (err error) {
295283
// 数据匹配(结果信息,答题次数,提示次数,是否结束游戏)
296284
func gameMatch(c *zero.Ctx, beginner int64, musicInfo []string, answerTimes, tickTimes int) (message.MessageSegment, int, int, bool) {
297285
answer := strings.Replace(c.Event.Message.String(), "-", "", 1)
298-
// 大小写,简繁体转换
286+
// 回答内容转小写,比对时再把标准答案转小写
299287
answer = ConvertText(answer)
300-
for i, element := range musicInfo {
301-
musicInfo[i] = ConvertText(element)
302-
}
288+
303289
switch {
304290
case answer == "取消":
305291
if c.Event.UserID == beginner {
306-
return message.Text("游戏已取消,猜歌答案是\n", musicInfo[len(musicInfo)-1], "\n\n\n下面欣赏猜歌的歌曲"), answerTimes, tickTimes, true
292+
return message.Text("游戏已取消,猜歌答案是\n", musicInfo[len(musicInfo)-1], "\n\n下面欣赏猜歌的歌曲"), answerTimes, tickTimes, true
307293
}
308294
return message.Text("你无权限取消"), answerTimes, tickTimes, false
309295
case answer == "提示":
@@ -312,11 +298,11 @@ func gameMatch(c *zero.Ctx, beginner int64, musicInfo []string, answerTimes, tic
312298
return message.Text("已经没有提示了哦"), answerTimes, tickTimes, false
313299
}
314300
return message.Text("再听这段音频,要仔细听哦"), answerTimes, tickTimes, false
315-
case strings.Contains(musicInfo[0], answer) || strings.EqualFold(musicInfo[0], answer):
301+
case strings.Contains(ConvertText(musicInfo[0]), answer) || strings.EqualFold(ConvertText(musicInfo[0]), answer):
316302
return message.Text("太棒了,你猜对歌曲名了!答案是\n", musicInfo[len(musicInfo)-1], "\n\n下面欣赏猜歌的歌曲"), answerTimes, tickTimes, true
317-
case strings.Contains(musicInfo[1], answer) || strings.EqualFold(musicInfo[1], answer):
303+
case strings.Contains(ConvertText(musicInfo[1]), answer) || strings.EqualFold(ConvertText(musicInfo[1]), answer):
318304
return message.Text("太棒了,你猜对歌手名了!答案是\n", musicInfo[len(musicInfo)-1], "\n\n下面欣赏猜歌的歌曲"), answerTimes, tickTimes, true
319-
case len(musicInfo) == 4 && (strings.Contains(musicInfo[2], answer) || strings.EqualFold(musicInfo[2], answer)):
305+
case len(musicInfo) == 4 && (strings.Contains(ConvertText(musicInfo[2]), answer) || strings.EqualFold(ConvertText(musicInfo[2]), answer)):
320306
return message.Text("太棒了,你猜对相关信息了!答案是\n", musicInfo[len(musicInfo)-1], "\n\n下面欣赏猜歌的歌曲"), answerTimes, tickTimes, true
321307
default:
322308
answerTimes++
@@ -343,3 +329,39 @@ func ConvertText(input string) string {
343329
}
344330
return toLower
345331
}
332+
333+
func getMusicSelect(ctx *zero.Ctx, files []fs.DirEntry, musicName string) {
334+
// 生成音乐选项
335+
var musicInfo []string
336+
musicInfo = append(musicInfo, musicName)
337+
for i := 1; i < 4; i++ {
338+
musicInfo = append(musicInfo, getLocalMusic(files, 10))
339+
for musicInfo[0] == musicInfo[i] {
340+
musicInfo[i] = getLocalMusic(files, 10)
341+
}
342+
}
343+
// 对调正确答案
344+
j := rand.Intn(len(musicInfo))
345+
musicInfo[0], musicInfo[j] = musicInfo[j], musicInfo[0]
346+
347+
musicNameSelect := "请选出正确歌曲:\n"
348+
for i := 0; i < len(musicInfo); i++ {
349+
// 解析歌曲信息
350+
music := strings.Split(musicInfo[i], ".")
351+
// 获取音乐后缀
352+
musicType := music[len(music)-1]
353+
if !strings.Contains(musictypelist, musicType) {
354+
ctx.SendChain(message.Text("抽取到了歌曲:\n",
355+
musicInfo[i], "\n该歌曲不是音乐后缀,请联系bot主人修改"))
356+
}
357+
// 获取音乐信息
358+
musicInfo := strings.Split(strings.ReplaceAll(musicInfo[i], "."+musicType, ""), " - ")
359+
infoNum := len(musicInfo)
360+
if infoNum == 1 {
361+
ctx.SendChain(message.Text("抽取到了歌曲:\n",
362+
musicInfo[i], "\n该歌曲命名不符合命名规则,请联系bot主人修改"))
363+
}
364+
musicNameSelect += musicInfo[0] + " 歌手:" + musicInfo[1] + "\n"
365+
}
366+
ctx.SendChain(message.Text(musicNameSelect))
367+
}

0 commit comments

Comments
 (0)