diff --git a/README.md b/README.md index 78681e54..70238dcb 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,9 @@ zerobot -h -t token -u url [-d|w] [-g 监听地址:端口] qq1 qq2 qq3 ... - [x] 发大病 - [x] 教你一篇小作文[作文] - [x] [回复]查重 +- **鬼东西** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_wtf"` + - [x] 鬼东西列表 + - [x] 查询鬼东西xxx(@xxx) - **AIfalse** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_ai_false"` - [x] 查询计算机当前活跃度 [身体检查] - [x] 清理缓存 diff --git a/main.go b/main.go index 11f1d1af..866b1534 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,7 @@ import ( _ "github.com/FloatTech/ZeroBot-Plugin/plugin_omikuji" // 浅草寺求签 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_reborn" // 投胎 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_shindan" // 测定 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_wtf" // 鬼东西 // b站相关 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili" // 查询b站用户信息 diff --git a/plugin_wtf/main.go b/plugin_wtf/main.go new file mode 100644 index 00000000..ae64e9e9 --- /dev/null +++ b/plugin_wtf/main.go @@ -0,0 +1,62 @@ +package wtf + +import ( + "fmt" + "strconv" + "time" + + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/extension/rate" + "github.com/wdvxdr1123/ZeroBot/message" + + "github.com/FloatTech/ZeroBot-Plugin/control" +) + +var ( + // 限制调用频率 + limit = rate.NewManager(time.Minute*5, 5) +) + +func init() { + en := control.Register("wtf", &control.Options{ + DisableOnDefault: false, + Help: "鬼东西\n- 鬼东西列表\n- 查询鬼东西xxx(@xxx)", + }) + en.OnFullMatch("鬼东西列表").SetBlock(true).SetPriority(30). + Handle(func(ctx *zero.Ctx) { + s := "" + i := 0 + for k := range pathtable { + s += fmt.Sprintf("%02d. %s\n", i, k) + i++ + } + ctx.SendChain(message.Text(s)) + }) + en.OnRegex(`^查询鬼东西(.*)$`).SetBlock(false).SetPriority(30). + Handle(func(ctx *zero.Ctx) { + if !limit.Load(ctx.Event.UserID).Acquire() { + ctx.SendChain(message.Text("请稍后重试0x0...")) + return + } + // 调用接口 + w := NewWtf(ctx.State["regex_matched"].([]string)[1]) + if w == nil { + ctx.SendChain(message.Text("没有这项内容!")) + return + } + // 获取名字 + name := ctx.State["args"].(string) + if len(ctx.Event.Message) > 1 && ctx.Event.Message[1].Type == "at" { + qq, _ := strconv.ParseInt(ctx.Event.Message[1].Data["qq"], 10, 64) + name = ctx.GetGroupMemberInfo(ctx.Event.GroupID, qq, false).Get("nickname").Str + } else if name == "" { + name = ctx.Event.Sender.NickName + } + text, err := w.Predict(name) + if err != nil { + ctx.SendChain(message.Text("ERROR: ", err)) + } + // TODO: 可注入 + ctx.Send(text) + }) +} diff --git a/plugin_wtf/model.go b/plugin_wtf/model.go new file mode 100644 index 00000000..091969f9 --- /dev/null +++ b/plugin_wtf/model.go @@ -0,0 +1,152 @@ +package wtf + +import ( + "encoding/json" + "errors" + "io" + "net/http" + "net/url" +) + +/* JS path getter for https://wtf.hiigara.net/ranking +a = document.getElementById("testList").getElementsByTagName("a") +s = "" +for(i=0; i " + w.name + "\n" + re.Text, nil + } + return "", errors.New(re.Msg) +}