forked from FloatTech/ZeroBot-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ 新增 插件冲突检测、b14 加解密 添加随机等待 1~2s 工具函数
- Loading branch information
Showing
13 changed files
with
191 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("解密失败!")) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.