From 4f78b755b6fccf3fb7af00a5a3f6268e11574b59 Mon Sep 17 00:00:00 2001 From: qydysky Date: Tue, 15 Sep 2020 18:34:29 +0800 Subject: [PATCH] 10 --- .gitignore | 3 +++ F.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ Msg.go | 1 + bili_danmu.go | 2 +- 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 F.go diff --git a/.gitignore b/.gitignore index 8aea175..beb92ad 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ a.json demo/cookie.txt player-loader-2.0.4.min.js pv-tracker.js +demo/Autoban.txt +demo/his/danmu.log +danmu.log diff --git a/F.go b/F.go new file mode 100644 index 0000000..12f4048 --- /dev/null +++ b/F.go @@ -0,0 +1,46 @@ +package bili_danmu + +import ( + "bytes" + + p "github.com/qydysky/part" +) + +type Autoban struct { + buf []byte + Inuse bool +} + +var autoban = Autoban { + Inuse:true, +} + +func Autobanf(s string) float32 { + if autoban.Inuse {return 0} + + if len(autoban.buf) == 0 { + f := p.File().FileWR(p.Filel{ + File:"Autoban.txt", + Write:false, + }) + autoban.buf = []byte(f) + } + + var scop int + for _, v := range []byte(s) { + if bytes.Contains(autoban.buf, []byte{v}) {scop += 1} + } + return float32(scop) / float32(len(s)) +} + +func Autoban_add(s string) { + if autoban.Inuse {return} + + autoban.buf = append(autoban.buf, []byte(s)...) + p.File().FileWR(p.Filel{ + File:"Autoban.txt", + Write:true, + Loc:-1, + Context:[]interface{}{s}, + }) +} \ No newline at end of file diff --git a/Msg.go b/Msg.go index a12e1e0..1f8d859 100644 --- a/Msg.go +++ b/Msg.go @@ -253,6 +253,7 @@ func danmu(s string) { msg := infob[1].(string) auth := infob[2].([]interface{})[1].(string) + if Autobanf(msg) > 0.5 {msglog.Base(1, "风险").I(msg)} if Msg_roomid != 0 && Msg_cookie != "" && msg == "弹幕机在么" {Danmu_s("在", Msg_cookie, Msg_roomid)} msglog.I(auth, ":", msg) diff --git a/bili_danmu.go b/bili_danmu.go index 86e809d..e0ce16a 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -150,7 +150,7 @@ func headChe(head []byte, datalenght,Bodyv,Opeation,Sequence,show int) (bool,int if len(head) != WS_PACKAGE_HEADER_TOTAL_LENGTH {return false, 0} danmulog.Base(-1, "头部检查").Level(show) - defer danmulog.Base(0) + defer danmulog.Base(0).Level(LogLevel) packL := Btoi32(head[:4]) headL := Btoi16(head[4:6]) -- 2.39.2