mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-12 02:00:24 +00:00
✨ 新增插件控制
This commit is contained in:
@@ -8,25 +8,36 @@ import (
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
"github.com/FloatTech/ZeroBot-Plugin/plugin_diana/data"
|
||||
)
|
||||
|
||||
var engine *zero.Engine
|
||||
|
||||
func init() {
|
||||
engine = control.Register("diana", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "嘉然\n" +
|
||||
"- @BOT 小作文\n" +
|
||||
"- @BOT 发大病\n" +
|
||||
"- @BOT 教你一篇小作文[作文]\n" +
|
||||
"- [回复]查重",
|
||||
})
|
||||
// 随机发送一篇上面的小作文
|
||||
zero.OnFullMatch("小作文", zero.OnlyToMe).
|
||||
engine.OnFullMatch("小作文", zero.OnlyToMe).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
// 绕过第一行发病
|
||||
ctx.Send((*data.Array)[rand.Intn(len(*data.Array)-1)+1])
|
||||
})
|
||||
// 逆天
|
||||
zero.OnFullMatch("发大病", zero.OnlyToMe).
|
||||
engine.OnFullMatch("发大病", zero.OnlyToMe).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
// 第一行是发病
|
||||
ctx.Send((*data.Array)[0])
|
||||
})
|
||||
// 增加小作文
|
||||
zero.OnRegex(`^教你一篇小作文(.*)$`, zero.AdminPermission).
|
||||
engine.OnRegex(`^教你一篇小作文(.*)$`, zero.AdminPermission).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
err := data.AddText(ctx.State["regex_matched"].([]string)[1])
|
||||
if err != nil {
|
||||
|
||||
@@ -93,6 +93,8 @@ func LoadText() error {
|
||||
func AddText(txt string) error {
|
||||
sum := md5.Sum(str2bytes(txt))
|
||||
if txt != "" && !isin(sum) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
compo.Array = append(compo.Array, txt)
|
||||
md5s = append(md5s, sum)
|
||||
return savecompo()
|
||||
@@ -114,13 +116,10 @@ func savecompo() error {
|
||||
data, err := compo.Marshal()
|
||||
if err == nil {
|
||||
if _, err := os.Stat(datapath); err == nil || os.IsExist(err) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
f, err1 := os.OpenFile(pbfile, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
|
||||
if err1 == nil {
|
||||
_, err2 := f.Write(data)
|
||||
f.Close()
|
||||
|
||||
return err2
|
||||
}
|
||||
return err1
|
||||
|
||||
@@ -28,7 +28,7 @@ type zhiwang struct {
|
||||
|
||||
// 小作文查重: 回复要查的消息 查重
|
||||
func init() {
|
||||
zero.OnMessage(fullmatch("查重")).
|
||||
engine.OnMessage(fullmatch("查重")).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
msg := ctx.Event.Message
|
||||
if msg[0].Type == "reply" {
|
||||
|
||||
Reference in New Issue
Block a user