Compare commits

...

13 Commits

Author SHA1 Message Date
源文雨
41c499840f fix #197: 猜单词出现空指针报警 2022-04-18 22:59:33 +08:00
himawari
f5cef170f0 🚑️ 修复查看其他群聊热词的问题 (#195) 2022-04-18 16:31:09 +08:00
源文雨
d7922a7c9b ️ 优化pool 2022-04-18 16:29:09 +08:00
github-actions[bot]
23fc77e8e1 🎨 改进代码样式 2022-04-17 13:25:27 +00:00
himawari
51f3eda09a 👍 添加聊天热词 (#192)
*  添加聊天热词

*  添加聊天热词

*  添加聊天热词

* 🚨 修lint

* 🚨 修lint
2022-04-17 21:24:07 +08:00
源文雨
6ec08a5227 🐛 reg 时序 2022-04-17 21:22:08 +08:00
源文雨
4855f694cb 🎨 edit README 2022-04-17 00:11:54 +08:00
源文雨
eaef37a831 Update README.md 2022-04-16 19:10:06 +08:00
源文雨
b182ff36bb 🔖 1.3.3-beta6 2022-04-16 00:35:05 +08:00
源文雨
c4e543449c 使用真正lazy的资源下载方式 2022-04-16 00:33:50 +08:00
源文雨
c76d9d4461 🔥 remove debug info in gorm 2022-04-16 00:04:07 +08:00
源文雨
dfd184724b 使用真正lazy的资源下载方式 2022-04-16 00:02:41 +08:00
源文雨
fef254031e ️ banmap 使用 ttl 2022-04-15 19:02:06 +08:00
31 changed files with 580 additions and 291 deletions

View File

@@ -11,7 +11,7 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/FloatTech/ZeroBot-Plugin?style=flat-square&logo=go)](https://goreportcard.com/report/github.com/github.com/FloatTech/ZeroBot-Plugin)
[![Badge](https://img.shields.io/badge/onebot-v11-black?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAABwCAMAAADxPgR5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAxQTFRF////29vbr6+vAAAAk1hCcwAAAAR0Uk5T////AEAqqfQAAAKcSURBVHja7NrbctswDATQXfD//zlpO7FlmwAWIOnOtNaTM5JwDMa8E+PNFz7g3waJ24fviyDPgfhz8fHP39cBcBL9KoJbQUxjA2iYqHL3FAnvzhL4GtVNUcoSZe6eSHizBcK5LL7dBr2AUZlev1ARRHCljzRALIEog6H3U6bCIyqIZdAT0eBuJYaGiJaHSjmkYIZd+qSGWAQnIaz2OArVnX6vrItQvbhZJtVGB5qX9wKqCMkb9W7aexfCO/rwQRBzsDIsYx4AOz0nhAtWu7bqkEQBO0Pr+Ftjt5fFCUEbm0Sbgdu8WSgJ5NgH2iu46R/o1UcBXJsFusWF/QUaz3RwJMEgngfaGGdSxJkE/Yg4lOBryBiMwvAhZrVMUUvwqU7F05b5WLaUIN4M4hRocQQRnEedgsn7TZB3UCpRrIJwQfqvGwsg18EnI2uSVNC8t+0QmMXogvbPg/xk+Mnw/6kW/rraUlvqgmFreAA09xW5t0AFlHrQZ3CsgvZm0FbHNKyBmheBKIF2cCA8A600aHPmFtRB1XvMsJAiza7LpPog0UJwccKdzw8rdf8MyN2ePYF896LC5hTzdZqxb6VNXInaupARLDNBWgI8spq4T0Qb5H4vWfPmHo8OyB1ito+AysNNz0oglj1U955sjUN9d41LnrX2D/u7eRwxyOaOpfyevCWbTgDEoilsOnu7zsKhjRCsnD/QzhdkYLBLXjiK4f3UWmcx2M7PO21CKVTH84638NTplt6JIQH0ZwCNuiWAfvuLhdrcOYPVO9eW3A67l7hZtgaY9GZo9AFc6cryjoeFBIWeU+npnk/nLE0OxCHL1eQsc1IciehjpJv5mqCsjeopaH6r15/MrxNnVhu7tmcslay2gO2Z1QfcfX0JMACG41/u0RrI9QAAAABJRU5ErkJggg==)](https://github.com/howmanybots/onebot)
[![Badge](https://img.shields.io/badge/zerobot-v1.4.1-black?style=flat-square&logo=go)](https://github.com/wdvxdr1123/ZeroBot)
[![Badge](https://img.shields.io/badge/zerobot-v1.5.0-black?style=flat-square&logo=go)](https://github.com/wdvxdr1123/ZeroBot)
[![License](https://img.shields.io/github/license/FloatTech/ZeroBot-Plugin.svg?style=flat-square&logo=gnu)](https://raw.githubusercontent.com/FloatTech/ZeroBot-Plugin/master/LICENSE)
[![qq group](https://img.shields.io/badge/group-1048452984-red?style=flat-square&logo=tencent-qq)](https://jq.qq.com/?_wv=1027&k=QMb7x1mM)
@@ -405,6 +405,8 @@ print("run[CQ:image,file="+j["img"]+"]")
```
- **舔狗日记** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/tiangou"`
- [x] 舔狗日记
- **聊天热词** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/word_count"`
- [x] 热词 [群号] [消息数目]|热词 123456 1000
- **TODO...**
## 使用方法
@@ -469,7 +471,3 @@ GOOS=linux GOARCH=mips GOMIPS=softfloat CGO_ENABLED=0 go build -ldflags "-s -w"
- [ZeroBot](https://github.com/wdvxdr1123/ZeroBot)
- [ATRI](https://github.com/Kyomotoi/ATRI)
## License
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FFloatTech%2FZeroBot-Plugin.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FFloatTech%2FZeroBot-Plugin?ref=badge_large)

2
data

Submodule data updated: 7d6739a9b7...b3d25c45fd

6
go.mod
View File

@@ -3,15 +3,15 @@ module github.com/FloatTech/ZeroBot-Plugin
go 1.18
require (
github.com/FloatTech/AnimeAPI v1.3.3-0.20220415072648-32d1101a65a4
github.com/FloatTech/AnimeAPI v1.3.3-0.20220417132103-df55797131af
github.com/FloatTech/sqlite v0.2.1
github.com/FloatTech/zbputils v1.3.3-0.20220415072510-2833c397c253
github.com/FloatTech/zbputils v1.3.3-0.20220418145633-c1d3c00da628
github.com/antchfx/htmlquery v1.2.4
github.com/corona10/goimagehash v1.0.3
github.com/fogleman/gg v1.3.0
github.com/fumiama/cron v1.3.0
github.com/fumiama/go-base16384 v1.4.0
github.com/fumiama/go-registry v0.1.3
github.com/fumiama/go-registry v0.1.5
github.com/fumiama/gofastTEA v0.0.10
github.com/fumiama/gotracemoe v0.0.3
github.com/fumiama/sqlite3 v1.14.6

12
go.sum
View File

@@ -1,9 +1,9 @@
github.com/FloatTech/AnimeAPI v1.3.3-0.20220415072648-32d1101a65a4 h1:XrOM1EsSPAjP0Oj7HK0E9w+3APwKl3aWkcRmRw/43kM=
github.com/FloatTech/AnimeAPI v1.3.3-0.20220415072648-32d1101a65a4/go.mod h1:YJyZSkv/i8PuNSmaBcCmvXUoWnQnQwm495zSh1PVC6o=
github.com/FloatTech/AnimeAPI v1.3.3-0.20220417132103-df55797131af h1:K7Cdrd1jgiTUe8hcITgmwJeIdwfCMM+phw8DD1tALXA=
github.com/FloatTech/AnimeAPI v1.3.3-0.20220417132103-df55797131af/go.mod h1:jUOit4oeiKOtRDy5ZLTJQa7aE0972R/KPF15b22Q3vY=
github.com/FloatTech/sqlite v0.2.1 h1:9t6Me48XJJCIoPy4nLRvcdhcVKfT0c2lilp7SEKROG8=
github.com/FloatTech/sqlite v0.2.1/go.mod h1:6NfHRzqOo9RWeMJEoAQVuo51Omd5LFNxCNQhMF02/9U=
github.com/FloatTech/zbputils v1.3.3-0.20220415072510-2833c397c253 h1:vmSIQ4BbeNtBEZ3AE4Pj8B5eS5fWLd+k7xmO6OCijbQ=
github.com/FloatTech/zbputils v1.3.3-0.20220415072510-2833c397c253/go.mod h1:a6vKTjBt//Mr4M8VSSj5ER597/ZjJ+dJAIQSVU/M/oY=
github.com/FloatTech/zbputils v1.3.3-0.20220418145633-c1d3c00da628 h1:NC7m06uyenwt4TRyCEkK5lFNId3TB5gKEeOYNQpYTBI=
github.com/FloatTech/zbputils v1.3.3-0.20220418145633-c1d3c00da628/go.mod h1:K2IVrhwmrVKZSHSHmNoO9JthN1As9RcnQplf+stQ5BY=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c h1:cNPOdTNiVwxLpROLjXCgbIPvdkE+BwvxDvgmdYmWx6Q=
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c/go.mod h1:KqZzu7slNKROh3TSYEH/IUMG6f4M+1qubZ5e52QypsE=
@@ -34,8 +34,8 @@ github.com/fumiama/cron v1.3.0 h1:ZWlwuexF+HQHl3cYytEE5HNwD99q+3vNZF1GrEiXCFo=
github.com/fumiama/cron v1.3.0/go.mod h1:bz5Izvgi/xEUI8tlBN8BI2jr9Moo8N4or0KV8xXuPDY=
github.com/fumiama/go-base16384 v1.4.0 h1:4KrtewnmAChrZjPA7/QYc72t+vvsKF+DYB0q1iRPdpo=
github.com/fumiama/go-base16384 v1.4.0/go.mod h1:OEn+947GV5gsbTAnyuUW/SrfxJYUdYupSIQXOuGOcXM=
github.com/fumiama/go-registry v0.1.3 h1:WvUN2wdziB2+LyYs4zNy1FHGQOvZeto7lbADfSqbMPw=
github.com/fumiama/go-registry v0.1.3/go.mod h1:iJT3DVgH7KXpJZs6waXEjnWtJPUBBGhF+ByJIMRfngk=
github.com/fumiama/go-registry v0.1.5 h1:5a7n+JwwKQrnW3U0+gOKSx+2x4Zv+2A3BhyQthJL4Ng=
github.com/fumiama/go-registry v0.1.5/go.mod h1:dIUVbiOgfk9oZcsgwDvNLC72i+ctibVukSXR/9bLviI=
github.com/fumiama/gofastTEA v0.0.10 h1:JJJ+brWD4kie+mmK2TkspDXKzqq0IjXm89aGYfoGhhQ=
github.com/fumiama/gofastTEA v0.0.10/go.mod h1:RIdbYZyB4MbH6ZBlPymRaXn3cD6SedlCu5W/HHfMPBk=
github.com/fumiama/gotracemoe v0.0.3 h1:iI5EbE9A3UUbfukG6+/soYPjp1S31eCNYf4tw7s6/Jc=

View File

@@ -10,7 +10,7 @@ import (
var (
info = [...]string{
"* OneBot + ZeroBot + Golang",
"* Version 1.3.3-beta5 - 2022-04-15 15:29:27 +0800 CST",
"* Version 1.3.3-beta6 - 2022-04-16 00:34:43 +0800 CST",
"* Copyright © 2020 - 2022 FloatTech. All Rights Reserved.",
"* Project: https://github.com/FloatTech/ZeroBot-Plugin",
}

View File

@@ -110,6 +110,7 @@ import (
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/translation" // 翻译
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/vtb_quotation" // vtb语录
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wangyiyun" // 网易云音乐热评
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/word_count" // 聊天热词
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wordle" // 猜单词
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ymgal" // 月幕galgame
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/zaobao" // 早报

View File

@@ -11,6 +11,7 @@ import (
"time"
control "github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
"github.com/FloatTech/zbputils/file"
"github.com/FloatTech/zbputils/img"
"github.com/FloatTech/zbputils/img/text"
@@ -36,14 +37,21 @@ var engine = control.Register("bilibili", &control.Options{
// 查成分的
func init() {
cachePath := engine.DataFolder() + "cache/"
dbfile := engine.DataFolder() + "bilibili.db"
go func() {
_ = os.MkdirAll(cachePath, 0755)
_ = os.RemoveAll(cachePath)
_ = os.MkdirAll(cachePath, 0755)
var getdb = ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
var err error
dbfile := engine.DataFolder() + "bilibili.db"
_, _ = file.GetLazyData(dbfile, false, false)
vdb = initialize(dbfile)
}()
vdb, err = initialize(dbfile)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
return true
})
engine.OnRegex(`^>user info\s?(.{1,25})$`).SetBlock(true).
engine.OnRegex(`^>user info\s?(.{1,25})$`, getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
keyword := ctx.State["regex_matched"].([]string)[1]
uidRes, err := search(keyword)
@@ -95,7 +103,7 @@ func init() {
))
})
engine.OnRegex(`^查成分\s?(.{1,25})$`).SetBlock(true).
engine.OnRegex(`^查成分\s?(.{1,25})$`, getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
keyword := ctx.State["regex_matched"].([]string)[1]
searchRes, err := search(keyword)
@@ -256,7 +264,7 @@ func init() {
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + drawedFile))
})
engine.OnRegex(`^设置b站cookie?\s+(.{1,100})$`, zero.SuperUserPermission).SetBlock(true).
engine.OnRegex(`^设置b站cookie?\s+(.{1,100})$`, zero.SuperUserPermission, getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
cookie := ctx.State["regex_matched"].([]string)[1]
err := vdb.setBilibiliCookie(cookie)
@@ -267,7 +275,7 @@ func init() {
ctx.SendChain(message.Text("成功设置b站cookie为" + cookie))
})
engine.OnFullMatch("更新vup", zero.SuperUserPermission).SetBlock(true).
engine.OnFullMatch("更新vup", zero.SuperUserPermission, getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
ctx.SendChain(message.Text("少女祈祷中..."))
err := updateVup()

View File

@@ -42,21 +42,21 @@ func (config) TableName() string {
}
// initialize 初始化vtb数据库
func initialize(dbpath string) *vupdb {
func initialize(dbpath string) (*vupdb, error) {
if _, err := os.Stat(dbpath); err != nil || os.IsNotExist(err) {
// 生成文件
f, err := os.Create(dbpath)
if err != nil {
return nil
return nil, err
}
defer f.Close()
}
gdb, err := gorm.Open("sqlite3", dbpath)
if err != nil {
panic(err)
return nil, err
}
gdb.Debug().AutoMigrate(&vup{}).AutoMigrate(&config{})
return (*vupdb)(gdb)
gdb.AutoMigrate(&vup{}).AutoMigrate(&config{})
return (*vupdb)(gdb), nil
}
func (vdb *vupdb) insertVupByMid(mid int64, uname string, roomid int64) (err error) {
@@ -66,9 +66,9 @@ func (vdb *vupdb) insertVupByMid(mid int64, uname string, roomid int64) (err err
Uname: uname,
Roomid: roomid,
}
if err = db.Debug().Model(&vup{}).First(&v, "mid = ? ", mid).Error; err != nil {
if err = db.Model(&vup{}).First(&v, "mid = ? ", mid).Error; err != nil {
if gorm.IsRecordNotFoundError(err) {
err = db.Debug().Model(&vup{}).Create(&v).Error
err = db.Model(&vup{}).Create(&v).Error
}
}
return
@@ -77,7 +77,7 @@ func (vdb *vupdb) insertVupByMid(mid int64, uname string, roomid int64) (err err
// filterVup 筛选vup
func (vdb *vupdb) filterVup(ids []int64) (vups []vup, err error) {
db := (*gorm.DB)(vdb)
if err = db.Debug().Model(&vup{}).Find(&vups, "mid in (?)", ids).Error; err != nil {
if err = db.Model(&vup{}).Find(&vups, "mid in (?)", ids).Error; err != nil {
return vups, err
}
return
@@ -112,13 +112,13 @@ func (vdb *vupdb) setBilibiliCookie(cookie string) (err error) {
Key: bilibiliCookie,
Value: cookie,
}
if err = db.Debug().Model(&config{}).First(&c, "key = ? ", bilibiliCookie).Error; err != nil {
if err = db.Model(&config{}).First(&c, "key = ? ", bilibiliCookie).Error; err != nil {
// error handling...
if gorm.IsRecordNotFoundError(err) {
err = db.Debug().Model(&config{}).Create(&c).Error
err = db.Model(&config{}).Create(&c).Error
}
} else {
err = db.Debug().Model(&config{}).Where("key = ? ", bilibiliCookie).Update(
err = db.Model(&config{}).Where("key = ? ", bilibiliCookie).Update(
map[string]interface{}{
"value": cookie,
}).Error
@@ -128,6 +128,6 @@ func (vdb *vupdb) setBilibiliCookie(cookie string) (err error) {
func (vdb *vupdb) getBilibiliCookie() (c config) {
db := (*gorm.DB)(vdb)
db.Debug().Model(&config{}).First(&c, "key = ?", bilibiliCookie)
db.Model(&config{}).First(&c, "key = ?", bilibiliCookie)
return
}

View File

@@ -59,12 +59,12 @@ func (bdb *bilibilipushdb) insertOrUpdateLiveAndDynamic(bpMap map[string]interfa
bp := bilibilipush{}
data, _ := json.Marshal(&bpMap)
_ = json.Unmarshal(data, &bp)
if err = db.Debug().Model(&bilibilipush{}).First(&bp, "bilibili_uid = ? and group_id = ?", bp.BilibiliUID, bp.GroupID).Error; err != nil {
if err = db.Model(&bilibilipush{}).First(&bp, "bilibili_uid = ? and group_id = ?", bp.BilibiliUID, bp.GroupID).Error; err != nil {
if gorm.IsRecordNotFoundError(err) {
err = db.Debug().Model(&bilibilipush{}).Create(&bp).Error
err = db.Model(&bilibilipush{}).Create(&bp).Error
}
} else {
err = db.Debug().Model(&bilibilipush{}).Where("bilibili_uid = ? and group_id = ?", bp.BilibiliUID, bp.GroupID).Update(bpMap).Error
err = db.Model(&bilibilipush{}).Where("bilibili_uid = ? and group_id = ?", bp.BilibiliUID, bp.GroupID).Update(bpMap).Error
}
return
}
@@ -72,7 +72,7 @@ func (bdb *bilibilipushdb) insertOrUpdateLiveAndDynamic(bpMap map[string]interfa
func (bdb *bilibilipushdb) getAllBuidByLive() (buidList []int64) {
db := (*gorm.DB)(bdb)
var bpl []bilibilipush
db.Debug().Model(&bilibilipush{}).Find(&bpl, "live_disable = 0")
db.Model(&bilibilipush{}).Find(&bpl, "live_disable = 0")
temp := make(map[int64]bool)
for _, v := range bpl {
_, ok := temp[v.BilibiliUID]
@@ -87,7 +87,7 @@ func (bdb *bilibilipushdb) getAllBuidByLive() (buidList []int64) {
func (bdb *bilibilipushdb) getAllBuidByDynamic() (buidList []int64) {
db := (*gorm.DB)(bdb)
var bpl []bilibilipush
db.Debug().Model(&bilibilipush{}).Find(&bpl, "dynamic_disable = 0")
db.Model(&bilibilipush{}).Find(&bpl, "dynamic_disable = 0")
temp := make(map[int64]bool)
for _, v := range bpl {
_, ok := temp[v.BilibiliUID]
@@ -102,7 +102,7 @@ func (bdb *bilibilipushdb) getAllBuidByDynamic() (buidList []int64) {
func (bdb *bilibilipushdb) getAllGroupByBuidAndLive(buid int64) (groupList []int64) {
db := (*gorm.DB)(bdb)
var bpl []bilibilipush
db.Debug().Model(&bilibilipush{}).Find(&bpl, "bilibili_uid = ? and live_disable = 0", buid)
db.Model(&bilibilipush{}).Find(&bpl, "bilibili_uid = ? and live_disable = 0", buid)
for _, v := range bpl {
groupList = append(groupList, v.GroupID)
}
@@ -112,7 +112,7 @@ func (bdb *bilibilipushdb) getAllGroupByBuidAndLive(buid int64) (groupList []int
func (bdb *bilibilipushdb) getAllGroupByBuidAndDynamic(buid int64) (groupList []int64) {
db := (*gorm.DB)(bdb)
var bpl []bilibilipush
db.Debug().Model(&bilibilipush{}).Find(&bpl, "bilibili_uid = ? and dynamic_disable = 0", buid)
db.Model(&bilibilipush{}).Find(&bpl, "bilibili_uid = ? and dynamic_disable = 0", buid)
for _, v := range bpl {
groupList = append(groupList, v.GroupID)
}
@@ -121,7 +121,7 @@ func (bdb *bilibilipushdb) getAllGroupByBuidAndDynamic(buid int64) (groupList []
func (bdb *bilibilipushdb) getAllPushByGroup(groupID int64) (bpl []bilibilipush) {
db := (*gorm.DB)(bdb)
db.Debug().Model(&bilibilipush{}).Find(&bpl, "group_id = ? and (live_disable = 0 or dynamic_disable = 0)", groupID)
db.Model(&bilibilipush{}).Find(&bpl, "group_id = ? and (live_disable = 0 or dynamic_disable = 0)", groupID)
return
}
@@ -131,13 +131,13 @@ func (bdb *bilibilipushdb) insertBilibiliUp(buid int64, name string) {
BilibiliUID: buid,
Name: name,
}
db.Debug().Model(&bilibiliup{}).Create(bu)
db.Model(&bilibiliup{}).Create(bu)
}
func (bdb *bilibilipushdb) updateAllUp() {
db := (*gorm.DB)(bdb)
var bul []bilibiliup
db.Debug().Model(&bilibiliup{}).Find(&bul)
db.Model(&bilibiliup{}).Find(&bul)
for _, v := range bul {
upMap[v.BilibiliUID] = v.Name
}

View File

@@ -8,6 +8,7 @@ import (
"github.com/FloatTech/zbputils/binary"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
"github.com/FloatTech/zbputils/file"
"github.com/FloatTech/zbputils/img/text"
)
@@ -19,24 +20,27 @@ func init() {
PublicDataFolder: "BookReview",
})
go func() {
getdb := ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
dbpath := engine.DataFolder()
db.DBPath = dbpath + "bookreview.db"
// os.RemoveAll(dbpath)
_, _ = file.GetLazyData(db.DBPath, false, true)
err := db.Create("bookreview", &book{})
if err != nil {
panic(err)
ctx.SendChain(message.Text("ERROR:", err))
return false
}
n, err := db.Count("bookreview")
if err != nil {
panic(err)
ctx.SendChain(message.Text("ERROR:", err))
return false
}
log.Printf("[bookreview]读取%d条书评", n)
}()
log.Infof("[bookreview]读取%d条书评", n)
return true
})
// 中文、英文、数字但不包括下划线等符号
engine.OnRegex("^书评([\u4E00-\u9FA5A-Za-z0-9]{1,25})$").SetBlock(true).
engine.OnRegex("^书评([\u4E00-\u9FA5A-Za-z0-9]{1,25})$", getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
b := getBookReviewByKeyword(ctx.State["regex_matched"].([]string)[1])
data, err := text.RenderToBase64(b.BookReview, text.FontFile, 400, 20)
@@ -49,7 +53,7 @@ func init() {
}
})
engine.OnFullMatch("随机书评").SetBlock(true).
engine.OnFullMatch("随机书评", getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
br := getRandomBookReview()
data, err := text.RenderToBase64(br.BookReview, text.FontFile, 400, 20)

View File

@@ -7,6 +7,7 @@ import (
"github.com/wdvxdr1123/ZeroBot/message"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
"github.com/FloatTech/zbputils/file"
)
@@ -17,23 +18,26 @@ func init() {
PublicDataFolder: "ChouXiangHua",
})
go func() {
dbpath := en.DataFolder()
db.DBPath = dbpath + "cxh.db"
// os.RemoveAll(dbpath)
_, _ = file.GetLazyData(db.DBPath, false, true)
err := db.Create("pinyin", &pinyin{})
if err != nil {
panic(err)
}
n, err := db.Count("pinyin")
if err != nil {
panic(err)
}
logrus.Printf("[chouxianghua]读取%d条拼音", n)
}()
en.OnRegex("^抽象翻译((\\s|[\\r\\n]|[\\p{Han}\\p{P}A-Za-z0-9])+)$").SetBlock(true).
en.OnRegex("^抽象翻译((\\s|[\\r\\n]|[\\p{Han}\\p{P}A-Za-z0-9])+)$",
ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
dbpath := en.DataFolder()
db.DBPath = dbpath + "cxh.db"
// os.RemoveAll(dbpath)
_, _ = file.GetLazyData(db.DBPath, false, true)
err := db.Create("pinyin", &pinyin{})
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
n, err := db.Count("pinyin")
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
logrus.Printf("[chouxianghua]读取%d条拼音", n)
return true
}),
).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
r := cx(ctx.State["regex_matched"].([]string)[1])
ctx.SendChain(message.Text(r))

View File

@@ -9,6 +9,7 @@ import (
"github.com/wdvxdr1123/ZeroBot/message"
control "github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
"github.com/FloatTech/zbputils/file"
"github.com/FloatTech/zbputils/math"
)
@@ -20,23 +21,26 @@ func init() {
PublicDataFolder: "CpStory",
})
go func() {
getdb := ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
dbpath := engine.DataFolder()
db.DBPath = dbpath + "cp.db"
// os.RemoveAll(dbpath)
_, _ = file.GetLazyData(db.DBPath, false, true)
err := db.Create("cp_story", &cpstory{})
if err != nil {
panic(err)
ctx.SendChain(message.Text("ERROR:", err))
return false
}
n, err := db.Count("cp_story")
if err != nil {
panic(err)
ctx.SendChain(message.Text("ERROR:", err))
return false
}
logrus.Printf("[cpstory]读取%d条故事", n)
}()
return true
})
engine.OnRegex("^组cp.*?(\\d+).*?(\\d+)", zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
engine.OnRegex("^组cp.*?(\\d+).*?(\\d+)", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
cs := getRandomCpStory()
gong := ctx.CardOrNickName(math.Str2Int64(ctx.State["regex_matched"].([]string)[1]))
shou := ctx.CardOrNickName(math.Str2Int64(ctx.State["regex_matched"].([]string)[2]))
@@ -46,7 +50,7 @@ func init() {
text = strings.ReplaceAll(text, cs.Shou, gong)
ctx.SendChain(message.Text(text))
})
engine.OnPrefix("磕cp").SetBlock(true).Handle(func(ctx *zero.Ctx) {
engine.OnPrefix("磕cp", getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
cs := getRandomCpStory()
params := strings.Split(ctx.State["args"].(string), " ")
if len(params) < 2 {

View File

@@ -24,34 +24,41 @@ func init() {
PublicDataFolder: "Curse",
})
go func() {
getdb := ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
dbpath := engine.DataFolder()
db.DBPath = dbpath + "curse.db"
_, err := file.GetLazyData(db.DBPath, false, true)
if err != nil {
panic(err)
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = db.Create("curse", &curse{})
if err != nil {
panic(err)
ctx.SendChain(message.Text("ERROR:", err))
return false
}
c, err := db.Count("curse")
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
c, _ := db.Count("curse")
logrus.Infoln("[curse]加载", c, "条骂人语录")
}()
return true
})
engine.OnFullMatch("骂我").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
engine.OnFullMatch("骂我", getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
process.SleepAbout1sTo2s()
text := getRandomCurseByLevel(minLevel).Text
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(text))
})
engine.OnFullMatch("大力骂我").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
engine.OnFullMatch("大力骂我", getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
process.SleepAbout1sTo2s()
text := getRandomCurseByLevel(maxLevel).Text
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(text))
})
engine.OnKeywordGroup([]string{"他妈", "公交车", "你妈", "操", "屎", "去死", "快死", "我日", "逼", "尼玛", "艾滋", "癌症", "有病", "烦你", "你爹", "屮", "cnm"}, zero.OnlyToMe).SetBlock(true).
engine.OnKeywordGroup([]string{"他妈", "公交车", "你妈", "操", "屎", "去死", "快死", "我日", "逼", "尼玛", "艾滋", "癌症", "有病", "烦你", "你爹", "屮", "cnm"}, zero.OnlyToMe, getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
text := getRandomCurseByLevel(maxLevel).Text
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(text))

View File

@@ -6,6 +6,7 @@ import (
"github.com/wdvxdr1123/ZeroBot/message"
control "github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
"github.com/FloatTech/ZeroBot-Plugin/plugin/diana/data"
)
@@ -21,26 +22,29 @@ var engine = control.Register("diana", &control.Options{
})
func init() {
go func() {
datapath := engine.DataFolder()
dbfile := datapath + "text.db"
data.LoadText(dbfile)
}()
getdb := ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
err := data.LoadText(engine.DataFolder() + "text.db")
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
return true
})
// 随机发送一篇上面的小作文
engine.OnFullMatch("小作文").SetBlock(true).
engine.OnFullMatch("小作文", getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
// 绕过第一行发病
ctx.SendChain(message.Text(data.RandText()))
})
// 逆天
engine.OnFullMatch("发大病").SetBlock(true).
engine.OnFullMatch("发大病", getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
// 第一行是发病
ctx.SendChain(message.Text(data.HentaiText()))
})
// 增加小作文
engine.OnRegex(`^教你一篇小作文(.*)$`, zero.AdminPermission).SetBlock(true).
engine.OnRegex(`^教你一篇小作文(.*)$`, zero.AdminPermission, getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
err := data.AddText(ctx.State["regex_matched"].([]string)[1])
if err != nil {

View File

@@ -19,18 +19,22 @@ type text struct {
}
// LoadText 加载小作文
func LoadText(dbfile string) {
func LoadText(dbfile string) error {
_, err := file.GetLazyData(dbfile, false, false)
db.DBPath = dbfile
if err != nil {
panic(err)
return err
}
err = db.Create("text", &text{})
if err != nil {
panic(err)
return err
}
c, err := db.Count("text")
if err != nil {
return err
}
c, _ := db.Count("text")
logrus.Printf("[Diana]读取%d条小作文", c)
return nil
}
// AddText 添加小作文

View File

@@ -61,25 +61,9 @@ func init() {
if err != nil {
panic(err)
}
go func() {
for i, s := range table {
index[s] = uint8(i)
}
data, err := file.GetLazyData(omikujson, true, false)
if err != nil {
panic(err)
}
err = json.Unmarshal(data, &omikujis)
if err != nil {
panic(err)
}
}()
go func() {
_, err := file.GetLazyData(font, false, true)
if err != nil {
panic(err)
}
}()
for i, s := range table {
index[s] = uint8(i)
}
en.OnRegex(`^设置底图\s?(.*)`).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
gid := ctx.Event.GroupID
@@ -104,7 +88,26 @@ func init() {
}
ctx.SendChain(message.Text("没有这个底图哦~"))
})
en.OnFullMatchGroup([]string{"运势", "抽签"}).SetBlock(true).
en.OnFullMatchGroup([]string{"运势", "抽签"}, ctxext.DoOnceOnSuccess(
func(ctx *zero.Ctx) bool {
data, err := file.GetLazyData(omikujson, true, false)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = json.Unmarshal(data, &omikujis)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
_, err = file.GetLazyData(font, false, true)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
return true
},
)).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
// 获取该群背景类型,默认车万
kind := "车万"

View File

@@ -29,22 +29,27 @@ func init() {
PublicDataFolder: "Funny",
})
go func() {
en.OnPrefix("讲个笑话", ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
dbpath := en.DataFolder()
db.DBPath = dbpath + "jokes.db"
_, err := file.GetLazyData(db.DBPath, false, true)
if err != nil {
panic(err)
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = db.Create("jokes", &joke{})
if err != nil {
panic(err)
ctx.SendChain(message.Text("ERROR:", err))
return false
}
c, err := db.Count("jokes")
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
c, _ := db.Count("jokes")
logrus.Infoln("[funny]加载", c, "个笑话")
}()
en.OnPrefix("讲个笑话").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
return true
})).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
// 获取名字
name := ctx.NickName()
var j joke

View File

@@ -38,18 +38,6 @@ func init() {
PublicDataFolder: "Genshin",
}).ApplySingle(ctxext.DefaultSingle)
go func() {
zipfile := engine.DataFolder() + "Genshin.zip"
_, err := file.GetLazyData(zipfile, false, false)
if err != nil {
panic(err)
}
err = parsezip(zipfile)
if err != nil {
panic(err)
}
}()
engine.OnFullMatch("切换原神卡池").SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
c, ok := control.Lookup("genshin")
@@ -76,7 +64,22 @@ func init() {
}
})
engine.OnFullMatch("原神十连").SetBlock(true).Limit(ctxext.LimitByUser).
engine.OnFullMatch("原神十连", ctxext.DoOnceOnSuccess(
func(ctx *zero.Ctx) bool {
zipfile := engine.DataFolder() + "Genshin.zip"
_, err := file.GetLazyData(zipfile, false, false)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = parsezip(zipfile)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
return true
},
)).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
c, ok := control.Lookup("genshin")
if !ok {

View File

@@ -9,6 +9,7 @@ import (
"github.com/FloatTech/zbputils/binary"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
"github.com/FloatTech/zbputils/file"
"github.com/antchfx/htmlquery"
"github.com/sirupsen/logrus"
@@ -27,22 +28,25 @@ func init() {
PublicDataFolder: "Jandan",
})
go func() {
getdb := ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
dbpath := engine.DataFolder()
db.DBPath = dbpath + "pics.db"
_, _ = file.GetLazyData(db.DBPath, false, false)
err := db.Create("picture", &picture{})
if err != nil {
panic(err)
ctx.SendChain(message.Text("ERROR:", err))
return false
}
n, err := db.Count("picture")
if err != nil {
panic(err)
ctx.SendChain(message.Text("ERROR:", err))
return false
}
logrus.Printf("[jandan]读取%d张图片", n)
}()
return true
})
engine.OnRegex(`来份[屌|弔|吊]图`).SetBlock(true).
engine.OnRegex(`来份[屌|弔|吊]图`, getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
u, err := getRandomPicture()
if err != nil {
@@ -52,7 +56,7 @@ func init() {
ctx.SendChain(message.Image(u))
})
engine.OnRegex(`更新[屌|弔|吊]图`, zero.SuperUserPermission).SetBlock(true).
engine.OnRegex(`更新[屌|弔|吊]图`, zero.SuperUserPermission, getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
ctx.Send("少女更新中...")
webpageURL := api

View File

@@ -3,11 +3,11 @@ package omikuji
import (
"fmt"
"log"
"math/rand"
"strconv"
"time"
log "github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
"github.com/wdvxdr1123/ZeroBot/utils/helper"
@@ -28,21 +28,6 @@ func init() { // 插件主体
PublicDataFolder: "Omikuji",
}).ApplySingle(ctxext.DefaultSingle)
go func() {
dbpath := engine.DataFolder()
db.DBPath = dbpath + "kuji.db"
_, _ = file.GetLazyData(db.DBPath, false, true)
err := db.Create("kuji", &kuji{})
if err != nil {
panic(err)
}
n, err := db.Count("kuji")
if err != nil {
panic(err)
}
log.Printf("[kuji]读取%d条签文", n)
}()
engine.OnFullMatchGroup([]string{"求签", "占卜"}).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
miku, err := bangoToday(ctx.Event.UserID)
@@ -56,7 +41,29 @@ func init() { // 插件主体
message.Image(fmt.Sprintf(bed, miku, 1)),
)
})
engine.OnFullMatchGroup([]string{"解签"}).SetBlock(true).
engine.OnFullMatch("解签", ctxext.DoOnceOnSuccess(
func(ctx *zero.Ctx) bool {
dbpath := engine.DataFolder()
db.DBPath = dbpath + "kuji.db"
_, err := file.GetLazyData(db.DBPath, false, true)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = db.Create("kuji", &kuji{})
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
n, err := db.Count("kuji")
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
log.Printf("[kuji]读取%d条签文", n)
return true
},
)).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
bg, err := bangoToday(ctx.Event.UserID)
if err != nil {

View File

@@ -5,7 +5,8 @@ import (
"fmt"
"math/rand"
control "github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
wr "github.com/mroth/weightedrand"
"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
@@ -18,26 +19,31 @@ func init() {
Help: "投胎\n- reborn",
PublicDataFolder: "Reborn",
})
go func() {
datapath := en.DataFolder()
jsonfile := datapath + "rate.json"
area := make(rate, 226)
err := load(&area, jsonfile)
if err != nil {
panic(err)
}
choices := make([]wr.Choice, len(area))
for i, a := range area {
choices[i].Item = a.Name
choices[i].Weight = uint(a.Weight * 1e9)
}
areac, err = wr.NewChooser(choices...)
if err != nil {
panic(err)
}
logrus.Printf("[Reborn]读取%d个国家/地区", len(area))
}()
en.OnFullMatch("reborn").SetBlock(true).
en.OnFullMatch("reborn", ctxext.DoOnceOnSuccess(
func(ctx *zero.Ctx) bool {
datapath := en.DataFolder()
jsonfile := datapath + "rate.json"
area := make(rate, 226)
err := load(&area, jsonfile)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
choices := make([]wr.Choice, len(area))
for i, a := range area {
choices[i].Item = a.Name
choices[i].Weight = uint(a.Weight * 1e9)
}
areac, err = wr.NewChooser(choices...)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
logrus.Printf("[Reborn]读取%d个国家/地区", len(area))
return true
},
)).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
if rand.Int31() > 1<<27 {
ctx.SendChain(message.At(ctx.Event.UserID), message.Text(fmt.Sprintf("投胎成功!\n您出生在 %s, 是 %s。", randcoun(), randgen())))

View File

@@ -65,7 +65,7 @@ func (sdb *scoredb) Close() error {
// GetScoreByUID 取得分数
func (sdb *scoredb) GetScoreByUID(uid int64) (s scoretable) {
db := (*gorm.DB)(sdb)
db.Debug().Model(&scoretable{}).FirstOrCreate(&s, "uid = ? ", uid)
db.Model(&scoretable{}).FirstOrCreate(&s, "uid = ? ", uid)
return s
}
@@ -76,13 +76,13 @@ func (sdb *scoredb) InsertOrUpdateScoreByUID(uid int64, score int) (err error) {
UID: uid,
Score: score,
}
if err = db.Debug().Model(&scoretable{}).First(&s, "uid = ? ", uid).Error; err != nil {
if err = db.Model(&scoretable{}).First(&s, "uid = ? ", uid).Error; err != nil {
// error handling...
if gorm.IsRecordNotFoundError(err) {
err = db.Debug().Model(&scoretable{}).Create(&s).Error // newUser not user
err = db.Model(&scoretable{}).Create(&s).Error // newUser not user
}
} else {
err = db.Debug().Model(&scoretable{}).Where("uid = ? ", uid).Update(
err = db.Model(&scoretable{}).Where("uid = ? ", uid).Update(
map[string]interface{}{
"score": score,
}).Error
@@ -93,7 +93,7 @@ func (sdb *scoredb) InsertOrUpdateScoreByUID(uid int64, score int) (err error) {
// GetSignInByUID 取得签到次数
func (sdb *scoredb) GetSignInByUID(uid int64) (si signintable) {
db := (*gorm.DB)(sdb)
db.Debug().Model(&signintable{}).FirstOrCreate(&si, "uid = ? ", uid)
db.Model(&signintable{}).FirstOrCreate(&si, "uid = ? ", uid)
return si
}
@@ -104,13 +104,13 @@ func (sdb *scoredb) InsertOrUpdateSignInCountByUID(uid int64, count int) (err er
UID: uid,
Count: count,
}
if err = db.Debug().Model(&signintable{}).First(&si, "uid = ? ", uid).Error; err != nil {
if err = db.Model(&signintable{}).First(&si, "uid = ? ", uid).Error; err != nil {
// error handling...
if gorm.IsRecordNotFoundError(err) {
db.Debug().Model(&signintable{}).Create(&si) // newUser not user
db.Model(&signintable{}).Create(&si) // newUser not user
}
} else {
err = db.Debug().Model(&signintable{}).Where("uid = ? ", uid).Update(
err = db.Model(&signintable{}).Where("uid = ? ", uid).Update(
map[string]interface{}{
"count": count,
}).Error
@@ -120,6 +120,6 @@ func (sdb *scoredb) InsertOrUpdateSignInCountByUID(uid int64, count int) (err er
func (sdb *scoredb) GetScoreRankByTopN(n int) (st []scoretable, err error) {
db := (*gorm.DB)(sdb)
err = db.Debug().Model(&scoretable{}).Order("score desc").Limit(n).Find(&st).Error
err = db.Model(&scoretable{}).Order("score desc").Limit(n).Find(&st).Error
return
}

View File

@@ -59,22 +59,25 @@ func init() { // 插件主体
PublicDataFolder: "SetuTime",
})
go func() {
getdb := ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
// 如果数据库不存在则下载
pool.db.DBPath = engine.DataFolder() + "SetuTime.db"
_, _ = fileutil.GetLazyData(pool.db.DBPath, false, false)
err := pool.db.Open()
if err != nil {
panic(err)
ctx.SendChain(message.Text("ERROR:", err))
return false
}
for _, imgtype := range pool.List() {
if err := pool.db.Create(imgtype, &pixiv.Illust{}); err != nil {
panic(err)
ctx.SendChain(message.Text("ERROR:", err))
return false
}
}
}()
return true
})
engine.OnRegex(`^来份(.+)$`, ctxext.FirstValueInList(pool)).SetBlock(true).Limit(ctxext.LimitByUser).
engine.OnRegex(`^来份(.+)$`, getdb, ctxext.FirstValueInList(pool)).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
var imgtype = ctx.State["regex_matched"].([]string)[1]
// 补充池子
@@ -94,7 +97,7 @@ func init() { // 插件主体
}
})
engine.OnRegex(`^添加(.+)\s?(\d+)$`, zero.SuperUserPermission).SetBlock(true).
engine.OnRegex(`^添加(.+)\s?(\d+)$`, zero.SuperUserPermission, getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
var (
imgtype = ctx.State["regex_matched"].([]string)[1]
@@ -108,7 +111,7 @@ func init() { // 插件主体
ctx.SendChain(message.Text("成功向分类", imgtype, "添加图片", id))
})
engine.OnRegex(`^删除(.+)\s?(\d+)$`, ctxext.FirstValueInList(pool), zero.SuperUserPermission).SetBlock(true).
engine.OnRegex(`^删除(.+)\s?(\d+)$`, getdb, ctxext.FirstValueInList(pool), zero.SuperUserPermission).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
var (
imgtype = ctx.State["regex_matched"].([]string)[1]
@@ -123,7 +126,7 @@ func init() { // 插件主体
})
// 查询数据库涩图数量
engine.OnFullMatchGroup([]string{">setu status"}).SetBlock(true).
engine.OnFullMatch(">setu status", getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
state := []string{"[SetuTime]"}
pool.dbmu.RLock()

View File

@@ -68,20 +68,20 @@ func (sdb *sleepdb) sleep(gid, uid int64) (position int, awakeTime time.Duration
UserID: uid,
SleepTime: now,
}
if err := db.Debug().Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).First(&st).Error; err != nil {
if err := db.Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).First(&st).Error; err != nil {
// error handling...
if gorm.IsRecordNotFoundError(err) {
db.Debug().Model(&SleepManage{}).Create(&st) // newUser not user
db.Model(&SleepManage{}).Create(&st) // newUser not user
}
} else {
log.Debugln("sleeptime为", st)
awakeTime = now.Sub(st.SleepTime)
db.Debug().Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).Update(
db.Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).Update(
map[string]interface{}{
"sleep_time": now,
})
}
db.Debug().Model(&SleepManage{}).Where("group_id = ? and sleep_time <= ? and sleep_time >= ?", gid, now, today).Count(&position)
db.Model(&SleepManage{}).Where("group_id = ? and sleep_time <= ? and sleep_time >= ?", gid, now, today).Count(&position)
return position, awakeTime
}
@@ -95,19 +95,19 @@ func (sdb *sleepdb) getUp(gid, uid int64) (position int, sleepTime time.Duration
UserID: uid,
SleepTime: now,
}
if err := db.Debug().Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).First(&st).Error; err != nil {
if err := db.Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).First(&st).Error; err != nil {
// error handling...
if gorm.IsRecordNotFoundError(err) {
db.Debug().Model(&SleepManage{}).Create(&st) // newUser not user
db.Model(&SleepManage{}).Create(&st) // newUser not user
}
} else {
log.Debugln("sleeptime为", st)
sleepTime = now.Sub(st.SleepTime)
db.Debug().Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).Update(
db.Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).Update(
map[string]interface{}{
"sleep_time": now,
})
}
db.Debug().Model(&SleepManage{}).Where("group_id = ? and sleep_time <= ? and sleep_time >= ?", gid, now, today).Count(&position)
db.Model(&SleepManage{}).Where("group_id = ? and sleep_time <= ? and sleep_time >= ?", gid, now, today).Count(&position)
return position, sleepTime
}

View File

@@ -26,22 +26,29 @@ func init() {
PublicDataFolder: "Tiangou",
})
go func() {
dbpath := en.DataFolder()
db.DBPath = dbpath + "tiangou.db"
_, err := file.GetLazyData(db.DBPath, false, true)
if err != nil {
panic(err)
}
err = db.Create("tiangou", &tiangou{})
if err != nil {
panic(err)
}
c, _ := db.Count("tiangou")
logrus.Infoln("[tiangou]加载", c, "条舔狗日记")
}()
en.OnFullMatch("舔狗日记").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
en.OnFullMatch("舔狗日记", ctxext.DoOnceOnSuccess(
func(ctx *zero.Ctx) bool {
dbpath := en.DataFolder()
db.DBPath = dbpath + "tiangou.db"
_, err := file.GetLazyData(db.DBPath, false, true)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = db.Create("tiangou", &tiangou{})
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
c, err := db.Count("tiangou")
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
logrus.Infoln("[tiangou]加载", c, "条舔狗日记")
return true
},
)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
var t tiangou
err := db.Pick("tiangou", &t)
if err != nil {

View File

@@ -99,7 +99,7 @@ func (vdb *VtbDB) GetAllFirstCategoryMessage() (string, error) {
db := (*gorm.DB)(vdb)
firstStepMessage := "请选择一个vtb并发送序号:\n"
var fcl []FirstCategory
err := db.Debug().Model(&FirstCategory{}).Find(&fcl).Error
err := db.Model(&FirstCategory{}).Find(&fcl).Error
if err != nil {
return "", err
}
@@ -116,7 +116,7 @@ func (vdb *VtbDB) GetAllSecondCategoryMessageByFirstIndex(firstIndex int) (strin
var scl []SecondCategory
var fc FirstCategory
db.Model(FirstCategory{}).Where("first_category_index = ?", firstIndex).First(&fc)
err := db.Debug().Model(&SecondCategory{}).Find(&scl, "first_category_uid = ?", fc.FirstCategoryUID).Error
err := db.Model(&SecondCategory{}).Find(&scl, "first_category_uid = ?", fc.FirstCategoryUID).Error
if err != nil || len(scl) == 0 {
return "", err
}
@@ -133,7 +133,7 @@ func (vdb *VtbDB) GetAllThirdCategoryMessageByFirstIndexAndSecondIndex(firstInde
var fc FirstCategory
db.Model(FirstCategory{}).Where("first_category_index = ?", firstIndex).First(&fc)
var tcl []ThirdCategory
err := db.Debug().Model(&ThirdCategory{}).Find(&tcl, "first_category_uid = ? and second_category_index = ?", fc.FirstCategoryUID, secondIndex).Error
err := db.Model(&ThirdCategory{}).Find(&tcl, "first_category_uid = ? and second_category_index = ?", fc.FirstCategoryUID, secondIndex).Error
if err != nil || len(tcl) == 0 {
return "", err
}
@@ -217,12 +217,12 @@ func (vdb *VtbDB) GetVtbList() (uidList []string, err error) {
}
log.Debugln(fc)
if err := db.Debug().Model(&FirstCategory{}).First(&fc, "first_category_uid = ?", fc.FirstCategoryUID).Error; err != nil {
if err := db.Model(&FirstCategory{}).First(&fc, "first_category_uid = ?", fc.FirstCategoryUID).Error; err != nil {
if gorm.IsRecordNotFoundError(err) {
db.Debug().Model(&FirstCategory{}).Create(&fc) // newUser not user
db.Model(&FirstCategory{}).Create(&fc) // newUser not user
}
} else {
db.Debug().Model(&FirstCategory{}).Where("first_category_uid = ?", fc.FirstCategoryUID).Update(
db.Model(&FirstCategory{}).Where("first_category_uid = ?", fc.FirstCategoryUID).Update(
map[string]interface{}{
"first_category_index": i,
"first_category_name": item.Get("name").String(),
@@ -276,13 +276,13 @@ func (vdb *VtbDB) StoreVtb(uid string) (err error) {
FirstCategoryUID: uid,
}
if err := db.Debug().Model(&SecondCategory{}).First(&sc, "first_category_uid = ? and second_category_index = ?", uid, secondIndex).Error; err != nil {
if err := db.Model(&SecondCategory{}).First(&sc, "first_category_uid = ? and second_category_index = ?", uid, secondIndex).Error; err != nil {
// error handling...
if gorm.IsRecordNotFoundError(err) {
db.Debug().Model(&SecondCategory{}).Create(&sc) // newUser not user
db.Model(&SecondCategory{}).Create(&sc) // newUser not user
}
} else {
db.Debug().Model(&SecondCategory{}).Where("first_category_uid = ? and second_category_index = ?", uid, secondIndex).Update(
db.Model(&SecondCategory{}).Where("first_category_uid = ? and second_category_index = ?", uid, secondIndex).Update(
map[string]interface{}{
"second_category_name": secondItem.Get("categoryName").String(),
"second_category_author": secondItem.Get("author").String(),
@@ -305,13 +305,13 @@ func (vdb *VtbDB) StoreVtb(uid string) (err error) {
}
log.Debugln(tc)
if err := db.Debug().Model(&ThirdCategory{}).First(&tc, "first_category_uid = ? and second_category_index = ? and third_category_index = ?",
if err := db.Model(&ThirdCategory{}).First(&tc, "first_category_uid = ? and second_category_index = ? and third_category_index = ?",
uid, secondIndex, thirdIndex).Error; err != nil {
if gorm.IsRecordNotFoundError(err) {
db.Debug().Model(&ThirdCategory{}).Create(&tc) // newUser not user
db.Model(&ThirdCategory{}).Create(&tc) // newUser not user
}
} else {
db.Debug().Model(&ThirdCategory{}).Where("first_category_uid = ? and second_category_index = ? and third_category_index = ?",
db.Model(&ThirdCategory{}).Where("first_category_uid = ? and second_category_index = ? and third_category_index = ?",
uid, secondIndex, thirdIndex).Update(
map[string]interface{}{
"third_category_name": thirdItem.Get("name").String(),

View File

@@ -18,6 +18,7 @@ import (
"github.com/wdvxdr1123/ZeroBot/utils/helper"
control "github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
"github.com/FloatTech/zbputils/file"
"github.com/FloatTech/zbputils/img/text"
"github.com/FloatTech/zbputils/web"
@@ -40,14 +41,21 @@ func init() {
})
dbfile := engine.DataFolder() + "vtb.db"
storePath := engine.DataFolder() + "store/"
go func() {
getdb := ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
err := os.MkdirAll(storePath, 0755)
if err != nil {
panic(err)
ctx.SendChain(message.Text("ERROR:", err))
return false
}
_, _ = file.GetLazyData(dbfile, false, false)
}()
engine.OnFullMatch("vtb语录").SetBlock(true).
_, err = file.GetLazyData(dbfile, false, false)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
return true
})
engine.OnFullMatch("vtb语录", getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
var firstIndex int
var secondIndex int
@@ -238,7 +246,7 @@ func init() {
}
}
})
engine.OnFullMatch("随机vtb").SetBlock(true).
engine.OnFullMatch("随机vtb", getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
db, err := model.Open(dbfile)
if err != nil {
@@ -274,7 +282,7 @@ func init() {
ctx.SendChain(message.Record("file:///" + file.BOTPATH + "/" + recordFile))
}
})
engine.OnFullMatch("更新vtb", zero.SuperUserPermission).SetBlock(true).
engine.OnFullMatch("更新vtb", zero.SuperUserPermission, getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
ctx.Send("少女祈祷中......")
db := model.Initialize(dbfile)

View File

@@ -0,0 +1,181 @@
// Package wordcount 聊天热词
package wordcount
import (
"fmt"
"os"
"regexp"
"sort"
"strconv"
"strings"
"time"
"github.com/FloatTech/zbputils/binary"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
"github.com/FloatTech/zbputils/file"
"github.com/FloatTech/zbputils/img/text"
"github.com/golang/freetype"
"github.com/sirupsen/logrus"
"github.com/wcharczuk/go-chart/v2"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)
var (
re = regexp.MustCompile(`^[一-龥]+$`)
stopwords []string
)
func init() {
engine := control.Register("wordcount", &control.Options{
DisableOnDefault: false,
Help: "聊天热词\n" +
"- 热词 [群号] [消息数目]|热词 123456 1000",
PublicDataFolder: "WordCount",
})
cachePath := engine.DataFolder() + "cache/"
_ = os.RemoveAll(cachePath)
_ = os.MkdirAll(cachePath, 0755)
engine.OnRegex(`^热词\s?(\d*)\s?(\d*)$`, zero.OnlyGroup, ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
_, err := file.GetLazyData(engine.DataFolder()+"stopwords.txt", false, false)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
data, err := os.ReadFile(engine.DataFolder() + "stopwords.txt")
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
stopwords = strings.Split(binary.BytesToString(data), "\r\n")
sort.Strings(stopwords)
logrus.Infoln("[wordcount]加载", len(stopwords), "条停用词")
return true
})).Limit(ctxext.LimitByUser).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
ctx.SendChain(message.Text("少女祈祷中..."))
gid, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64)
p, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
if p > 10000 {
p = 10000
}
if p == 0 {
p = 1000
}
if gid == 0 {
gid = ctx.Event.GroupID
}
group := ctx.GetGroupInfo(gid, false)
if group.MemberCount == 0 {
ctx.SendChain(message.Text(zero.BotConfig.NickName[0], "未加入", group.Name, "(", gid, "),无法获得热词呢"))
return
}
today := time.Now().Format("20060102")
drawedFile := fmt.Sprintf("%s%d%s%dwordCount.png", cachePath, gid, today, p)
if file.IsExist(drawedFile) {
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + drawedFile))
return
}
messageMap := make(map[string]int)
h := ctx.CallAction("get_group_msg_history", zero.Params{"group_id": gid}).Data
messageSeq := h.Get("messages.0.message_seq").Int()
for i := 0; i < int(p/20) && messageSeq != 0; i++ {
if i != 0 {
h = ctx.CallAction("get_group_msg_history", zero.Params{"group_id": gid, "message_seq": messageSeq}).Data
}
for _, v := range h.Get("messages.#.message").Array() {
tex := strings.TrimSpace(message.ParseMessageFromString(v.Str).ExtractPlainText())
if tex == "" {
continue
}
for _, t := range ctx.GetWordSlices(tex).Get("slices").Array() {
tex := strings.TrimSpace(t.Str)
i := sort.SearchStrings(stopwords, tex)
if re.MatchString(tex) && (i >= len(stopwords) || stopwords[i] != tex) {
messageMap[tex]++
}
}
}
messageSeq = h.Get("messages.0.message_seq").Int()
}
wc := rankByWordCount(messageMap)
if len(wc) > 20 {
wc = wc[:20]
}
// 绘图
if len(wc) == 0 {
ctx.SendChain(message.Text("ERROR:历史消息为空或者无法获得历史消息"))
return
}
_, err := file.GetLazyData(text.FontFile, false, true)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
b, err := os.ReadFile(text.FontFile)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
font, err := freetype.ParseFont(b)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
bars := make([]chart.Value, len(wc))
for i, v := range wc {
bars[i] = chart.Value{
Value: float64(v.Value),
Label: v.Key,
}
}
graph := chart.BarChart{
Font: font,
Title: fmt.Sprintf("%s(%d)在%s号的%d条消息的热词top20", group.Name, gid, time.Now().Format("2006-01-02"), p),
Background: chart.Style{
Padding: chart.Box{
Top: 40,
},
},
Height: 500,
BarWidth: 25,
Bars: bars,
}
f, err := os.Create(drawedFile)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
err = graph.Render(chart.PNG, f)
_ = f.Close()
if err != nil {
_ = os.Remove(drawedFile)
ctx.SendChain(message.Text("ERROR:", err))
return
}
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + drawedFile))
})
}
func rankByWordCount(wordFrequencies map[string]int) pairlist {
pl := make(pairlist, len(wordFrequencies))
i := 0
for k, v := range wordFrequencies {
pl[i] = pair{k, v}
i++
}
sort.Sort(sort.Reverse(pl))
return pl
}
type pair struct {
Key string
Value int
}
type pairlist []pair
func (p pairlist) Len() int { return len(p) }
func (p pairlist) Less(i, j int) bool { return p[i].Value < p[j].Value }
func (p pairlist) Swap(i, j int) { p[i], p[j] = p[j], p[i] }

View File

@@ -9,10 +9,13 @@ import (
"sort"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/FloatTech/AnimeAPI/tl"
"github.com/sirupsen/logrus"
"github.com/FloatTech/zbputils/binary"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
"github.com/FloatTech/zbputils/file"
@@ -55,10 +58,7 @@ type dictionary map[int]struct {
cet4 []string
}
var (
words = make(dictionary)
wordsmu sync.Mutex
)
var words = make(dictionary)
func init() {
en := control.Register("wordle", &control.Options{
@@ -77,35 +77,55 @@ func init() {
)
}),
))
for i := 5; i <= 7; i++ {
go func(i int) {
dc, err := file.GetLazyData(fmt.Sprintf("%scet-4_%d.txt", en.DataFolder(), i), true, true)
if err != nil {
panic(err)
en.OnRegex(`^(个人|团队)(五阶|六阶|七阶)?猜单词$`, zero.OnlyGroup, ctxext.DoOnceOnSuccess(
func(ctx *zero.Ctx) bool {
var errcnt uint32
var wg sync.WaitGroup
var mu sync.Mutex
for i := 5; i <= 7; i++ {
wg.Add(2)
go func(i int) {
defer wg.Done()
dc, err := file.GetLazyData(fmt.Sprintf("%scet-4_%d.txt", en.DataFolder(), i), true, true)
logrus.Debugln("[wordle] get", fmt.Sprintf("%scet-4_%d.txt", en.DataFolder(), i))
if err != nil {
atomic.AddUint32(&errcnt, 1)
return
}
c := strings.Split(binary.BytesToString(dc), "\n")
sort.Strings(c)
mu.Lock()
tmp := words[i]
tmp.cet4 = c
words[i] = tmp
mu.Unlock()
}(i)
go func(i int) {
defer wg.Done()
dd, err := file.GetLazyData(fmt.Sprintf("%sdict_%d.txt", en.DataFolder(), i), true, true)
logrus.Debugln("[wordle] get", fmt.Sprintf("%sdict_%d.txt", en.DataFolder(), i))
if err != nil {
atomic.AddUint32(&errcnt, 1)
return
}
d := strings.Split(binary.BytesToString(dd), "\n")
sort.Strings(d)
mu.Lock()
tmp := words[i]
tmp.dict = d
words[i] = tmp
mu.Unlock()
}(i)
}
c := strings.Split(string(dc), "\n")
sort.Strings(c)
wordsmu.Lock()
tmp := words[i]
tmp.cet4 = c
words[i] = tmp
wordsmu.Unlock()
}(i)
go func(i int) {
dd, err := file.GetLazyData(fmt.Sprintf("%sdict_%d.txt", en.DataFolder(), i), true, true)
if err != nil {
panic(err)
wg.Wait()
if errcnt > 0 {
ctx.SendChain(message.Text("ERROR:下载字典时发生", errcnt, "个错误"))
return false
}
d := strings.Split(string(dd), "\n")
sort.Strings(d)
wordsmu.Lock()
tmp := words[i]
tmp.dict = d
words[i] = tmp
wordsmu.Unlock()
}(i)
}
en.OnRegex(`(个人|团队)(五阶|六阶|七阶)?猜单词`, zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByUser).
return true
},
)).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
class := classdict[ctx.State["regex_matched"].([]string)[2]]
target := words[class].cet4[rand.Intn(len(words[class].cet4))]

View File

@@ -38,22 +38,21 @@ func (ymgal) TableName() string {
}
// initialize 初始化ymgaldb数据库
func initialize(dbpath string) *ymgaldb {
var err error
func initialize(dbpath string) (db *ymgaldb, err error) {
if _, err = os.Stat(dbpath); err != nil || os.IsNotExist(err) {
// 生成文件
f, err := os.Create(dbpath)
if err != nil {
return nil
return nil, err
}
defer f.Close()
_ = f.Close()
}
gdb, err := gorm.Open("sqlite3", dbpath)
if err != nil {
panic(err)
return
}
gdb.AutoMigrate(&ymgal{})
return (*ymgaldb)(gdb)
return (*ymgaldb)(gdb), nil
}
func (gdb *ymgaldb) insertOrUpdateYmgalByID(id int64, title, pictureType, pictureDescription, pictureList string) (err error) {
@@ -65,12 +64,12 @@ func (gdb *ymgaldb) insertOrUpdateYmgalByID(id int64, title, pictureType, pictur
PictureDescription: pictureDescription,
PictureList: pictureList,
}
if err = db.Debug().Model(&ymgal{}).First(&y, "id = ? ", id).Error; err != nil {
if err = db.Model(&ymgal{}).First(&y, "id = ? ", id).Error; err != nil {
if gorm.IsRecordNotFoundError(err) {
err = db.Debug().Model(&ymgal{}).Create(&y).Error // newUser not user
err = db.Model(&ymgal{}).Create(&y).Error // newUser not user
}
} else {
err = db.Debug().Model(&ymgal{}).Where("id = ? ", id).Update(map[string]interface{}{
err = db.Model(&ymgal{}).Where("id = ? ", id).Update(map[string]interface{}{
"title": title,
"picture_type": pictureType,
"picture_description": pictureDescription,
@@ -82,14 +81,14 @@ func (gdb *ymgaldb) insertOrUpdateYmgalByID(id int64, title, pictureType, pictur
func (gdb *ymgaldb) getYmgalByID(id string) (y ymgal) {
db := (*gorm.DB)(gdb)
db.Debug().Model(&ymgal{}).Where("id = ?", id).Take(&y)
db.Model(&ymgal{}).Where("id = ?", id).Take(&y)
return
}
func (gdb *ymgaldb) randomYmgal(pictureType string) (y ymgal) {
db := (*gorm.DB)(gdb)
var count int
s := db.Debug().Model(&ymgal{}).Where("picture_type = ?", pictureType).Count(&count)
s := db.Model(&ymgal{}).Where("picture_type = ?", pictureType).Count(&count)
if count == 0 {
return
}
@@ -100,7 +99,7 @@ func (gdb *ymgaldb) randomYmgal(pictureType string) (y ymgal) {
func (gdb *ymgaldb) getYmgalByKey(pictureType, key string) (y ymgal) {
db := (*gorm.DB)(gdb)
var count int
s := db.Debug().Model(&ymgal{}).Where("picture_type = ? and (picture_description like ? or title like ?) ", pictureType, "%"+key+"%", "%"+key+"%").Count(&count)
s := db.Model(&ymgal{}).Where("picture_type = ? and (picture_description like ? or title like ?) ", pictureType, "%"+key+"%", "%"+key+"%").Count(&count)
if count == 0 {
return
}

View File

@@ -18,11 +18,20 @@ func init() {
PublicDataFolder: "Ymgal",
})
dbfile := engine.DataFolder() + "ymgal.db"
go func() {
_, _ = file.GetLazyData(dbfile, false, false)
gdb = initialize(dbfile)
}()
engine.OnRegex("^随机gal(CG|表情包)$").Limit(ctxext.LimitByUser).SetBlock(true).
getdb := ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
_, err := file.GetLazyData(dbfile, false, false)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
gdb, err = initialize(dbfile)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
return true
})
engine.OnRegex("^随机gal(CG|表情包)$", getdb).Limit(ctxext.LimitByUser).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
ctx.Send("少女祈祷中......")
pictureType := ctx.State["regex_matched"].([]string)[1]
@@ -34,7 +43,7 @@ func init() {
}
sendYmgal(y, ctx)
})
engine.OnRegex("^gal(CG|表情包)([一-龥ぁ-んァ-ヶA-Za-z0-9]{1,25})$").Limit(ctxext.LimitByUser).SetBlock(true).
engine.OnRegex("^gal(CG|表情包)([一-龥ぁ-んァ-ヶA-Za-z0-9]{1,25})$", getdb).Limit(ctxext.LimitByUser).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
ctx.Send("少女祈祷中......")
pictureType := ctx.State["regex_matched"].([]string)[1]
@@ -47,7 +56,7 @@ func init() {
}
sendYmgal(y, ctx)
})
engine.OnFullMatch("更新gal", zero.SuperUserPermission).SetBlock(true).Handle(
engine.OnFullMatch("更新gal", zero.SuperUserPermission, getdb).SetBlock(true).Handle(
func(ctx *zero.Ctx) {
ctx.Send("少女祈祷中......")
err := updatePic()