mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
⚡️ 🎨 🔥 优化代码结构
This commit is contained in:
parent
121403231a
commit
4ca5038ae9
4
go.mod
4
go.mod
@ -3,9 +3,9 @@ module github.com/FloatTech/ZeroBot-Plugin
|
|||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220215081026-d6f95aaf77df
|
github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220215114239-bcb083dfeb08
|
||||||
github.com/FloatTech/sqlite v0.1.0
|
github.com/FloatTech/sqlite v0.1.0
|
||||||
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220215053220-192931cec3a8
|
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220215114138-e858f7fbf9f7
|
||||||
github.com/antchfx/htmlquery v1.2.4
|
github.com/antchfx/htmlquery v1.2.4
|
||||||
github.com/corona10/goimagehash v1.0.3
|
github.com/corona10/goimagehash v1.0.3
|
||||||
github.com/fogleman/gg v1.3.0
|
github.com/fogleman/gg v1.3.0
|
||||||
|
|||||||
8
go.sum
8
go.sum
@ -1,10 +1,10 @@
|
|||||||
github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220215081026-d6f95aaf77df h1:HLbcSbk4ReH+f6C+jGur32CP3NqWqGDCUAvcITOFSXU=
|
github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220215114239-bcb083dfeb08 h1:UcvmuO3WO4ecqpciM0Cr8nxXDQjH66klPMFQNfdr9bk=
|
||||||
github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220215081026-d6f95aaf77df/go.mod h1:Kl18EWeAbw1xxqq/2KgS1pT3PmJv+9vWBeD3TNdIDvE=
|
github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220215114239-bcb083dfeb08/go.mod h1:HH4BkFvRhMlRG6etlFhilf+Di3Xcejke38VKSZSlaNQ=
|
||||||
github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9O/jd5BPSfWfOQ=
|
github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9O/jd5BPSfWfOQ=
|
||||||
github.com/FloatTech/sqlite v0.1.0 h1:Geh6Z+DWZXmyXVOhM0U2oXT7b1Ob6sQtuyjInk+MCUk=
|
github.com/FloatTech/sqlite v0.1.0 h1:Geh6Z+DWZXmyXVOhM0U2oXT7b1Ob6sQtuyjInk+MCUk=
|
||||||
github.com/FloatTech/sqlite v0.1.0/go.mod h1:XS0oeSqtH6lFzpPRiDE9fV6+zMcuUF5/6o+tQVO1QZE=
|
github.com/FloatTech/sqlite v0.1.0/go.mod h1:XS0oeSqtH6lFzpPRiDE9fV6+zMcuUF5/6o+tQVO1QZE=
|
||||||
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220215053220-192931cec3a8 h1:BLuZxgk5HcqNmxbieAurWAxbVQfUYwMo+jq6a0IA6tU=
|
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220215114138-e858f7fbf9f7 h1:c+nr+Lbpc5kZgFi0WPY3yJxO6gpbvRbZEc4v6eVkQos=
|
||||||
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220215053220-192931cec3a8/go.mod h1:s4RcgaO+X7y/ZkKcRt0b7Dg/AsnMFeS1kVylKGUiMhk=
|
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220215114138-e858f7fbf9f7/go.mod h1:s4RcgaO+X7y/ZkKcRt0b7Dg/AsnMFeS1kVylKGUiMhk=
|
||||||
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
||||||
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc h1:AAx50/fb/xS4lvsdQg+bFbGvqSDhyV1MF+p2PLCamZ0=
|
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc h1:AAx50/fb/xS4lvsdQg+bFbGvqSDhyV1MF+p2PLCamZ0=
|
||||||
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc/go.mod h1:OMmITAib6POA37xCichWM0aRnoVpSMZO1rB/G01wrr0=
|
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc/go.mod h1:OMmITAib6POA37xCichWM0aRnoVpSMZO1rB/G01wrr0=
|
||||||
|
|||||||
@ -7,20 +7,21 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control"
|
|
||||||
"github.com/FloatTech/zbputils/ctxext"
|
|
||||||
"github.com/FloatTech/zbputils/img/text"
|
|
||||||
"github.com/FloatTech/zbputils/web"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
|
||||||
|
|
||||||
|
"github.com/FloatTech/zbputils/binary"
|
||||||
|
"github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
|
"github.com/FloatTech/zbputils/img/text"
|
||||||
|
"github.com/FloatTech/zbputils/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -34,6 +35,9 @@ const (
|
|||||||
serviceName = "bilibilipush"
|
serviceName = "bilibilipush"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// bdb bilibili推送数据库
|
||||||
|
var bdb *bilibilipushdb
|
||||||
|
|
||||||
var (
|
var (
|
||||||
lastTime = map[int64]int64{}
|
lastTime = map[int64]int64{}
|
||||||
typeMsg = map[int64]string{
|
typeMsg = map[int64]string{
|
||||||
@ -65,8 +69,24 @@ func init() {
|
|||||||
"- 取消动态订阅[uid]\n" +
|
"- 取消动态订阅[uid]\n" +
|
||||||
"- 取消直播订阅[uid]\n" +
|
"- 取消直播订阅[uid]\n" +
|
||||||
"- 推送列表",
|
"- 推送列表",
|
||||||
|
PrivateDataFolder: serviceName,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 加载数据库
|
||||||
|
go func() {
|
||||||
|
dbpath := en.DataFolder()
|
||||||
|
cachePath := dbpath + "cache/"
|
||||||
|
dbfile := dbpath + "push.db"
|
||||||
|
defer order.DoneOnExit()()
|
||||||
|
_ = os.RemoveAll(en.DataFolder() + "cache")
|
||||||
|
err := os.MkdirAll(cachePath, 0755)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
bdb = initialize(dbfile)
|
||||||
|
log.Println("[bilibilipush]加载bilibilipush数据库")
|
||||||
|
}()
|
||||||
|
|
||||||
en.OnRegex(`^添加订阅\s?(\d+)$`, ctxext.UserOrGrpAdmin).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
en.OnRegex(`^添加订阅\s?(\d+)$`, ctxext.UserOrGrpAdmin).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||||
buid, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64)
|
buid, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64)
|
||||||
var name string
|
var name string
|
||||||
@ -202,7 +222,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln("[bilibilipush]:", err)
|
log.Errorln("[bilibilipush]:", err)
|
||||||
}
|
}
|
||||||
if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id.ID() == 0 {
|
if id := ctx.SendChain(message.Image("base64://" + binary.BytesToString(data))); id.ID() == 0 {
|
||||||
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
|
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -223,8 +243,8 @@ func checkBuid(buid int64) (status int, name string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln("[bilibilipush]:", err)
|
log.Errorln("[bilibilipush]:", err)
|
||||||
}
|
}
|
||||||
status = int(gjson.Get(helper.BytesToString(data), "code").Int())
|
status = int(gjson.Get(binary.BytesToString(data), "code").Int())
|
||||||
name = gjson.Get(helper.BytesToString(data), "data.name").String()
|
name = gjson.Get(binary.BytesToString(data), "data.name").String()
|
||||||
if status == 0 {
|
if status == 0 {
|
||||||
bdb.insertBilibiliUp(buid, name)
|
bdb.insertBilibiliUp(buid, name)
|
||||||
upMap[buid] = name
|
upMap[buid] = name
|
||||||
@ -281,7 +301,7 @@ func getUserDynamicCard(buid int64) (cardList []gjson.Result) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln("[bilibilipush]:", err)
|
log.Errorln("[bilibilipush]:", err)
|
||||||
}
|
}
|
||||||
cardList = gjson.Get(helper.BytesToString(data), "data.cards").Array()
|
cardList = gjson.Get(binary.BytesToString(data), "data.cards").Array()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +326,7 @@ func getLiveList(uids ...int64) string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln("[bilibilipush]:", err)
|
log.Errorln("[bilibilipush]:", err)
|
||||||
}
|
}
|
||||||
return helper.BytesToString(data)
|
return binary.BytesToString(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendDynamic() {
|
func sendDynamic() {
|
||||||
|
|||||||
@ -1,32 +0,0 @@
|
|||||||
package bilibilipush
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/process"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
cachePath = dbpath + "cache/"
|
|
||||||
dbpath = "data/bilibilipush/"
|
|
||||||
dbfile = dbpath + "push.db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// bdb bilibili推送数据库
|
|
||||||
var bdb *bilibilipushdb
|
|
||||||
|
|
||||||
// 加载数据库
|
|
||||||
func init() {
|
|
||||||
go func() {
|
|
||||||
defer order.DoneOnExit()()
|
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
_ = os.MkdirAll(dbpath, 0755)
|
|
||||||
os.RemoveAll(cachePath)
|
|
||||||
_ = os.MkdirAll(cachePath, 0755)
|
|
||||||
bdb = initialize(dbfile)
|
|
||||||
log.Println("[bilibilipush]加载bilibilipush数据库")
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
@ -5,20 +5,38 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
|
||||||
|
|
||||||
|
"github.com/FloatTech/zbputils/binary"
|
||||||
"github.com/FloatTech/zbputils/control"
|
"github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/img/text"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
|
"github.com/FloatTech/zbputils/file"
|
||||||
|
"github.com/FloatTech/zbputils/img/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
engine := control.Register("bookreview", order.AcquirePrio(), &control.Options{
|
engine := control.Register("bookreview", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "哀伤雪刃推书记录\n- 书评[xxx]\n- 随机书评",
|
Help: "哀伤雪刃推书记录\n- 书评[xxx]\n- 随机书评",
|
||||||
|
PublicDataFolder: "BookReview",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
dbpath := engine.DataFolder()
|
||||||
|
db.DBPath = dbpath + "bookreview.db"
|
||||||
|
defer order.DoneOnExit()()
|
||||||
|
// os.RemoveAll(dbpath)
|
||||||
|
_, _ = file.GetLazyData(db.DBPath, false, true)
|
||||||
|
err := db.Create("bookreview", &book{})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
n, err := db.Count("bookreview")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
log.Printf("[bookreview]读取%d条书评", n)
|
||||||
|
}()
|
||||||
|
|
||||||
// 中文、英文、数字但不包括下划线等符号
|
// 中文、英文、数字但不包括下划线等符号
|
||||||
engine.OnRegex("^书评([\u4E00-\u9FA5A-Za-z0-9]{1,25})$").SetBlock(true).
|
engine.OnRegex("^书评([\u4E00-\u9FA5A-Za-z0-9]{1,25})$").SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
@ -27,7 +45,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("err:", err)
|
log.Println("err:", err)
|
||||||
}
|
}
|
||||||
if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id.ID() == 0 {
|
if id := ctx.SendChain(message.Image("base64://" + binary.BytesToString(data))); id.ID() == 0 {
|
||||||
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
|
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -39,7 +57,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("err:", err)
|
log.Println("err:", err)
|
||||||
}
|
}
|
||||||
if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id.ID() == 0 {
|
if id := ctx.SendChain(message.Image("base64://" + binary.BytesToString(data))); id.ID() == 0 {
|
||||||
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
|
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,38 +0,0 @@
|
|||||||
package bookreview
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
sql "github.com/FloatTech/sqlite"
|
|
||||||
"github.com/FloatTech/zbputils/file"
|
|
||||||
"github.com/FloatTech/zbputils/process"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
|
||||||
)
|
|
||||||
|
|
||||||
const dbpath = "data/BookReview/"
|
|
||||||
const dbfile = dbpath + "bookreview.db"
|
|
||||||
|
|
||||||
var db = &sql.Sqlite{DBPath: dbfile}
|
|
||||||
|
|
||||||
// 加载数据库
|
|
||||||
func init() {
|
|
||||||
go func() {
|
|
||||||
defer order.DoneOnExit()()
|
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
// os.RemoveAll(dbpath)
|
|
||||||
_ = os.MkdirAll(dbpath, 0755)
|
|
||||||
_, _ = file.GetLazyData(dbfile, false, true)
|
|
||||||
err := db.Create("bookreview", &book{})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
n, err := db.Count("bookreview")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
log.Printf("[bookreview]读取%d条书评", n)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
@ -1,10 +1,14 @@
|
|||||||
package bookreview
|
package bookreview
|
||||||
|
|
||||||
|
import sql "github.com/FloatTech/sqlite"
|
||||||
|
|
||||||
type book struct {
|
type book struct {
|
||||||
ID uint64 `db:"id"`
|
ID uint64 `db:"id"`
|
||||||
BookReview string `db:"bookreview"`
|
BookReview string `db:"bookreview"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var db = &sql.Sqlite{}
|
||||||
|
|
||||||
// 暂时随机选择一个书评
|
// 暂时随机选择一个书评
|
||||||
func getBookReviewByKeyword(keyword string) (b book) {
|
func getBookReviewByKeyword(keyword string) (b book) {
|
||||||
_ = db.Find("bookreview", &b, "where bookreview LIKE '%"+keyword+"%'")
|
_ = db.Find("bookreview", &b, "where bookreview LIKE '%"+keyword+"%'")
|
||||||
|
|||||||
@ -2,18 +2,40 @@
|
|||||||
package chouxianghua
|
package chouxianghua
|
||||||
|
|
||||||
import (
|
import (
|
||||||
control "github.com/FloatTech/zbputils/control"
|
"github.com/sirupsen/logrus"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
|
"github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
|
"github.com/FloatTech/zbputils/file"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
control.Register("chouxianghua", order.AcquirePrio(), &control.Options{
|
en := control.Register("chouxianghua", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "抽象话\n- 抽象翻译xxx",
|
Help: "抽象话\n- 抽象翻译xxx",
|
||||||
}).OnRegex("^抽象翻译((\\s|[\\r\\n]|[\\p{Han}\\p{P}A-Za-z0-9])+)$").SetBlock(true).
|
PublicDataFolder: "ChouXiangHua",
|
||||||
|
})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
dbpath := en.DataFolder()
|
||||||
|
db.DBPath = dbpath + "cxh.db"
|
||||||
|
defer order.DoneOnExit()()
|
||||||
|
// 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).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
r := cx(ctx.State["regex_matched"].([]string)[1])
|
r := cx(ctx.State["regex_matched"].([]string)[1])
|
||||||
ctx.SendChain(message.Text(r))
|
ctx.SendChain(message.Text(r))
|
||||||
|
|||||||
@ -1,40 +0,0 @@
|
|||||||
package chouxianghua
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
sql "github.com/FloatTech/sqlite"
|
|
||||||
"github.com/FloatTech/zbputils/file"
|
|
||||||
"github.com/FloatTech/zbputils/process"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
dbpath = "data/ChouXiangHua/"
|
|
||||||
dbfile = dbpath + "cxh.db"
|
|
||||||
)
|
|
||||||
|
|
||||||
var db = &sql.Sqlite{DBPath: dbfile}
|
|
||||||
|
|
||||||
// 加载数据库
|
|
||||||
func init() {
|
|
||||||
go func() {
|
|
||||||
defer order.DoneOnExit()()
|
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
// os.RemoveAll(dbpath)
|
|
||||||
_ = os.MkdirAll(dbpath, 0755)
|
|
||||||
_, _ = file.GetLazyData(dbfile, false, true)
|
|
||||||
err := db.Create("pinyin", &pinyin{})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
n, err := db.Count("pinyin")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
log.Printf("[chouxianghua]读取%d条拼音", n)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
@ -1,5 +1,7 @@
|
|||||||
package chouxianghua
|
package chouxianghua
|
||||||
|
|
||||||
|
import sql "github.com/FloatTech/sqlite"
|
||||||
|
|
||||||
type pinyin struct {
|
type pinyin struct {
|
||||||
Word string `db:"word"`
|
Word string `db:"word"`
|
||||||
Pronun string `db:"pronunciation"`
|
Pronun string `db:"pronunciation"`
|
||||||
@ -9,6 +11,8 @@ type emoji struct {
|
|||||||
Emoji string `db:"emoji"`
|
Emoji string `db:"emoji"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var db = &sql.Sqlite{}
|
||||||
|
|
||||||
func getPinyinByWord(word string) string {
|
func getPinyinByWord(word string) string {
|
||||||
var p pinyin
|
var p pinyin
|
||||||
_ = db.Find("pinyin", &p, "where word = '"+word+"'")
|
_ = db.Find("pinyin", &p, "where word = '"+word+"'")
|
||||||
|
|||||||
@ -4,11 +4,13 @@ package cpstory
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
control "github.com/FloatTech/zbputils/control"
|
control "github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/ctxext"
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
|
"github.com/FloatTech/zbputils/file"
|
||||||
"github.com/FloatTech/zbputils/math"
|
"github.com/FloatTech/zbputils/math"
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
@ -18,7 +20,26 @@ func init() {
|
|||||||
engine := control.Register("cpstory", order.AcquirePrio(), &control.Options{
|
engine := control.Register("cpstory", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "cp短打\n- 组cp[@xxx][@xxx]\n- 磕cp大老师 雪乃",
|
Help: "cp短打\n- 组cp[@xxx][@xxx]\n- 磕cp大老师 雪乃",
|
||||||
|
PublicDataFolder: "CpStory",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
dbpath := engine.DataFolder()
|
||||||
|
db.DBPath = dbpath + "cp.db"
|
||||||
|
defer order.DoneOnExit()()
|
||||||
|
// os.RemoveAll(dbpath)
|
||||||
|
_, _ = file.GetLazyData(db.DBPath, false, true)
|
||||||
|
err := db.Create("cp_story", &cpstory{})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
n, err := db.Count("cp_story")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
logrus.Printf("[cpstory]读取%d条故事", n)
|
||||||
|
}()
|
||||||
|
|
||||||
engine.OnRegex("^组cp.*?(\\d+).*?(\\d+)", zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
engine.OnRegex("^组cp.*?(\\d+).*?(\\d+)", zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||||
cs := getRandomCpStory()
|
cs := getRandomCpStory()
|
||||||
gong := ctxext.CardOrNickName(ctx, math.Str2Int64(ctx.State["regex_matched"].([]string)[1]))
|
gong := ctxext.CardOrNickName(ctx, math.Str2Int64(ctx.State["regex_matched"].([]string)[1]))
|
||||||
|
|||||||
@ -1,40 +0,0 @@
|
|||||||
package cpstory
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
sql "github.com/FloatTech/sqlite"
|
|
||||||
"github.com/FloatTech/zbputils/file"
|
|
||||||
"github.com/FloatTech/zbputils/process"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
dbpath = "data/CpStory/"
|
|
||||||
dbfile = dbpath + "cp.db"
|
|
||||||
)
|
|
||||||
|
|
||||||
var db = &sql.Sqlite{DBPath: dbfile}
|
|
||||||
|
|
||||||
// 加载数据库
|
|
||||||
func init() {
|
|
||||||
go func() {
|
|
||||||
defer order.DoneOnExit()()
|
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
// os.RemoveAll(dbpath)
|
|
||||||
_ = os.MkdirAll(dbpath, 0755)
|
|
||||||
_, _ = file.GetLazyData(dbfile, false, true)
|
|
||||||
err := db.Create("cp_story", &cpstory{})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
n, err := db.Count("cp_story")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
log.Printf("[cpstory]读取%d条故事", n)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
@ -1,5 +1,7 @@
|
|||||||
package cpstory
|
package cpstory
|
||||||
|
|
||||||
|
import sql "github.com/FloatTech/sqlite"
|
||||||
|
|
||||||
type cpstory struct {
|
type cpstory struct {
|
||||||
ID int64 `db:"id"`
|
ID int64 `db:"id"`
|
||||||
Gong string `db:"gong"`
|
Gong string `db:"gong"`
|
||||||
@ -7,6 +9,8 @@ type cpstory struct {
|
|||||||
Story string `db:"story"`
|
Story string `db:"story"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var db = &sql.Sqlite{}
|
||||||
|
|
||||||
func getRandomCpStory() (cs cpstory) {
|
func getRandomCpStory() (cs cpstory) {
|
||||||
_ = db.Pick("cp_story", &cs)
|
_ = db.Pick("cp_story", &cs)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -2,11 +2,13 @@
|
|||||||
package curse
|
package curse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
control "github.com/FloatTech/zbputils/control"
|
control "github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/ctxext"
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
|
"github.com/FloatTech/zbputils/file"
|
||||||
"github.com/FloatTech/zbputils/process"
|
"github.com/FloatTech/zbputils/process"
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
@ -21,8 +23,25 @@ func init() {
|
|||||||
engine := control.Register("curse", order.AcquirePrio(), &control.Options{
|
engine := control.Register("curse", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: true,
|
DisableOnDefault: true,
|
||||||
Help: "骂人(求骂,自卫)\n- 骂我\n- 大力骂我",
|
Help: "骂人(求骂,自卫)\n- 骂我\n- 大力骂我",
|
||||||
|
PublicDataFolder: "Curse",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
dbpath := engine.DataFolder()
|
||||||
|
db.DBPath = dbpath + "curse.db"
|
||||||
|
defer order.DoneOnExit()()
|
||||||
|
_, err := file.GetLazyData(db.DBPath, false, true)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
err = db.Create("curse", &curse{})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
c, _ := db.Count("curse")
|
||||||
|
logrus.Infoln("[curse]加载", c, "条骂人语录")
|
||||||
|
}()
|
||||||
|
|
||||||
engine.OnFullMatch("骂我").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
engine.OnFullMatch("骂我").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||||
process.SleepAbout1sTo2s()
|
process.SleepAbout1sTo2s()
|
||||||
text := getRandomCurseByLevel(minLevel).Text
|
text := getRandomCurseByLevel(minLevel).Text
|
||||||
|
|||||||
@ -1,41 +0,0 @@
|
|||||||
package curse
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
sql "github.com/FloatTech/sqlite"
|
|
||||||
"github.com/FloatTech/zbputils/file"
|
|
||||||
"github.com/FloatTech/zbputils/process"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
dbpath = "data/Curse/"
|
|
||||||
dbfile = dbpath + "curse.db"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
db = &sql.Sqlite{DBPath: dbfile}
|
|
||||||
)
|
|
||||||
|
|
||||||
// 加载数据库
|
|
||||||
func init() {
|
|
||||||
go func() {
|
|
||||||
defer order.DoneOnExit()()
|
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
_ = os.MkdirAll(dbpath, 0755)
|
|
||||||
_, err := file.GetLazyData(dbfile, false, true)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
err = db.Create("curse", &curse{})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
c, _ := db.Count("curse")
|
|
||||||
logrus.Infoln("[curse]加载", c, "条骂人语录")
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
@ -1,11 +1,15 @@
|
|||||||
package curse
|
package curse
|
||||||
|
|
||||||
|
import sql "github.com/FloatTech/sqlite"
|
||||||
|
|
||||||
type curse struct {
|
type curse struct {
|
||||||
ID uint32 `db:"id"`
|
ID uint32 `db:"id"`
|
||||||
Text string `db:"text"`
|
Text string `db:"text"`
|
||||||
Level string `db:"level"`
|
Level string `db:"level"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var db = &sql.Sqlite{}
|
||||||
|
|
||||||
func getRandomCurseByLevel(level string) (c curse) {
|
func getRandomCurseByLevel(level string) (c curse) {
|
||||||
_ = db.Find("curse", &c, "where level = '"+level+"' ORDER BY RANDOM() limit 1")
|
_ = db.Find("curse", &c, "where level = '"+level+"' ORDER BY RANDOM() limit 1")
|
||||||
return
|
return
|
||||||
|
|||||||
@ -4,7 +4,6 @@ package deepdanbooru
|
|||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/FloatTech/AnimeAPI/danbooru"
|
"github.com/FloatTech/AnimeAPI/danbooru"
|
||||||
"github.com/FloatTech/AnimeAPI/saucenao"
|
"github.com/FloatTech/AnimeAPI/saucenao"
|
||||||
@ -19,19 +18,16 @@ import (
|
|||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
)
|
)
|
||||||
|
|
||||||
const cachefile = "data/danbooru/"
|
|
||||||
|
|
||||||
func init() { // 插件主体
|
func init() { // 插件主体
|
||||||
_ = os.RemoveAll(cachefile)
|
|
||||||
err := os.MkdirAll(cachefile, 0755)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
engine := control.Register("danbooru", order.AcquirePrio(), &control.Options{
|
engine := control.Register("danbooru", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "二次元图片标签识别\n" +
|
Help: "二次元图片标签识别\n" +
|
||||||
"- 鉴赏图片[图片]",
|
"- 鉴赏图片[图片]",
|
||||||
|
PrivateDataFolder: "danbooru",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
cachefolder := engine.DataFolder()
|
||||||
|
|
||||||
// 上传一张图进行评价
|
// 上传一张图进行评价
|
||||||
engine.OnKeywordGroup([]string{"鉴赏图片"}, zero.OnlyGroup, ctxext.MustProvidePicture).SetBlock(true).
|
engine.OnKeywordGroup([]string{"鉴赏图片"}, zero.OnlyGroup, ctxext.MustProvidePicture).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
@ -50,7 +46,7 @@ func init() { // 插件主体
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
digest := md5.Sum(helper.StringToBytes(url))
|
digest := md5.Sum(helper.StringToBytes(url))
|
||||||
f := cachefile + hex.EncodeToString(digest[:])
|
f := cachefolder + hex.EncodeToString(digest[:])
|
||||||
if file.IsNotExist(f) {
|
if file.IsNotExist(f) {
|
||||||
_ = writer.SavePNG2Path(f, t)
|
_ = writer.SavePNG2Path(f, t)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,9 +22,17 @@ var engine = control.Register("diana", order.AcquirePrio(), &control.Options{
|
|||||||
"- 发大病\n" +
|
"- 发大病\n" +
|
||||||
"- 教你一篇小作文[作文]\n" +
|
"- 教你一篇小作文[作文]\n" +
|
||||||
"- [回复]查重",
|
"- [回复]查重",
|
||||||
|
PublicDataFolder: "Diana",
|
||||||
})
|
})
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
go func() {
|
||||||
|
datapath := engine.DataFolder()
|
||||||
|
dbfile := datapath + "text.db"
|
||||||
|
defer order.DoneOnExit()()
|
||||||
|
data.LoadText(dbfile)
|
||||||
|
}()
|
||||||
|
|
||||||
// 随机发送一篇上面的小作文
|
// 随机发送一篇上面的小作文
|
||||||
engine.OnFullMatch("小作文").SetBlock(true).
|
engine.OnFullMatch("小作文").SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
|
|||||||
@ -4,61 +4,38 @@ package data
|
|||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"os"
|
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
|
||||||
|
|
||||||
sql "github.com/FloatTech/sqlite"
|
sql "github.com/FloatTech/sqlite"
|
||||||
|
binutils "github.com/FloatTech/zbputils/binary"
|
||||||
"github.com/FloatTech/zbputils/file"
|
"github.com/FloatTech/zbputils/file"
|
||||||
"github.com/FloatTech/zbputils/process"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
var db = sql.Sqlite{}
|
||||||
datapath = "data/Diana"
|
|
||||||
dbfile = datapath + "/text.db"
|
|
||||||
)
|
|
||||||
|
|
||||||
var db = sql.Sqlite{DBPath: dbfile}
|
|
||||||
|
|
||||||
type text struct {
|
type text struct {
|
||||||
ID int64 `db:"id"`
|
ID int64 `db:"id"`
|
||||||
Data string `db:"data"`
|
Data string `db:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
go func() {
|
|
||||||
defer order.DoneOnExit()()
|
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
err := os.MkdirAll(datapath, 0755)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
err = LoadText()
|
|
||||||
if err == nil {
|
|
||||||
err = db.Create("text", &text{})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
c, _ := db.Count("text")
|
|
||||||
log.Printf("[Diana]读取%d条小作文", c)
|
|
||||||
} else {
|
|
||||||
log.Printf("[Diana]读取小作文错误:%v", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
// LoadText 加载小作文
|
// LoadText 加载小作文
|
||||||
func LoadText() error {
|
func LoadText(dbfile string) {
|
||||||
_, err := file.GetLazyData(dbfile, false, false)
|
_, err := file.GetLazyData(dbfile, false, false)
|
||||||
return err
|
db.DBPath = dbfile
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
err = db.Create("text", &text{})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
c, _ := db.Count("text")
|
||||||
|
logrus.Printf("[Diana]读取%d条小作文", c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddText 添加小作文
|
// AddText 添加小作文
|
||||||
func AddText(txt string) error {
|
func AddText(txt string) error {
|
||||||
s := md5.Sum(helper.StringToBytes(txt))
|
s := md5.Sum(binutils.StringToBytes(txt))
|
||||||
i := binary.LittleEndian.Uint64(s[:8])
|
i := binary.LittleEndian.Uint64(s[:8])
|
||||||
return db.Insert("text", &text{ID: int64(i), Data: txt})
|
return db.Insert("text", &text{ID: int64(i), Data: txt})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,7 @@ type bottle struct {
|
|||||||
Msg string `db:"msg"` // Msg 消息,纯文本
|
Msg string `db:"msg"` // Msg 消息,纯文本
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sea = &sql.Sqlite{}
|
||||||
var seamu sync.RWMutex
|
var seamu sync.RWMutex
|
||||||
|
|
||||||
func newBottle(qq, grp int64, name, msg string) *bottle {
|
func newBottle(qq, grp int64, name, msg string) *bottle {
|
||||||
|
|||||||
@ -1,23 +0,0 @@
|
|||||||
package driftbottle
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
sql "github.com/FloatTech/sqlite"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
dbpath = "data/driftbottle/"
|
|
||||||
dbfile = dbpath + "sea.db"
|
|
||||||
)
|
|
||||||
|
|
||||||
var sea = &sql.Sqlite{DBPath: dbfile}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
_ = os.MkdirAll(dbpath, 0755)
|
|
||||||
err := sea.Open()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
_ = createChannel(sea, "global")
|
|
||||||
}
|
|
||||||
@ -16,9 +16,16 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
en := control.Register("driftbottle", order.AcquirePrio(), &control.Options{
|
en := control.Register("driftbottle", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "漂流瓶\n- (在群xxx)丢漂流瓶(到频道xxx) [消息]\n- (从频道xxx)捡漂流瓶\n- @BOT 创建频道 xxx\n- 跳入(频道)海中\n- 注:不显式限制时,私聊发送可在所有群抽到,群聊发送仅可在本群抽到,默认频道为 global",
|
Help: "漂流瓶\n- (在群xxx)丢漂流瓶(到频道xxx) [消息]\n- (从频道xxx)捡漂流瓶\n- @BOT 创建频道 xxx\n- 跳入(频道)海中\n- 注:不显式限制时,私聊发送可在所有群抽到,群聊发送仅可在本群抽到,默认频道为 global",
|
||||||
|
PrivateDataFolder: "driftbottle",
|
||||||
})
|
})
|
||||||
|
sea.DBPath = en.DataFolder() + "sea.db"
|
||||||
|
err := sea.Open()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
_ = createChannel(sea, "global")
|
||||||
en.OnRegex(`^(在群\d+)?丢漂流瓶(到频道\w+)?\s+(.*)$`).SetBlock(true).
|
en.OnRegex(`^(在群\d+)?丢漂流瓶(到频道\w+)?\s+(.*)$`).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
msgs := ctx.State["regex_matched"].([]string)
|
msgs := ctx.State["regex_matched"].([]string)
|
||||||
|
|||||||
@ -41,8 +41,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// 底图类型列表:车万 DC4 爱因斯坦 星空列车 樱云之恋 富婆妹 李清歌
|
// 底图类型列表
|
||||||
// 公主连结 原神 明日方舟 碧蓝航线 碧蓝幻想 战双 阴阳师 赛马娘
|
|
||||||
table = [...]string{"车万", "DC4", "爱因斯坦", "星空列车", "樱云之恋", "富婆妹", "李清歌", "公主连结", "原神", "明日方舟", "碧蓝航线", "碧蓝幻想", "战双", "阴阳师", "赛马娘"}
|
table = [...]string{"车万", "DC4", "爱因斯坦", "星空列车", "樱云之恋", "富婆妹", "李清歌", "公主连结", "原神", "明日方舟", "碧蓝航线", "碧蓝幻想", "战双", "阴阳师", "赛马娘"}
|
||||||
// 映射底图与 index
|
// 映射底图与 index
|
||||||
index = make(map[string]uint8)
|
index = make(map[string]uint8)
|
||||||
@ -51,37 +50,37 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
for i, s := range table {
|
|
||||||
index[s] = uint8(i)
|
|
||||||
}
|
|
||||||
err := os.MkdirAll(images, 0755)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
_ = os.RemoveAll(cache)
|
|
||||||
err = os.MkdirAll(cache, 0755)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
data, err := file.GetLazyData(omikujson, true, false)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(data, &omikujis)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
_, err = file.GetLazyData(font, false, true)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
// 插件主体
|
// 插件主体
|
||||||
en := control.Register("fortune", order.AcquirePrio(), &control.Options{
|
en := control.Register("fortune", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "每日运势: \n" +
|
Help: "每日运势: \n" +
|
||||||
"- 运势 | 抽签\n" +
|
"- 运势 | 抽签\n" +
|
||||||
"- 设置底图[车万 | DC4 | 爱因斯坦 | 星空列车 | 樱云之恋 | 富婆妹 | 李清歌 | 公主连结 | 原神 | 明日方舟 | 碧蓝航线 | 碧蓝幻想 | 战双 | 阴阳师 | 赛马娘]",
|
"- 设置底图[车万 | DC4 | 爱因斯坦 | 星空列车 | 樱云之恋 | 富婆妹 | 李清歌 | 公主连结 | 原神 | 明日方舟 | 碧蓝航线 | 碧蓝幻想 | 战双 | 阴阳师 | 赛马娘]",
|
||||||
|
PublicDataFolder: "Fortune",
|
||||||
})
|
})
|
||||||
|
go func() {
|
||||||
|
defer order.DoneOnExit()()
|
||||||
|
for i, s := range table {
|
||||||
|
index[s] = uint8(i)
|
||||||
|
}
|
||||||
|
_ = os.RemoveAll(cache)
|
||||||
|
err := os.MkdirAll(cache, 0755)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
data, err := file.GetLazyData(omikujson, true, false)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(data, &omikujis)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
_, err = file.GetLazyData(font, false, true)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
en.OnRegex(`^设置底图\s?(.*)`).SetBlock(true).
|
en.OnRegex(`^设置底图\s?(.*)`).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
gid := ctx.Event.GroupID
|
gid := ctx.Event.GroupID
|
||||||
@ -93,7 +92,7 @@ func init() {
|
|||||||
if ok {
|
if ok {
|
||||||
c, ok := control.Lookup("fortune")
|
c, ok := control.Lookup("fortune")
|
||||||
if ok {
|
if ok {
|
||||||
err = c.SetData(gid, int64(i)&0xff)
|
err := c.SetData(gid, int64(i)&0xff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("设置失败:", err))
|
ctx.SendChain(message.Text("设置失败:", err))
|
||||||
return
|
return
|
||||||
@ -125,7 +124,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
// 检查背景图片是否存在
|
// 检查背景图片是否存在
|
||||||
zipfile := images + kind + ".zip"
|
zipfile := images + kind + ".zip"
|
||||||
_, err = file.GetLazyData(zipfile, false, false)
|
_, err := file.GetLazyData(zipfile, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("ERROR: ", err))
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
return
|
return
|
||||||
|
|||||||
@ -1,41 +0,0 @@
|
|||||||
package funny
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/file"
|
|
||||||
"github.com/FloatTech/zbputils/process"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
|
||||||
)
|
|
||||||
|
|
||||||
type joke struct {
|
|
||||||
ID uint32 `db:"id"`
|
|
||||||
Text string `db:"text"`
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
dbpath = "data/Funny/"
|
|
||||||
dbfile = dbpath + "jokes.db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 加载数据库
|
|
||||||
func init() {
|
|
||||||
go func() {
|
|
||||||
defer order.DoneOnExit()()
|
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
_ = os.MkdirAll(dbpath, 0755)
|
|
||||||
_, err := file.GetLazyData(dbfile, false, true)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
err = db.Create("jokes", &joke{})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
c, _ := db.Count("jokes")
|
|
||||||
logrus.Infoln("[funny]加载", c, "个笑话")
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
package funny
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/md5"
|
|
||||||
"encoding/binary"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
sql "github.com/FloatTech/sqlite"
|
|
||||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestFillData(t *testing.T) {
|
|
||||||
data, err := os.ReadFile("laugh.txt")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
db := &sql.Sqlite{DBPath: "jokes.db"}
|
|
||||||
err = db.Create("jokes", &joke{})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
jokes := strings.Split(helper.BytesToString(data), "\n")
|
|
||||||
for _, j := range jokes {
|
|
||||||
s := md5.Sum(helper.StringToBytes(j))
|
|
||||||
db.Insert("jokes", &joke{ID: binary.LittleEndian.Uint32(s[:4]), Text: j})
|
|
||||||
}
|
|
||||||
err = db.Close()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -4,24 +4,50 @@ package funny
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
sql "github.com/FloatTech/sqlite"
|
sql "github.com/FloatTech/sqlite"
|
||||||
control "github.com/FloatTech/zbputils/control"
|
control "github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/ctxext"
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
|
"github.com/FloatTech/zbputils/file"
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
)
|
)
|
||||||
|
|
||||||
var db = &sql.Sqlite{DBPath: dbfile}
|
type joke struct {
|
||||||
|
ID uint32 `db:"id"`
|
||||||
|
Text string `db:"text"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var db = &sql.Sqlite{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
control.Register("funny", order.AcquirePrio(), &control.Options{
|
en := control.Register("funny", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "讲个笑话\n" +
|
Help: "讲个笑话\n" +
|
||||||
"- 讲个笑话[@xxx] | 讲个笑话[qq号]",
|
"- 讲个笑话[@xxx] | 讲个笑话[qq号]",
|
||||||
}).OnPrefix("讲个笑话").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
PublicDataFolder: "Funny",
|
||||||
|
})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
dbpath := en.DataFolder()
|
||||||
|
db.DBPath = dbpath + "jokes.db"
|
||||||
|
defer order.DoneOnExit()()
|
||||||
|
_, err := file.GetLazyData(db.DBPath, false, true)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
err = db.Create("jokes", &joke{})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
c, _ := db.Count("jokes")
|
||||||
|
logrus.Infoln("[funny]加载", c, "个笑话")
|
||||||
|
}()
|
||||||
|
|
||||||
|
en.OnPrefix("讲个笑话").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||||
// 获取名字
|
// 获取名字
|
||||||
name := ctxext.NickName(ctx)
|
name := ctxext.NickName(ctx)
|
||||||
var j joke
|
var j joke
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package gif
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -11,6 +10,7 @@ import (
|
|||||||
|
|
||||||
control "github.com/FloatTech/zbputils/control"
|
control "github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/ctxext"
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
|
"github.com/FloatTech/zbputils/file"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
@ -20,17 +20,18 @@ import (
|
|||||||
var (
|
var (
|
||||||
cmds = []string{"搓", "冲", "摸", "拍", "丢", "吃", "敲", "啃", "蹭", "爬", "撕",
|
cmds = []string{"搓", "冲", "摸", "拍", "丢", "吃", "敲", "啃", "蹭", "爬", "撕",
|
||||||
"灰度", "上翻", "下翻", "左翻", "右翻", "反色", "浮雕", "打码", "负片"}
|
"灰度", "上翻", "下翻", "左翻", "右翻", "反色", "浮雕", "打码", "负片"}
|
||||||
botpath, _ = os.Getwd()
|
datapath string
|
||||||
datapath = botpath + "/data/gif/"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { // 插件主体
|
func init() { // 插件主体
|
||||||
_ = os.MkdirAll(datapath, 0755)
|
|
||||||
rand.Seed(time.Now().UnixNano()) // 设置种子
|
rand.Seed(time.Now().UnixNano()) // 设置种子
|
||||||
control.Register("gif", order.AcquirePrio(), &control.Options{
|
en := control.Register("gif", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "制图\n- " + strings.Join(cmds, "\n- "),
|
Help: "制图\n- " + strings.Join(cmds, "\n- "),
|
||||||
}).ApplySingle(ctxext.DefaultSingle).OnRegex(`^(` + strings.Join(cmds, "|") + `)\D*?(\[CQ:(image\,file=([0-9a-zA-Z]{32}).*|at.+?(\d{5,11}))\].*|(\d+))$`).
|
PrivateDataFolder: "gif",
|
||||||
|
}).ApplySingle(ctxext.DefaultSingle)
|
||||||
|
datapath = file.BOTPATH + "/" + en.DataFolder()
|
||||||
|
en.OnRegex(`^(` + strings.Join(cmds, "|") + `)\D*?(\[CQ:(image\,file=([0-9a-zA-Z]{32}).*|at.+?(\d{5,11}))\].*|(\d+))$`).
|
||||||
SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||||
c := newContext(ctx.Event.UserID)
|
c := newContext(ctx.Event.UserID)
|
||||||
list := ctx.State["regex_matched"].([]string)
|
list := ctx.State["regex_matched"].([]string)
|
||||||
|
|||||||
@ -20,11 +20,8 @@ import (
|
|||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var reqconf = [...]string{"GET", "https://hs.fbigame.com",
|
||||||
cachedir = file.BOTPATH + "/data/hs/"
|
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Mobile Safari/537.36"}
|
||||||
reqconf = [...]string{"GET", "https://hs.fbigame.com",
|
|
||||||
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Mobile Safari/537.36"}
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
hs = `https://hs.fbigame.com/ajax.php?`
|
hs = `https://hs.fbigame.com/ajax.php?`
|
||||||
@ -46,19 +43,15 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
os.RemoveAll(cachedir)
|
|
||||||
err := os.MkdirAll(cachedir, 0755)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
engine := control.Register("hs", order.AcquirePrio(), &control.Options{
|
engine := control.Register("hs", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "炉石\n" +
|
Help: "炉石\n" +
|
||||||
"- 搜卡[xxxx]\n" +
|
"- 搜卡[xxxx]\n" +
|
||||||
"- [卡组代码xxx]\n" +
|
"- [卡组代码xxx]\n" +
|
||||||
"- 更多搜卡指令参数:https://hs.fbigame.com/misc/searchhelp",
|
"- 更多搜卡指令参数:https://hs.fbigame.com/misc/searchhelp",
|
||||||
|
PrivateDataFolder: "hs",
|
||||||
}).ApplySingle(ctxext.DefaultSingle)
|
}).ApplySingle(ctxext.DefaultSingle)
|
||||||
|
cachedir := file.BOTPATH + "/" + engine.DataFolder()
|
||||||
engine.OnRegex(`^搜卡(.+)$`).
|
engine.OnRegex(`^搜卡(.+)$`).
|
||||||
SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||||
List := ctx.State["regex_matched"].([]string)[1]
|
List := ctx.State["regex_matched"].([]string)[1]
|
||||||
|
|||||||
@ -1,21 +1,12 @@
|
|||||||
package jandan
|
package jandan
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
sql "github.com/FloatTech/sqlite"
|
sql "github.com/FloatTech/sqlite"
|
||||||
"github.com/FloatTech/zbputils/file"
|
|
||||||
"github.com/FloatTech/zbputils/process"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const dbpath = "data/Jandan/"
|
var db = &sql.Sqlite{}
|
||||||
const dbfile = dbpath + "pics.db"
|
|
||||||
|
|
||||||
var db = &sql.Sqlite{DBPath: dbfile}
|
|
||||||
var mu sync.RWMutex
|
var mu sync.RWMutex
|
||||||
|
|
||||||
type picture struct {
|
type picture struct {
|
||||||
@ -31,22 +22,3 @@ func getRandomPicture() (u string, err error) {
|
|||||||
u = p.URL
|
u = p.URL
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载数据库
|
|
||||||
func init() {
|
|
||||||
go func() {
|
|
||||||
defer order.DoneOnExit()()
|
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
_ = os.MkdirAll(dbpath, 0755)
|
|
||||||
_, _ = file.GetLazyData(dbfile, false, false)
|
|
||||||
err := db.Create("picture", &picture{})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
n, err := db.Count("picture")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
log.Printf("[jandan]读取%d张图片", n)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/FloatTech/zbputils/binary"
|
"github.com/FloatTech/zbputils/binary"
|
||||||
"github.com/FloatTech/zbputils/control"
|
"github.com/FloatTech/zbputils/control"
|
||||||
|
"github.com/FloatTech/zbputils/file"
|
||||||
"github.com/antchfx/htmlquery"
|
"github.com/antchfx/htmlquery"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
@ -25,8 +26,25 @@ func init() {
|
|||||||
engine := control.Register("jandan", order.AcquirePrio(), &control.Options{
|
engine := control.Register("jandan", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "煎蛋网无聊图\n- 来份屌图\n- 更新屌图\n",
|
Help: "煎蛋网无聊图\n- 来份屌图\n- 更新屌图\n",
|
||||||
|
PublicDataFolder: "Jandan",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
dbpath := engine.DataFolder()
|
||||||
|
db.DBPath = dbpath + "pics.db"
|
||||||
|
defer order.DoneOnExit()()
|
||||||
|
_, _ = file.GetLazyData(db.DBPath, false, false)
|
||||||
|
err := db.Create("picture", &picture{})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
n, err := db.Count("picture")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
logrus.Printf("[jandan]读取%d张图片", n)
|
||||||
|
}()
|
||||||
|
|
||||||
engine.OnFullMatch("来份屌图").SetBlock(true).
|
engine.OnFullMatch("来份屌图").SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
u, err := getRandomPicture()
|
u, err := getRandomPicture()
|
||||||
|
|||||||
@ -4,7 +4,6 @@ package manager
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -26,9 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
datapath = "data/manager/"
|
hint = "====群管====\n" +
|
||||||
confile = datapath + "config.db"
|
|
||||||
hint = "====群管====\n" +
|
|
||||||
"- 禁言@QQ 1分钟\n" +
|
"- 禁言@QQ 1分钟\n" +
|
||||||
"- 解除禁言 @QQ\n" +
|
"- 解除禁言 @QQ\n" +
|
||||||
"- 我要自闭 1分钟\n" +
|
"- 我要自闭 1分钟\n" +
|
||||||
@ -56,20 +53,20 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
db = &sql.Sqlite{DBPath: confile}
|
db = &sql.Sqlite{}
|
||||||
clock timer.Clock
|
clock timer.Clock
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { // 插件主体
|
func init() { // 插件主体
|
||||||
engine := control.Register("manager", order.AcquirePrio(), &control.Options{
|
engine := control.Register("manager", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: hint,
|
Help: hint,
|
||||||
|
PrivateDataFolder: "manager",
|
||||||
})
|
})
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer order.DoneOnExit()()
|
defer order.DoneOnExit()()
|
||||||
process.SleepAbout1sTo2s()
|
db.DBPath = engine.DataFolder() + "config.db"
|
||||||
_ = os.MkdirAll(datapath, 0755)
|
|
||||||
clock = timer.NewClock(db)
|
clock = timer.NewClock(db)
|
||||||
err := db.Create("welcome", &welcome{})
|
err := db.Create("welcome", &welcome{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -10,14 +10,10 @@ import (
|
|||||||
|
|
||||||
"github.com/corona10/goimagehash"
|
"github.com/corona10/goimagehash"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
|
||||||
_ "golang.org/x/image/webp" // import webp decoding
|
_ "golang.org/x/image/webp" // import webp decoding
|
||||||
|
|
||||||
sql "github.com/FloatTech/sqlite"
|
sql "github.com/FloatTech/sqlite"
|
||||||
"github.com/FloatTech/zbputils/file"
|
"github.com/FloatTech/zbputils/file"
|
||||||
"github.com/FloatTech/zbputils/process"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// setuclass holds setus in a folder, which is the class name.
|
// setuclass holds setus in a folder, which is the class name.
|
||||||
@ -27,25 +23,7 @@ type setuclass struct {
|
|||||||
Path string `db:"path"` // Path 图片路径
|
Path string `db:"path"` // Path 图片路径
|
||||||
}
|
}
|
||||||
|
|
||||||
var ns = &nsetu{db: &sql.Sqlite{DBPath: dbfile}}
|
var ns = &nsetu{db: &sql.Sqlite{}}
|
||||||
|
|
||||||
func init() {
|
|
||||||
go func() {
|
|
||||||
defer order.DoneOnExit()()
|
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
err := os.MkdirAll(datapath, 0755)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if file.IsExist(cfgfile) {
|
|
||||||
b, err := os.ReadFile(cfgfile)
|
|
||||||
if err == nil {
|
|
||||||
setupath = helper.BytesToString(b)
|
|
||||||
logrus.Println("[nsetu] set setu dir to", setupath)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
type nsetu struct {
|
type nsetu struct {
|
||||||
db *sql.Sqlite
|
db *sql.Sqlite
|
||||||
|
|||||||
@ -12,16 +12,11 @@ import (
|
|||||||
|
|
||||||
"github.com/FloatTech/zbputils/control"
|
"github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/ctxext"
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
|
"github.com/FloatTech/zbputils/file"
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
datapath = "data/nsetu"
|
|
||||||
dbfile = datapath + "/data.db"
|
|
||||||
cfgfile = datapath + "/setupath.txt"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
setupath = "/tmp" // 绝对路径,图片根目录
|
setupath = "/tmp" // 绝对路径,图片根目录
|
||||||
)
|
)
|
||||||
@ -35,7 +30,19 @@ func init() {
|
|||||||
"- 设置本地setu绝对路径[xxx]\n" +
|
"- 设置本地setu绝对路径[xxx]\n" +
|
||||||
"- 刷新所有本地setu\n" +
|
"- 刷新所有本地setu\n" +
|
||||||
"- 所有本地setu分类",
|
"- 所有本地setu分类",
|
||||||
|
PrivateDataFolder: "nsetu",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ns.db.DBPath = engine.DataFolder() + "data.db"
|
||||||
|
cfgfile := engine.DataFolder() + "setupath.txt"
|
||||||
|
if file.IsExist(cfgfile) {
|
||||||
|
b, err := os.ReadFile(cfgfile)
|
||||||
|
if err == nil {
|
||||||
|
setupath = helper.BytesToString(b)
|
||||||
|
logrus.Println("[nsetu] set setu dir to", setupath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
engine.OnRegex(`^本地(.*)$`, ctxext.FirstValueInList(ns)).SetBlock(true).
|
engine.OnRegex(`^本地(.*)$`, ctxext.FirstValueInList(ns)).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
imgtype := ctx.State["regex_matched"].([]string)[1]
|
imgtype := ctx.State["regex_matched"].([]string)[1]
|
||||||
|
|||||||
@ -23,19 +23,14 @@ import (
|
|||||||
"github.com/FloatTech/zbputils/file"
|
"github.com/FloatTech/zbputils/file"
|
||||||
)
|
)
|
||||||
|
|
||||||
const base = "data/nwife"
|
|
||||||
|
|
||||||
var baseuri = "file:///" + file.BOTPATH + "/" + base
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
err := os.MkdirAll(base, 0755)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
engine := control.Register("nwife", order.AcquirePrio(), &control.Options{
|
engine := control.Register("nwife", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "nativewife\n- 抽wife[@xxx]\n- 添加wife[名字][图片]\n- 删除wife[名字]\n- [让 | 不让]所有人均可添加wife",
|
Help: "nativewife\n- 抽wife[@xxx]\n- 添加wife[名字][图片]\n- 删除wife[名字]\n- [让 | 不让]所有人均可添加wife",
|
||||||
|
PrivateDataFolder: "nwife",
|
||||||
})
|
})
|
||||||
|
base := engine.DataFolder()
|
||||||
|
baseuri := "file:///" + file.BOTPATH + "/" + base
|
||||||
engine.OnPrefix("抽wife", zero.OnlyGroup).SetBlock(true).
|
engine.OnPrefix("抽wife", zero.OnlyGroup).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
grpf := strconv.FormatInt(ctx.Event.GroupID, 36)
|
grpf := strconv.FormatInt(ctx.Event.GroupID, 36)
|
||||||
@ -78,13 +73,13 @@ func init() {
|
|||||||
url := ctx.State["image_url"].([]string)[0]
|
url := ctx.State["image_url"].([]string)[0]
|
||||||
grpfolder := base + "/" + strconv.FormatInt(ctx.Event.GroupID, 36)
|
grpfolder := base + "/" + strconv.FormatInt(ctx.Event.GroupID, 36)
|
||||||
if file.IsNotExist(grpfolder) {
|
if file.IsNotExist(grpfolder) {
|
||||||
err = os.Mkdir(grpfolder, 0755)
|
err := os.Mkdir(grpfolder, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("错误:", err.Error()))
|
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("错误:", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = file.DownloadTo(url, grpfolder+"/"+name, true)
|
err := file.DownloadTo(url, grpfolder+"/"+name, true)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("成功!"))
|
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("成功!"))
|
||||||
} else {
|
} else {
|
||||||
@ -108,7 +103,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
if name != "" {
|
if name != "" {
|
||||||
grpfolder := base + "/" + strconv.FormatInt(ctx.Event.GroupID, 36)
|
grpfolder := base + "/" + strconv.FormatInt(ctx.Event.GroupID, 36)
|
||||||
err = os.Remove(grpfolder + "/" + name)
|
err := os.Remove(grpfolder + "/" + name)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("成功!"))
|
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("成功!"))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,38 +0,0 @@
|
|||||||
package omikuji
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
sql "github.com/FloatTech/sqlite"
|
|
||||||
"github.com/FloatTech/zbputils/file"
|
|
||||||
"github.com/FloatTech/zbputils/process"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
dbpath = "data/Omikuji/"
|
|
||||||
dbfile = dbpath + "kuji.db"
|
|
||||||
)
|
|
||||||
|
|
||||||
var db = &sql.Sqlite{DBPath: dbfile}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
go func() {
|
|
||||||
defer order.DoneOnExit()()
|
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
_ = os.MkdirAll(dbpath, 0755)
|
|
||||||
_, _ = file.GetLazyData(dbfile, 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)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
@ -1,12 +1,18 @@
|
|||||||
package omikuji
|
package omikuji
|
||||||
|
|
||||||
import "strconv"
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
sql "github.com/FloatTech/sqlite"
|
||||||
|
)
|
||||||
|
|
||||||
type kuji struct {
|
type kuji struct {
|
||||||
ID uint8 `db:"id"`
|
ID uint8 `db:"id"`
|
||||||
Text string `db:"text"`
|
Text string `db:"text"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var db = &sql.Sqlite{}
|
||||||
|
|
||||||
// 返回一个解签
|
// 返回一个解签
|
||||||
func getKujiByBango(id uint8) string {
|
func getKujiByBango(id uint8) string {
|
||||||
var s kuji
|
var s kuji
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
control "github.com/FloatTech/zbputils/control"
|
control "github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/ctxext"
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
|
"github.com/FloatTech/zbputils/file"
|
||||||
"github.com/FloatTech/zbputils/img/text"
|
"github.com/FloatTech/zbputils/img/text"
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
@ -26,7 +27,25 @@ func init() { // 插件主体
|
|||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "浅草寺求签\n" +
|
Help: "浅草寺求签\n" +
|
||||||
"- 求签 | 占卜\n- 解签",
|
"- 求签 | 占卜\n- 解签",
|
||||||
|
PublicDataFolder: "Omikuji",
|
||||||
}).ApplySingle(ctxext.DefaultSingle)
|
}).ApplySingle(ctxext.DefaultSingle)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
dbpath := engine.DataFolder()
|
||||||
|
db.DBPath = dbpath + "kuji.db"
|
||||||
|
defer order.DoneOnExit()()
|
||||||
|
_, _ = 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).
|
engine.OnFullMatchGroup([]string{"求签", "占卜"}).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
miku := bangoToday(ctx.Event.UserID)
|
miku := bangoToday(ctx.Event.UserID)
|
||||||
|
|||||||
@ -4,7 +4,13 @@ import (
|
|||||||
wr "github.com/mroth/weightedrand"
|
wr "github.com/mroth/weightedrand"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type rate []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Weight float64 `json:"weight"`
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
areac *wr.Chooser
|
||||||
gender, _ = wr.NewChooser(
|
gender, _ = wr.NewChooser(
|
||||||
wr.Choice{Item: "男孩子", Weight: 50707},
|
wr.Choice{Item: "男孩子", Weight: 50707},
|
||||||
wr.Choice{Item: "女孩子", Weight: 48292},
|
wr.Choice{Item: "女孩子", Weight: 48292},
|
||||||
|
|||||||
@ -2,59 +2,12 @@ package reborn
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
|
||||||
|
|
||||||
wr "github.com/mroth/weightedrand"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/file"
|
"github.com/FloatTech/zbputils/file"
|
||||||
"github.com/FloatTech/zbputils/process"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
datapath = "data/Reborn"
|
|
||||||
jsonfile = datapath + "/rate.json"
|
|
||||||
)
|
|
||||||
|
|
||||||
type rate []struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Weight float64 `json:"weight"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
areac *wr.Chooser
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
go func() {
|
|
||||||
defer order.DoneOnExit()()
|
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
err := os.MkdirAll(datapath, 0755)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
area := make(rate, 226)
|
|
||||||
err = load(&area)
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
log.Printf("[Reborn]读取%d个国家/地区", len(area))
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
// load 加载rate数据
|
// load 加载rate数据
|
||||||
func load(area *rate) error {
|
func load(area *rate, jsonfile string) error {
|
||||||
data, err := file.GetLazyData(jsonfile, true, true)
|
data, err := file.GetLazyData(jsonfile, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -4,9 +4,10 @@ package reborn
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
|
||||||
|
|
||||||
control "github.com/FloatTech/zbputils/control"
|
control "github.com/FloatTech/zbputils/control"
|
||||||
|
wr "github.com/mroth/weightedrand"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
@ -14,11 +15,32 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rand.Seed(time.Now().UnixNano())
|
en := control.Register("reborn", order.AcquirePrio(), &control.Options{
|
||||||
control.Register("reborn", order.AcquirePrio(), &control.Options{
|
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "投胎\n- reborn",
|
Help: "投胎\n- reborn",
|
||||||
}).OnFullMatch("reborn").SetBlock(true).
|
PublicDataFolder: "Reborn",
|
||||||
|
})
|
||||||
|
go func() {
|
||||||
|
datapath := en.DataFolder()
|
||||||
|
jsonfile := datapath + "rate.json"
|
||||||
|
defer order.DoneOnExit()()
|
||||||
|
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).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
if rand.Int31() > 1<<27 {
|
if rand.Int31() > 1<<27 {
|
||||||
ctx.SendChain(message.At(ctx.Event.UserID), message.Text(fmt.Sprintf("投胎成功!\n您出生在 %s, 是 %s。", randcoun(), randgen())))
|
ctx.SendChain(message.At(ctx.Event.UserID), message.Text(fmt.Sprintf("投胎成功!\n您出生在 %s, 是 %s。", randcoun(), randgen())))
|
||||||
|
|||||||
@ -17,18 +17,13 @@ import (
|
|||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
)
|
)
|
||||||
|
|
||||||
const cachedir = "data/scale/"
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
_ = os.RemoveAll(cachedir)
|
|
||||||
err := os.MkdirAll(cachedir, 0755)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
engine := control.Register("scale", order.AcquirePrio(), &control.Options{
|
engine := control.Register("scale", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "叔叔的AI二次元图片放大\n- 放大图片[图片]",
|
Help: "叔叔的AI二次元图片放大\n- 放大图片[图片]",
|
||||||
|
PrivateDataFolder: "scale",
|
||||||
}).ApplySingle(ctxext.DefaultSingle)
|
}).ApplySingle(ctxext.DefaultSingle)
|
||||||
|
cachedir := engine.DataFolder()
|
||||||
// 上传一张图进行评价
|
// 上传一张图进行评价
|
||||||
engine.OnKeywordGroup([]string{"放大图片"}, zero.OnlyGroup, ctxext.MustProvidePicture, getPara).SetBlock(true).
|
engine.OnKeywordGroup([]string{"放大图片"}, zero.OnlyGroup, ctxext.MustProvidePicture, getPara).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
|
|||||||
@ -1,43 +0,0 @@
|
|||||||
package score
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/file"
|
|
||||||
"github.com/FloatTech/zbputils/img/text"
|
|
||||||
"github.com/FloatTech/zbputils/process"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
cachePath = dbpath + "cache/"
|
|
||||||
dbpath = "data/score/"
|
|
||||||
dbfile = dbpath + "score.db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// sdb 得分数据库
|
|
||||||
var sdb *scoredb
|
|
||||||
|
|
||||||
// 加载数据库
|
|
||||||
func init() {
|
|
||||||
go func() {
|
|
||||||
defer order.DoneOnExit()()
|
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
_, err := file.GetLazyData(text.BoldFontFile, false, true)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
_, err = file.GetLazyData(text.FontFile, false, true)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
_ = os.MkdirAll(dbpath, 0755)
|
|
||||||
os.RemoveAll(cachePath)
|
|
||||||
_ = os.MkdirAll(cachePath, 0755)
|
|
||||||
sdb = initialize(dbfile)
|
|
||||||
log.Println("[score]加载score数据库")
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
@ -8,6 +8,9 @@ import (
|
|||||||
_ "github.com/logoove/sqlite" // import sql
|
_ "github.com/logoove/sqlite" // import sql
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// sdb 得分数据库
|
||||||
|
var sdb *scoredb
|
||||||
|
|
||||||
// scoredb 分数数据库
|
// scoredb 分数数据库
|
||||||
type scoredb gorm.DB
|
type scoredb gorm.DB
|
||||||
|
|
||||||
|
|||||||
@ -38,9 +38,29 @@ var levelArray = [...]int{0, 1, 2, 5, 10, 20, 35, 55, 75, 100, 120}
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
engine := control.Register("score", order.AcquirePrio(), &control.Options{
|
engine := control.Register("score", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "签到得分\n- 签到\n- 获得签到背景[@xxx] | 获得签到背景",
|
Help: "签到得分\n- 签到\n- 获得签到背景[@xxx] | 获得签到背景",
|
||||||
|
PrivateDataFolder: "score",
|
||||||
})
|
})
|
||||||
|
cachePath := engine.DataFolder() + "cache/"
|
||||||
|
go func() {
|
||||||
|
defer order.DoneOnExit()()
|
||||||
|
os.RemoveAll(cachePath)
|
||||||
|
err := os.MkdirAll(cachePath, 0755)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
_, err = file.GetLazyData(text.BoldFontFile, false, true)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
_, err = file.GetLazyData(text.FontFile, false, true)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
sdb = initialize(engine.DataFolder() + "score.db")
|
||||||
|
log.Println("[score]加载score数据库")
|
||||||
|
}()
|
||||||
engine.OnFullMatch("签到", zero.OnlyGroup).SetBlock(true).
|
engine.OnFullMatch("签到", zero.OnlyGroup).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
uid := ctx.Event.UserID
|
uid := ctx.Event.UserID
|
||||||
|
|||||||
@ -4,7 +4,6 @@ package setutime
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -43,19 +42,27 @@ func (p *imgpool) List() (l []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var pool = &imgpool{
|
var pool = &imgpool{
|
||||||
db: &sql.Sqlite{DBPath: "data/SetuTime/SetuTime.db"},
|
db: &sql.Sqlite{},
|
||||||
path: pixiv.CacheDir,
|
path: pixiv.CacheDir,
|
||||||
max: 10,
|
max: 10,
|
||||||
pool: map[string][]*pixiv.Illust{},
|
pool: map[string][]*pixiv.Illust{},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { // 插件主体
|
func init() { // 插件主体
|
||||||
_ = os.MkdirAll("data/SetuTime", 0755)
|
engine := control.Register("setutime", order.AcquirePrio(), &control.Options{
|
||||||
|
DisableOnDefault: false,
|
||||||
|
Help: "涩图\n" +
|
||||||
|
"- 来份[涩图/二次元/风景/车万]\n" +
|
||||||
|
"- 添加[涩图/二次元/风景/车万][P站图片ID]\n" +
|
||||||
|
"- 删除[涩图/二次元/风景/车万][P站图片ID]\n" +
|
||||||
|
"- >setu status",
|
||||||
|
PublicDataFolder: "SetuTime",
|
||||||
|
})
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer order.DoneOnExit()()
|
defer order.DoneOnExit()()
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
// 如果数据库不存在则下载
|
// 如果数据库不存在则下载
|
||||||
|
pool.db.DBPath = engine.DataFolder() + "SetuTime.db"
|
||||||
_, _ = fileutil.GetLazyData(pool.db.DBPath, false, false)
|
_, _ = fileutil.GetLazyData(pool.db.DBPath, false, false)
|
||||||
err := pool.db.Open()
|
err := pool.db.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -68,14 +75,6 @@ func init() { // 插件主体
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
engine := control.Register("setutime", order.AcquirePrio(), &control.Options{
|
|
||||||
DisableOnDefault: false,
|
|
||||||
Help: "涩图\n" +
|
|
||||||
"- 来份[涩图/二次元/风景/车万]\n" +
|
|
||||||
"- 添加[涩图/二次元/风景/车万][P站图片ID]\n" +
|
|
||||||
"- 删除[涩图/二次元/风景/车万][P站图片ID]\n" +
|
|
||||||
"- >setu status",
|
|
||||||
})
|
|
||||||
engine.OnRegex(`^来份(.*)$`, ctxext.FirstValueInList(pool)).SetBlock(true).Limit(ctxext.LimitByUser).
|
engine.OnRegex(`^来份(.*)$`, ctxext.FirstValueInList(pool)).SetBlock(true).Limit(ctxext.LimitByUser).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
var imgtype = ctx.State["regex_matched"].([]string)[1]
|
var imgtype = ctx.State["regex_matched"].([]string)[1]
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
package sleepmanage
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/process"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
|
||||||
|
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/plugin_sleep_manage/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
go func() {
|
|
||||||
defer order.DoneOnExit()()
|
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
_ = os.MkdirAll(dbpath, 0755)
|
|
||||||
model.Initialize(dbfile)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
@ -16,14 +16,13 @@ import (
|
|||||||
"github.com/FloatTech/ZeroBot-Plugin/plugin_sleep_manage/model"
|
"github.com/FloatTech/ZeroBot-Plugin/plugin_sleep_manage/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
const dbpath = "data/sleep/"
|
|
||||||
const dbfile = dbpath + "manage.db"
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
engine := control.Register("sleepmanage", order.AcquirePrio(), &control.Options{
|
engine := control.Register("sleepmanage", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "sleepmanage\n- 早安\n- 晚安",
|
Help: "sleepmanage\n- 早安\n- 晚安",
|
||||||
|
PrivateDataFolder: "sleep",
|
||||||
})
|
})
|
||||||
|
dbfile := engine.DataFolder() + "manage.db"
|
||||||
engine.OnFullMatch("早安", isMorning, zero.OnlyGroup).SetBlock(true).
|
engine.OnFullMatch("早安", isMorning, zero.OnlyGroup).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
db, err := model.Open(dbfile)
|
db, err := model.Open(dbfile)
|
||||||
|
|||||||
@ -2,31 +2,42 @@
|
|||||||
package thesaurus
|
package thesaurus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
|
||||||
control "github.com/FloatTech/zbputils/control"
|
control "github.com/FloatTech/zbputils/control"
|
||||||
|
"github.com/FloatTech/zbputils/file"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
type kimo = map[string]*[]string
|
||||||
dbpath = "data/Chat/"
|
|
||||||
dbfile = dbpath + "kimoi.json"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
engine = control.Register("thesaurus", order.AcquirePrio(), &control.Options{
|
|
||||||
DisableOnDefault: false,
|
|
||||||
Help: "thesaurus\n- 词典匹配回复",
|
|
||||||
})
|
|
||||||
kimomap = make(kimo, 256)
|
|
||||||
chatList = make([]string, 0, 256)
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
initThesaurusList(func() {
|
engine := control.Register("thesaurus", order.AcquirePrio(), &control.Options{
|
||||||
|
DisableOnDefault: false,
|
||||||
|
Help: "thesaurus\n- 词典匹配回复",
|
||||||
|
PublicDataFolder: "Chat",
|
||||||
|
})
|
||||||
|
go func() {
|
||||||
|
defer order.DoneOnExit()()
|
||||||
|
data, err := file.GetLazyData(engine.DataFolder()+"kimoi.json", true, true)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
kimomap := make(kimo, 256)
|
||||||
|
err = json.Unmarshal(data, &kimomap)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
chatList := make([]string, 0, 256)
|
||||||
|
for k := range kimomap {
|
||||||
|
chatList = append(chatList, k)
|
||||||
|
}
|
||||||
|
logrus.Infoln("[thesaurus]加载", len(chatList), "条kimoi")
|
||||||
engine.OnFullMatchGroup(chatList, zero.OnlyToMe).SetBlock(true).Handle(
|
engine.OnFullMatchGroup(chatList, zero.OnlyToMe).SetBlock(true).Handle(
|
||||||
func(ctx *zero.Ctx) {
|
func(ctx *zero.Ctx) {
|
||||||
key := ctx.MessageString()
|
key := ctx.MessageString()
|
||||||
@ -34,5 +45,5 @@ func init() {
|
|||||||
text := val[rand.Intn(len(val))]
|
text := val[rand.Intn(len(val))]
|
||||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(text)) // 来自于 https://github.com/Kyomotoi/AnimeThesaurus 的回复 经过二次修改
|
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(text)) // 来自于 https://github.com/Kyomotoi/AnimeThesaurus 的回复 经过二次修改
|
||||||
})
|
})
|
||||||
})
|
}()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,36 +0,0 @@
|
|||||||
package thesaurus
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/file"
|
|
||||||
"github.com/FloatTech/zbputils/process"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
|
||||||
)
|
|
||||||
|
|
||||||
type kimo = map[string]*[]string
|
|
||||||
|
|
||||||
func initThesaurusList(postinit func()) {
|
|
||||||
go func() {
|
|
||||||
defer order.DoneOnExit()()
|
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
_ = os.MkdirAll(dbpath, 0755)
|
|
||||||
data, err := file.GetLazyData(dbfile, true, true)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(data, &kimomap)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
for k := range kimomap {
|
|
||||||
chatList = append(chatList, k)
|
|
||||||
}
|
|
||||||
logrus.Infoln("[thesaurus]加载", len(chatList), "条kimoi")
|
|
||||||
postinit()
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
@ -1,45 +0,0 @@
|
|||||||
package vtbquotation
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/fumiama/cron"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/process"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
|
||||||
|
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/plugin_vtb_quotation/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
go func() {
|
|
||||||
defer order.DoneOnExit()()
|
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
log.Println("[vtb/cron] 开启vtb数据库日常更新")
|
|
||||||
vtbDaily()
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func vtbDaily() {
|
|
||||||
c := cron.New()
|
|
||||||
_, err := c.AddFunc("0 4 * * *", func() { vtbData() })
|
|
||||||
if err != nil {
|
|
||||||
log.Errorln("定时任务有错误:", err)
|
|
||||||
} else {
|
|
||||||
log.Println("开启vtb数据库定时任务")
|
|
||||||
c.Start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func vtbData() {
|
|
||||||
db := model.Initialize(dbfile)
|
|
||||||
if db != nil {
|
|
||||||
for _, v := range db.GetVtbList() {
|
|
||||||
db.StoreVtb(v)
|
|
||||||
}
|
|
||||||
err := db.Close()
|
|
||||||
if err != nil {
|
|
||||||
log.Errorln("[vtb/cron]", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
package vtbquotation
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/file"
|
|
||||||
"github.com/FloatTech/zbputils/process"
|
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 加载数据库
|
|
||||||
func init() {
|
|
||||||
go func() {
|
|
||||||
defer order.DoneOnExit()()
|
|
||||||
process.SleepAbout1sTo2s()
|
|
||||||
_ = os.MkdirAll(dbpath, 0755)
|
|
||||||
_, _ = file.GetLazyData(dbfile, false, false)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||||
|
|
||||||
control "github.com/FloatTech/zbputils/control"
|
control "github.com/FloatTech/zbputils/control"
|
||||||
|
"github.com/FloatTech/zbputils/file"
|
||||||
"github.com/FloatTech/zbputils/img/text"
|
"github.com/FloatTech/zbputils/img/text"
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
@ -22,17 +23,19 @@ import (
|
|||||||
"github.com/FloatTech/ZeroBot-Plugin/plugin_vtb_quotation/model"
|
"github.com/FloatTech/ZeroBot-Plugin/plugin_vtb_quotation/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const regStr = ".*/(.*)"
|
||||||
regStr = ".*/(.*)"
|
|
||||||
dbpath = "data/VtbQuotation/"
|
|
||||||
dbfile = dbpath + "vtb.db"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
engine := control.Register("vtbquotation", order.AcquirePrio(), &control.Options{
|
engine := control.Register("vtbquotation", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "vtbkeyboard.moe\n- vtb语录\n- 随机vtb\n- 更新vtb\n",
|
Help: "vtbkeyboard.moe\n- vtb语录\n- 随机vtb\n- 更新vtb\n",
|
||||||
|
PublicDataFolder: "VtbQuotation",
|
||||||
})
|
})
|
||||||
|
dbfile := engine.DataFolder() + "vtb.db"
|
||||||
|
go func() {
|
||||||
|
defer order.DoneOnExit()()
|
||||||
|
_, _ = file.GetLazyData(dbfile, false, false)
|
||||||
|
}()
|
||||||
engine.OnFullMatch("vtb语录").SetBlock(true).
|
engine.OnFullMatch("vtb语录").SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
var firstIndex int
|
var firstIndex int
|
||||||
@ -198,7 +201,16 @@ func init() {
|
|||||||
engine.OnFullMatch("更新vtb", zero.SuperUserPermission).SetBlock(true).
|
engine.OnFullMatch("更新vtb", zero.SuperUserPermission).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
ctx.Send("少女祈祷中......")
|
ctx.Send("少女祈祷中......")
|
||||||
vtbData()
|
db := model.Initialize(dbfile)
|
||||||
|
if db != nil {
|
||||||
|
for _, v := range db.GetVtbList() {
|
||||||
|
db.StoreVtb(v)
|
||||||
|
}
|
||||||
|
err := db.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln("[vtb/cron]", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
ctx.Send("vtb数据库已更新")
|
ctx.Send("vtb数据库已更新")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user