From 0943023a192fb4fdb1da780f19b848f6c094979e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E6=9F=B3=E7=85=9C?= <101934327+fangliuyu@users.noreply.github.com> Date: Fri, 26 Aug 2022 18:44:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=B4=E6=8A=A4guessmusic=E5=92=8Cqqwife?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=20(#385)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 优化error输出,新增猜歌结束后分享歌曲 * 添加反并发,防止被多娶 * Update main.go --- plugin/guessmusic/main.go | 21 +++++++++++++++------ plugin/qqwife/qqmapwife.go | 12 +++++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/plugin/guessmusic/main.go b/plugin/guessmusic/main.go index 684cacb976..f2ec6e706e 100644 --- a/plugin/guessmusic/main.go +++ b/plugin/guessmusic/main.go @@ -526,7 +526,8 @@ func init() { // 插件主体 tick.Stop() after.Stop() ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, - message.Text("游戏已取消,猜歌答案是\n", answerString))) + message.Text("游戏已取消,猜歌答案是\n", answerString, "\n\n\n下面欣赏猜歌的歌曲"))) + ctx.SendChain(message.Record("file:///" + pathOfMusic + musicName)) return } ctx.Send( @@ -557,21 +558,24 @@ func init() { // 插件主体 tick.Stop() after.Stop() ctx.Send(message.ReplyWithMessage(c.Event.MessageID, - message.Text("太棒了,你猜对歌曲名了!答案是\n", answerString))) + message.Text("太棒了,你猜对歌曲名了!答案是\n", answerString, "\n\n下面欣赏猜歌的歌曲"))) + ctx.SendChain(message.Record("file:///" + pathOfMusic + musicName)) return case strings.Contains(musicInfo[1], answer) || strings.EqualFold(musicInfo[1], answer): wait.Stop() tick.Stop() after.Stop() ctx.Send(message.ReplyWithMessage(c.Event.MessageID, - message.Text("太棒了,你猜对歌手名了!答案是\n", answerString))) + message.Text("太棒了,你猜对歌手名了!答案是\n", answerString, "\n\n下面欣赏猜歌的歌曲"))) + ctx.SendChain(message.Record("file:///" + pathOfMusic + musicName)) return case strings.Contains(musicAlia, answer) || strings.EqualFold(musicAlia, answer): wait.Stop() tick.Stop() after.Stop() ctx.Send(message.ReplyWithMessage(c.Event.MessageID, - message.Text("太棒了,你猜对出处了!答案是\n", answerString))) + message.Text("太棒了,你猜对出处了!答案是\n", answerString, "\n\n下面欣赏猜歌的歌曲"))) + ctx.SendChain(message.Record("file:///" + pathOfMusic + musicName)) return default: musicCount++ @@ -589,7 +593,8 @@ func init() { // 插件主体 tick.Stop() after.Stop() ctx.Send(message.ReplyWithMessage(c.Event.MessageID, - message.Text("次数到了,没能猜出来。答案是\n", answerString))) + message.Text("次数到了,没能猜出来。答案是\n", answerString, "\n\n下面欣赏猜歌的歌曲"))) + ctx.SendChain(message.Record("file:///" + pathOfMusic + musicName)) return default: wait.Reset(40 * time.Second) @@ -752,7 +757,11 @@ func getListMusic(listID, pathOfMusic string) (musicName string, err error) { musicURL := "http://music.163.com/song/media/outer/url?id=" + strconv.Itoa(musicID) response, err := http.Head(musicURL) if err != nil { - err = errors.Errorf("下载音乐失败, ERROR: %s", err) + if strings.Contains(err.Error(), "404") { + err = errors.Errorf("歌曲丢失, 可能歌曲已下架或者登录状态已过期。\n可尝试重新登录排除后者问题。") + } else { + err = errors.Errorf("下载音乐失败, ERROR: %s", err) + } return } _ = response.Body.Close() diff --git a/plugin/qqwife/qqmapwife.go b/plugin/qqwife/qqmapwife.go index 102437b9fe..ec93ed9bc1 100644 --- a/plugin/qqwife/qqmapwife.go +++ b/plugin/qqwife/qqmapwife.go @@ -15,6 +15,7 @@ import ( ctrl "github.com/FloatTech/zbpctrl" control "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/ctxext" + "github.com/wdvxdr1123/ZeroBot/extension/single" // 数据库 sql "github.com/FloatTech/sqlite" @@ -290,7 +291,16 @@ func init() { "- 娶群友\n- 群老婆列表\n" + "--------------------------------\n以下技能每人只能三选一\n CD12H,不跨天刷新\n--------------------------------\n" + "- (娶|嫁)@对方QQ\n- 当[对方Q号|@对方QQ]的小三\n- 闹离婚", - }) + }).ApplySingle(single.New( + single.WithKeyFn(func(ctx *zero.Ctx) int64 { return ctx.Event.GroupID }), + single.WithPostFn[int64](func(ctx *zero.Ctx) { + ctx.Send( + message.ReplyWithMessage(ctx.Event.MessageID, + message.Text("民政局门口排长队了!你们一个个来,别着急......"), + ), + ) + }), + )) getdb := fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool { 民政局.db.DBPath = engine.DataFolder() + "结婚登记表.db" // 如果数据库不存在则下载