mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-01-12 00:29:04 +08:00
feat: 添加小红书文案 (#1250)
Some checks are pending
最新版 / Build binary CI (386, linux) (push) Waiting to run
最新版 / Build binary CI (386, windows) (push) Waiting to run
最新版 / Build binary CI (amd64, linux) (push) Waiting to run
最新版 / Build binary CI (amd64, windows) (push) Waiting to run
最新版 / Build binary CI (arm, linux) (push) Waiting to run
最新版 / Build binary CI (arm64, linux) (push) Waiting to run
PushLint / lint (push) Waiting to run
Some checks are pending
最新版 / Build binary CI (386, linux) (push) Waiting to run
最新版 / Build binary CI (386, windows) (push) Waiting to run
最新版 / Build binary CI (amd64, linux) (push) Waiting to run
最新版 / Build binary CI (amd64, windows) (push) Waiting to run
最新版 / Build binary CI (arm, linux) (push) Waiting to run
最新版 / Build binary CI (arm64, linux) (push) Waiting to run
PushLint / lint (push) Waiting to run
This commit is contained in:
parent
ec59133f96
commit
91d512498d
10
README.md
10
README.md
@ -1514,6 +1514,16 @@ print("run[CQ:image,file="+j["img"]+"]")
|
|||||||
|
|
||||||
- 注:由于需要科学,默认注释。
|
- 注:由于需要科学,默认注释。
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>小红书文案</summary>
|
||||||
|
|
||||||
|
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/xhstext"`
|
||||||
|
|
||||||
|
- [x] 捧场
|
||||||
|
|
||||||
|
- [x] 有梗
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
<details>
|
<details>
|
||||||
<summary>游戏王白鸽API卡查</summary>
|
<summary>游戏王白鸽API卡查</summary>
|
||||||
|
|||||||
1
main.go
1
main.go
@ -154,6 +154,7 @@ import (
|
|||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wife" // 抽老婆
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wife" // 抽老婆
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wordcount" // 聊天热词
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wordcount" // 聊天热词
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wordle" // 猜单词
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wordle" // 猜单词
|
||||||
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/xhstext" // 小红书文案
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ygocdb" // 游戏王白鸽API卡查
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ygocdb" // 游戏王白鸽API卡查
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ygotrade" // 游戏王集换社卡价查询
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ygotrade" // 游戏王集换社卡价查询
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ymgal" // 月幕galgame
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ymgal" // 月幕galgame
|
||||||
|
|||||||
83
plugin/xhstext/xhstext.go
Normal file
83
plugin/xhstext/xhstext.go
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
// Package xhstext 小红书文案
|
||||||
|
package xhstext
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
fcext "github.com/FloatTech/floatbox/ctxext"
|
||||||
|
sql "github.com/FloatTech/sqlite"
|
||||||
|
ctrl "github.com/FloatTech/zbpctrl"
|
||||||
|
"github.com/FloatTech/zbputils/control"
|
||||||
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
)
|
||||||
|
|
||||||
|
type xhstext struct {
|
||||||
|
ID uint32 `db:"id"`
|
||||||
|
Text string `db:"text"`
|
||||||
|
Label string `db:"label"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var db sql.Sqlite
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||||
|
DisableOnDefault: false,
|
||||||
|
Brief: "小红书文案",
|
||||||
|
Help: "- 捧场\n- 有梗",
|
||||||
|
PublicDataFolder: "Xhstext",
|
||||||
|
})
|
||||||
|
|
||||||
|
// 初始化数据库
|
||||||
|
initDB := fcext.DoOnceOnSuccess(
|
||||||
|
func(ctx *zero.Ctx) bool {
|
||||||
|
db = sql.New(en.DataFolder() + "xhstext.db")
|
||||||
|
_, err := en.GetLazyData("xhstext.db", true)
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
err = db.Open(time.Hour)
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
err = db.Create("all_texts", &xhstext{})
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
c, err := db.Count("all_texts")
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
logrus.Infoln("[xhstext]加载", c, "条小红书文案")
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
// 捧场命令
|
||||||
|
en.OnFullMatch("捧场", initDB).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||||
|
var x xhstext
|
||||||
|
err := db.Find("all_texts", &x, "WHERE label = '捧场' ORDER BY RANDOM() LIMIT 1")
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.SendChain(message.Text(x.Text))
|
||||||
|
})
|
||||||
|
|
||||||
|
// 有梗命令
|
||||||
|
en.OnFullMatch("有梗", initDB).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||||
|
var x xhstext
|
||||||
|
err := db.Find("all_texts", &x, "WHERE label = '有梗' ORDER BY RANDOM() LIMIT 1")
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.SendChain(message.Text(x.Text))
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user