From 3b3dd3df99ce3ac0fab32d53bceb882e29ee4fb1 Mon Sep 17 00:00:00 2001 From: fumiama Date: Sun, 10 Oct 2021 11:37:41 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20fortune=20=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B9=9F=E5=8F=AF=E8=AE=BE=E7=BD=AE=E5=BA=95?= =?UTF-8?q?=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin_fortune/fortune.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/plugin_fortune/fortune.go b/plugin_fortune/fortune.go index ec0aae96..59ff3c95 100644 --- a/plugin_fortune/fortune.go +++ b/plugin_fortune/fortune.go @@ -53,14 +53,20 @@ func init() { "- 运势|抽签\n" + "- 设置底图[车万 DC4 爱因斯坦 星空列车 樱云之恋 富婆妹 李清歌 公主连结 原神 明日方舟 碧蓝航线 碧蓝幻想 战双 阴阳师]", }) - en.OnRegex(`^设置底图(.*)`, zero.OnlyGroup).SetBlock(true).SecondPriority(). + en.OnRegex(`^设置底图(.*)`).SetBlock(true).SecondPriority(). Handle(func(ctx *zero.Ctx) { + gid := ctx.Event.GroupID + if gid <= 0 { + // 个人用户设为负数 + gid = -ctx.Event.UserID + } i, ok := index[ctx.State["regex_matched"].([]string)[1]] if ok { - conf.Kind[ctx.Event.GroupID] = i + conf.Kind[gid] = i savecfg("cfg.pb") + ctx.SendChain(message.Text("设置成功~")) } else { - ctx.Send("没有这个底图哦~") + ctx.SendChain(message.Text("没有这个底图哦~")) } }) en.OnFullMatchGroup([]string{"运势", "抽签"}).SetBlock(true).SecondPriority(). @@ -89,7 +95,12 @@ func init() { } // 获取该群背景类型,默认车万 kind := "车万" - if v, ok := conf.Kind[ctx.Event.GroupID]; ok { + gid := ctx.Event.GroupID + if gid <= 0 { + // 个人用户设为负数 + gid = -ctx.Event.UserID + } + if v, ok := conf.Kind[gid]; ok { kind = table[v] } // 检查背景图片是否存在 @@ -116,13 +127,13 @@ func init() { t, _ := strconv.ParseInt(time.Now().Format("20060102"), 10, 64) seed := ctx.Event.UserID + t // 随机获取背景 - background, err := randimage(base+kind+"/", seed) + background, err := randimage(folder+"/", seed) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return } // 随机获取签文 - title, text, err := randtext(base+"运势签文.json", seed) + title, text, err := randtext(mikuji, seed) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return