Skip to content

Commit

Permalink
✨ 新增 插件冲突检测、b14 加解密 添加随机等待 1~2s 工具函数
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Oct 28, 2021
1 parent dd32aec commit d205d48
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ data/control
data/SetuTime/search
data/manager
data/acgimage
data/saucenao
data/fortune
data/hs
plugins/*.so
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ zerobot -h -t token -u url [-d|w] [-g] qq1 qq2 qq3 ...
- [x] /还原 xxx (在发送的群/用户还原xxx的开启状态到初始状态)
- [x] /用法 xxx
- [x] /服务列表
- [x] @Bot 插件冲突检测 (会在本群发送一条消息并在约 1s 后撤回以检测其它同类 bot 中已启用的插件并禁用)
- **聊天** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_chat"`
- [x] [BOT名字]
- [x] [戳一戳BOT]
Expand Down Expand Up @@ -108,6 +109,9 @@ zerobot -h -t token -u url [-d|w] [-g] qq1 qq2 qq3 ...
- [x][@xxx]
- [x][@xxx]
- 注:更多指令见项目 --> https://github.com/tdf1939/ZeroBot-Plugin-Gif
- **base16384加解密** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_b14"`
- [x] 加密xxx
- [x] 解密xxx
- **涩图** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_setutime"`
- [x] 来份[涩图/二次元/风景/车万]
- [x] 添加[涩图/二次元/风景/车万][P站图片ID]
Expand Down
92 changes: 92 additions & 0 deletions control/cd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package control

import (
"encoding/binary"
"strings"
"time"

b14 "github.com/fumiama/go-base16384"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
"github.com/wdvxdr1123/ZeroBot/utils/helper"

"github.com/FloatTech/ZeroBot-Plugin/utils/process"
)

var startTime int64

func init() {
// 插件冲突检测 会在本群发送一条消息并在约 1s 后撤回
zero.OnFullMatch("插件冲突检测", zero.OnlyGroup, zero.AdminPermission, zero.OnlyToMe).SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) {
tok, err := genToken()
if err != nil {
return
}
t := message.Text("●cd" + tok)
startTime = time.Now().Unix()
id := ctx.SendChain(t)
process.SleepAbout1sTo2s()
ctx.DeleteMessage(id)
})

zero.OnRegex("^●cd([\u4e00-\u9fa5]{4})$", zero.OnlyGroup).SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) {
tok := ctx.State["regex_matched"].([]string)[1]
if isValidToken(tok) && time.Now().Unix()-startTime < 10 {
msg := ""
gid := ctx.Event.GroupID
ForEach(func(key string, manager *Control) bool {
if manager.IsEnabledIn(gid) {
msg += "\xfe\xff" + key
}
return true
})
if len(msg) > 2 {
my, err := b14.UTF16be2utf8(b14.EncodeString(msg[2:]))
mys := "●cd●" + helper.BytesToString(my)
if err == nil {
id := ctx.SendChain(message.Text(mys))
process.SleepAbout1sTo2s()
ctx.DeleteMessage(id)
}
}
}
})

zero.OnRegex("^●cd●(.*)", zero.OnlyGroup).SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) {
msg, err := b14.UTF82utf16be(helper.StringToBytes(ctx.State["regex_matched"].([]string)[1]))
if err == nil {
gid := ctx.Event.GroupID
for _, s := range strings.Split(b14.DecodeString(msg), "\xfe\xff") {
mu.RLock()
c, ok := managers[s]
mu.RUnlock()
if ok && c.IsEnabledIn(gid) {
c.Disable(gid)
}
}
}
})
}

func genToken() (tok string, err error) {
timebytes := make([]byte, 8)
binary.BigEndian.PutUint64(timebytes, uint64(time.Now().Unix()))
timebytes, err = b14.UTF16be2utf8(b14.Encode(timebytes[1:]))
if err == nil {
tok = helper.BytesToString(timebytes)
}
return
}

func isValidToken(tok string) (yes bool) {
s, err := b14.UTF82utf16be(helper.StringToBytes(tok))
if err == nil {
timebytes := make([]byte, 1, 8)
timebytes = append(timebytes, b14.Decode(s)...)
yes = time.Now().Unix()-int64(binary.BigEndian.Uint64(timebytes)) < 10
}
return
}
19 changes: 19 additions & 0 deletions control/cd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package control

import "testing"

func TestGenToken(t *testing.T) {
tok, err := genToken()
if err == nil {
t.Log(tok)
t.Log(isValidToken(tok))
t.Fail()
} else {
t.Fatal(err)
}
}

func TestMaru(t *testing.T) {
t.Log(len("\xff"))
t.Fail()
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/FloatTech/bot-manager v1.0.0
github.com/fogleman/gg v1.3.0
github.com/fumiama/cron v1.3.0
github.com/fumiama/go-base16384 v1.2.1
github.com/gin-gonic/gin v1.7.4
github.com/golang/protobuf v1.5.2
github.com/gorilla/websocket v1.4.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzP
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
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.2.1 h1:6OGprW8g/95m2ocmryHi8mipZ7bx9StFMZDKEqLvMiA=
github.com/fumiama/go-base16384 v1.2.1/go.mod h1:1HTC0QFL7BjS0DuO5Qm+fBYKQkHqmAapLbRpCxrhPXQ=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.7.4 h1:QmUZXrvJ9qZ3GfWvQ+2wnW/1ePrTEJqPKMYEU3lD/DM=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_manager" // 群管
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_nbnhhsh" // 拼音首字母缩写释义工具
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_runcode" // 在线运行代码
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_translation" // 在线运行代码
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_translation" // 翻译

// 娱乐类
_ "github.com/FloatTech/ZeroBot-Plugin-Gif" // 制图
Expand Down
32 changes: 17 additions & 15 deletions plugin_atri/atri.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"

"github.com/FloatTech/ZeroBot-Plugin/utils/process"
)

var (
Expand All @@ -26,18 +28,18 @@ func init() { // 插件主体
zero.OnFullMatch("ATRI醒醒", zero.AdminPermission).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
enable = true
time.Sleep(time.Second * 1)
process.SleepAbout1sTo2s()
ctx.SendChain(randText("嗯呜呜……夏生先生……?"))
})
zero.OnFullMatch("ATRI睡吧", zero.AdminPermission).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
enable = false
time.Sleep(time.Second * 1)
process.SleepAbout1sTo2s()
ctx.SendChain(randText("Zzz……Zzz……"))
})
zero.OnFullMatch("萝卜子", atriSwitch(), atriSleep()).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
time.Sleep(time.Second * 1)
process.SleepAbout1sTo2s()
switch rand.Intn(2) {
case 0:
ctx.SendChain(randText("萝卜子是对机器人的蔑称!", "是亚托莉......萝卜子可是对机器人的蔑称"))
Expand All @@ -47,18 +49,18 @@ func init() { // 插件主体
})
zero.OnFullMatchGroup([]string{"喜欢", "爱你", "爱", "suki", "daisuki", "すき", "好き", "贴贴", "老婆", "亲一个", "mua"}, atriSwitch(), atriSleep(), zero.OnlyToMe).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
time.Sleep(time.Second * 1)
process.SleepAbout1sTo2s()
ctx.SendChain(randImage("SUKI.jpg", "SUKI1.jpg", "SUKI2.png"))
})
zero.OnKeywordGroup([]string{"草你妈", "操你妈", "脑瘫", "废柴", "fw", "five", "废物", "战斗", "爬", "爪巴", "sb", "SB", "傻B"}, atriSwitch(), atriSleep(), zero.OnlyToMe).SetBlock(true).SetPriority(prio - 1).
Handle(func(ctx *zero.Ctx) {
time.Sleep(time.Second * 1)
process.SleepAbout1sTo2s()
ctx.SendChain(randImage("FN.jpg", "WQ.jpg", "WQ1.jpg"))
})
zero.OnFullMatchGroup([]string{"早安", "早哇", "早上好", "ohayo", "哦哈哟", "お早う", "早好", "早"}, atriSwitch()).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
now := time.Now().Hour()
time.Sleep(time.Second * 1)
process.SleepAbout1sTo2s()
switch {
case now < 6: // 凌晨
ctx.SendChain(message.Reply(ctx.Event.MessageID), randText(
Expand Down Expand Up @@ -99,7 +101,7 @@ func init() { // 插件主体
Handle(func(ctx *zero.Ctx) {
now := time.Now().Hour()
if now > 11 && now < 15 { // 中午
time.Sleep(time.Second * 1)
process.SleepAbout1sTo2s()
ctx.SendChain(message.Reply(ctx.Event.MessageID), randText(
"午安w",
"午觉要好好睡哦,ATRI会陪伴在你身旁的w",
Expand All @@ -111,7 +113,7 @@ func init() { // 插件主体
zero.OnFullMatchGroup([]string{"晚安", "oyasuminasai", "おやすみなさい", "晚好", "晚上好"}, atriSwitch()).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
now := time.Now().Hour()
time.Sleep(time.Second * 1)
process.SleepAbout1sTo2s()
switch {
case now < 6: // 凌晨
ctx.SendChain(message.Reply(ctx.Event.MessageID), randText(
Expand Down Expand Up @@ -153,7 +155,7 @@ func init() { // 插件主体
})
zero.OnKeywordGroup([]string{"高性能", "太棒了", "すごい", "sugoi", "斯国一", "よかった"}, atriSwitch(), atriSleep(), zero.OnlyToMe).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
time.Sleep(time.Second * 1)
process.SleepAbout1sTo2s()
ctx.SendChain(randText(
"当然,我是高性能的嘛~!",
"小事一桩,我是高性能的嘛",
Expand All @@ -174,7 +176,7 @@ func init() { // 插件主体
})
zero.OnKeywordGroup([]string{"没事", "没关系", "大丈夫", "还好", "不要紧", "没出大问题", "没伤到哪"}, atriSwitch(), atriSleep(), zero.OnlyToMe).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
time.Sleep(time.Second * 1)
process.SleepAbout1sTo2s()
ctx.SendChain(randText(
"当然,我是高性能的嘛~!",
"没事没事,因为我是高性能的嘛!嗯哼!",
Expand All @@ -189,26 +191,26 @@ func init() { // 插件主体

zero.OnKeywordGroup([]string{"好吗", "是吗", "行不行", "能不能", "可不可以"}, atriSwitch(), atriSleep()).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
time.Sleep(time.Second * 1)
process.SleepAbout1sTo2s()
if rand.Intn(2) == 0 {
ctx.SendChain(randImage("YES.png", "NO.jpg"))
}
})
zero.OnKeywordGroup([]string{"啊这"}, atriSwitch(), atriSleep()).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
time.Sleep(time.Second * 1)
process.SleepAbout1sTo2s()
if rand.Intn(2) == 0 {
ctx.SendChain(randImage("AZ.jpg", "AZ1.jpg"))
}
})
zero.OnKeywordGroup([]string{"我好了"}, atriSwitch(), atriSleep()).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
time.Sleep(time.Second * 1)
process.SleepAbout1sTo2s()
ctx.SendChain(message.Reply(ctx.Event.MessageID), randText("不许好!", "憋回去!"))
})
zero.OnFullMatchGroup([]string{"?", "?", "¿"}, atriSwitch(), atriSleep()).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
time.Sleep(time.Second * 1)
process.SleepAbout1sTo2s()
switch rand.Intn(5) {
case 0:
ctx.SendChain(randText("?", "?", "嗯?", "(。´・ω・)ん?", "ん?"))
Expand All @@ -227,7 +229,7 @@ func init() { // 插件主体
})
zero.OnKeyword("答应我", atriSwitch(), atriSleep(), zero.OnlyToMe).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
time.Sleep(time.Second * 1)
process.SleepAbout1sTo2s()
ctx.SendChain(randText("我无法回应你的请求"))
})
}
Expand Down
38 changes: 38 additions & 0 deletions plugin_b14/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package b14coder

import (
base14 "github.com/fumiama/go-base16384"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
"github.com/wdvxdr1123/ZeroBot/utils/helper"

"github.com/FloatTech/ZeroBot-Plugin/control"
)

func init() {
en := control.Register("base16384", &control.Options{
DisableOnDefault: false,
Help: "base16384加解密\n" +
"- 加密xxx\n- 解密xxx",
})
en.OnRegex(`^加密(.*)`).SetBlock(true).ThirdPriority().
Handle(func(ctx *zero.Ctx) {
str := ctx.State["regex_matched"].([]string)[1]
es, err := base14.UTF16be2utf8(base14.EncodeString(str))
if err == nil {
ctx.SendChain(message.Text(es))
} else {
ctx.SendChain(message.Text("加密失败!"))
}
})
en.OnRegex("^解密([\u4e00-\u9fa5]*)$").SetBlock(true).ThirdPriority().
Handle(func(ctx *zero.Ctx) {
str := ctx.State["regex_matched"].([]string)[1]
es, err := base14.UTF82utf16be(helper.StringToBytes(str))
if err == nil {
ctx.SendChain(message.Text(base14.DecodeString(es)))
} else {
ctx.SendChain(message.Text("解密失败!"))
}
})
}
5 changes: 2 additions & 3 deletions plugin_diana/data/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import (
"crypto/md5"
"errors"
"io"
"math/rand"
"net/http"
"os"
"sync"
"time"

log "github.com/sirupsen/logrus"
"github.com/wdvxdr1123/ZeroBot/utils/helper"

"github.com/FloatTech/ZeroBot-Plugin/utils/file"
"github.com/FloatTech/ZeroBot-Plugin/utils/process"
)

const (
Expand All @@ -35,7 +34,7 @@ var (

func init() {
go func() {
time.Sleep(time.Second + time.Millisecond*time.Duration(rand.Intn(1000)))
process.SleepAbout1sTo2s()
err := os.MkdirAll(datapath, 0755)
if err != nil {
panic(err)
Expand Down
5 changes: 2 additions & 3 deletions plugin_reborn/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package reborn
import (
"encoding/json"
"io"
"math/rand"
"net/http"
"os"
"time"

wr "github.com/mroth/weightedrand"
log "github.com/sirupsen/logrus"

"github.com/FloatTech/ZeroBot-Plugin/utils/file"
"github.com/FloatTech/ZeroBot-Plugin/utils/process"
)

const (
Expand All @@ -31,7 +30,7 @@ var (

func init() {
go func() {
time.Sleep(time.Second + time.Millisecond*time.Duration(rand.Intn(1000)))
process.SleepAbout1sTo2s()
err := os.MkdirAll(datapath, 0755)
if err != nil {
panic(err)
Expand Down
Loading

0 comments on commit d205d48

Please sign in to comment.