From 058398d75afa22d3671ed4482ba223cb194da539 Mon Sep 17 00:00:00 2001 From: qydysky Date: Wed, 16 Sep 2020 17:00:32 +0800 Subject: [PATCH] 12 --- F.go | 58 +++++++++++++++++++++++++++++++----- Msg.go | 82 +++++++++++++++++++++++++++++++++++++++++++-------- README.md | 68 +++++++++++++++++++----------------------- bili_danmu.go | 6 ++-- 4 files changed, 154 insertions(+), 60 deletions(-) diff --git a/F.go b/F.go index 29ceb9f..8665260 100644 --- a/F.go +++ b/F.go @@ -11,15 +11,16 @@ import ( //功能开关 var AllF = map[string]bool{ - "Autoban":true,//自动封禁(仅提示,未完成) - "Danmuji":true,//反射型弹幕机 - "Danmuji_auto":false,//自动型弹幕机 - "Autoskip":true,//刷屏缩减 + "Autoban":false,//自动封禁(仅提示,未完成) + "Danmuji":true,//反射型弹幕机,回应弹幕 + "Danmuji_auto":false,//自动型弹幕机,定时输出 + "Autoskip":true,//刷屏缩减,相同合并 + "Lessdanmu":true,//弹幕缩减,显示差异大的 } func IsOn(s string) bool { - if v, ok := AllF[s]; ok { - return v + if v, ok := AllF[s]; ok && v { + return true } return false } @@ -35,7 +36,7 @@ var autoban = Autoban { } func Autobanf(s string) float32 { - if autoban.Inuse {return 0} + if !autoban.Inuse {return 0} if len(autoban.buf) == 0 { f := p.File().FileWR(p.Filel{ @@ -123,7 +124,48 @@ func Autoskipf(s string, maxNum,muteSecond int) int { } autoskip.num -= 1 i, ok := autoskip.buf.LoadAndDelete(s); - if ok && i.(int) > 0 {fmt.Println("", s, "+", i)} + if ok && i.(int) > 0 {fmt.Println(s, "+", i)} }() return 0 +} + +type Lessdanmu struct { + Inuse bool + buf []string + + avg float32 +} + +var lessdanmu = Lessdanmu{ + Inuse:IsOn("Lessdanmu"), +} + +func Lessdanmuf(s string, bufsize int) bool { + if !lessdanmu.Inuse {return false} + if len(lessdanmu.buf) > bufsize { + lessdanmu.buf = append(lessdanmu.buf[1:], s) + } else { + lessdanmu.buf = append(lessdanmu.buf, s) + } + + o := cross(s, lessdanmu.buf) + lessdanmu.avg = (0.8 * lessdanmu.avg + 0.2 * o) + return o > lessdanmu.avg +} + +func cross(a string,buf []string) float32 { + var ( + s float32 + all float32 + ) + for _,v1 := range buf { + for _,v2 := range v1 { + for _,v3 := range a { + if v3 == v2 {s += 1} + all += 1 + } + } + + } + return s / all } \ No newline at end of file diff --git a/Msg.go b/Msg.go index 6e2c8bd..9b71574 100644 --- a/Msg.go +++ b/Msg.go @@ -1,6 +1,7 @@ package bili_danmu import ( + "fmt" "bytes" "compress/zlib" @@ -14,6 +15,8 @@ var msglog = p.Logf().New().Base(-1, "Msg.go>").Open("danmu.log").Level(1) var Msg_cookie string var Msg_roomid int var Msg_map = map[string]func(replayF, string) { + "ROOM_SKIN_MSG":nil, + "GUARD_ACHIEVEMENT_ROOM":nil, "ANCHOR_LOT_START":nil,//天选之人开始 "ANCHOR_LOT_CHECKSTATUS":nil, "ANCHOR_LOT_END":nil,//天选之人结束 @@ -29,7 +32,8 @@ var Msg_map = map[string]func(replayF, string) { "ROOM_RANK":nil, "ROOM_SHIELD":nil, "USER_TOAST_MSG":nil, - "GUARD_BUY":nil,//大航海购买 + "WIN_ACTIVITY":nil, + "GUARD_BUY":replayF.guard_buy,//大航海购买 "WELCOME_GUARD":nil,//replayF.welcome_guard,//大航海进入 "DANMU_MSG":replayF.danmu,//弹幕 "ROOM_CHANGE":replayF.room_change,//房间信息分区改变 @@ -43,7 +47,7 @@ var Msg_map = map[string]func(replayF, string) { "SUPER_CHAT_MESSAGE_JPN":replayF.super_chat_message,//打赏 "PANEL":replayF.panel,//排行榜 "ENTRY_EFFECT":replayF.entry_effect,//进入特效 - "ROOM_REAL_TIME_MESSAGE_UPDATE":replayF.roominfo,//粉丝数 + "ROOM_REAL_TIME_MESSAGE_UPDATE":nil,//replayF.roominfo,//粉丝数 } func Msg(b []byte, compress bool) { @@ -91,6 +95,32 @@ func (replayF) defaultMsg(s string){ msglog.Base(1, "Unknow cmd").E(s) } +func (replayF) guard_buy(s string){ + msglog.Fileonly(true).Base(1, "礼") + defer msglog.Fileonly(false) + username := p.Json().GetValFromS(s, "data.username"); + gift_name := p.Json().GetValFromS(s, "data.gift_name"); + price := p.Json().GetValFromS(s, "data.price"); + + var sh []interface{} + + if username != nil { + sh = append(sh, username) + } + if gift_name != nil { + sh = append(sh, "购买了", gift_name) + } + if price != nil { + sh = append(sh, "¥", price) + } + + fmt.Println("====") + fmt.Println(sh...) + fmt.Println("====") + msglog.I(sh...) + +} + func (replayF) room_change(s string){ title := p.Json().GetValFromS(s, "data.title"); area_name := p.Json().GetValFromS(s, "data.area_name"); @@ -153,20 +183,28 @@ func (replayF) send_gift(s string){ if len(sh) == 0 {return} - msglog.Base(1, "礼") - //小于1万金瓜子 - if allprice < 10000 {msglog.T(sh...);return} + msglog.Fileonly(true).Base(1, "礼") + defer msglog.Fileonly(false) + + //小于3万金瓜子 + if allprice < 30000 {msglog.T(sh...);return} + + fmt.Println("====") + fmt.Println(sh...) + fmt.Println("====") msglog.I(sh...) } func (replayF) room_block_msg(s string) { - msglog.Base(1, "封") + msglog.Fileonly(true).Base(1, "封") + defer msglog.Fileonly(false) if uname := p.Json().GetValFromS(s, "uname");uname == nil { msglog.E("uname", uname) return } else { - msglog.I("用户", uname, "已被封禁") + fmt.Println("用户", uname, "已被封禁") + msglog.I("用户", uname, "已被封禁") } } @@ -212,29 +250,38 @@ func (replayF) super_chat_message(s string){ if message_jpn != nil && message != message_jpn { sh = append(sh, message_jpn) } + msglog.Fileonly(true) + defer msglog.Fileonly(false) + fmt.Println("====") + fmt.Println(sh...) + fmt.Println("====") msglog.Base(1, "礼").I(sh...) } func (replayF) panel(s string){ - msglog.Base(1, "房") + msglog.Fileonly(true).Base(1, "房") + defer msglog.Fileonly(false) if note := p.Json().GetValFromS(s, "data.note");note == nil { msglog.E("note", note) return } else { + fmt.Println("排行", note) msglog.I("排行", note) } } func (replayF) entry_effect(s string){ - msglog.Base(1, "房") + msglog.Fileonly(true).Base(1, "房") + defer msglog.Fileonly(false) if copy_writing := p.Json().GetValFromS(s, "data.copy_writing");copy_writing == nil { msglog.E("copy_writing", copy_writing) return } else { msglog.I(copy_writing) + fmt.Println(copy_writing) } } @@ -276,13 +323,24 @@ func (replayF) danmu(s string) { msg := infob[1].(string) auth := infob[2].([]interface{})[1] + msglog.Fileonly(true) + defer msglog.Fileonly(false) + Danmujif(msg, Msg_cookie, Msg_roomid) - if Autobanf(msg) > 0.5 {msglog.Base(1, "风险").I(msg);return} - if i := Autoskipf(msg, 20, 20); i > 0 { - msglog.Fileonly(true).I(auth, ":", msg).Fileonly(false) + if Autobanf(msg) > 0.5 { + msglog.Base(1, "风险").I(msg) + return + } + if i := Autoskipf(msg, 50, 15); i > 0 { + msglog.I(auth, ":", msg) + return + } + if Lessdanmuf(msg, 50) { + msglog.I(auth, ":", msg) return } + fmt.Println(msg) msglog.I(auth, ":", msg) } } diff --git a/README.md b/README.md index bed324f..4eee78b 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ ## bilibili 直播弹幕机 -### 当前支持功能列表 +### 当前支持显示/功能 ``` -Msg.go -case 后有函数调用的为支持,无调用的为待完善,注释掉的调用为未启用 +显示 +case 后有函数调用的为支持,为nil的为待完善,注释掉的调用为未启用 var Msg_map = map[string]func(replayF, string) { + "ROOM_SKIN_MSG":nil, + "GUARD_ACHIEVEMENT_ROOM":nil, "ANCHOR_LOT_START":nil,//天选之人开始 "ANCHOR_LOT_CHECKSTATUS":nil, "ANCHOR_LOT_END":nil,//天选之人结束 @@ -21,7 +23,8 @@ var Msg_map = map[string]func(replayF, string) { "ROOM_RANK":nil, "ROOM_SHIELD":nil, "USER_TOAST_MSG":nil, - "GUARD_BUY":nil,//大航海购买 + "WIN_ACTIVITY":nil, + "GUARD_BUY":replayF.guard_buy,//大航海购买 "WELCOME_GUARD":nil,//replayF.welcome_guard,//大航海进入 "DANMU_MSG":replayF.danmu,//弹幕 "ROOM_CHANGE":replayF.room_change,//房间信息分区改变 @@ -35,15 +38,17 @@ var Msg_map = map[string]func(replayF, string) { "SUPER_CHAT_MESSAGE_JPN":replayF.super_chat_message,//打赏 "PANEL":replayF.panel,//排行榜 "ENTRY_EFFECT":replayF.entry_effect,//进入特效 - "ROOM_REAL_TIME_MESSAGE_UPDATE":replayF.roominfo,//粉丝数 + "ROOM_REAL_TIME_MESSAGE_UPDATE":nil,//replayF.roominfo,//粉丝数 } 其他功能 +//功能开关 var AllF = map[string]bool{ - "Autoban":true,//自动封禁(仅提示,未完成) - "Danmuji":true,//反射型弹幕机 - "Danmuji_auto":false,//自动型弹幕机 - "Autoskip":true,//刷屏缩减 + "Autoban":false,//自动封禁(仅提示,未完成) + "Danmuji":true,//反射型弹幕机,回应弹幕 + "Danmuji_auto":false,//自动型弹幕机,定时输出 + "Autoskip":true,//刷屏缩减,相同合并 + "Lessdanmu":true,//弹幕缩减,显示差异大的 } ``` @@ -55,35 +60,22 @@ cd demo go run main.go ``` ``` -输入房间号: 13946381 -INFO: 2020/09/15 06:40:21 [bili_danmu.go>测试] [连接到房间 13946381] -INFO: 2020/09/15 06:40:21 [bili_danmu.go>测试] [连接 wss://tx-sh-live-comet-01.chat.bilibili.com/sub] -INFO: 2020/09/15 06:40:21 [bili_danmu.go>测试] [已连接到房间 13946381] -INFO: 2020/09/15 06:40:22 [bili_danmu.go>测试] [开始心跳] -弹幕 -INFO: 2020/09/15 06:40:29 [Msg.go>] [pek0pek0 : 外掛] -弹幕机 -INFO: 2020/09/15 14:45:54 [弹幕发送] [发送 在 至 12345] -INFO: 2020/09/15 14:45:55 [弹幕发送] [成功] -INFO: 2020/09/15 14:45:55 [Msg.go>] [12345 : 弹幕机在么] -INFO: 2020/09/15 14:45:56 [Msg.go>] [12345 : 在] -礼物 -INFO: 2020/09/15 09:00:26 [Msg.go> 礼] [不能一命通关的M桑 投喂 5 x 冰阔落 ( 5000 x 金瓜子 )] -入场提示 -INFO: 2020/09/15 09:00:41 [Msg.go> 房] [欢迎舰长 <%不同选择%> 进入直播间] -排行 -INFO: 2020/09/15 09:01:00 [Msg.go> 房] [排行 手游 第4名] -粉丝更新 -INFO: 2020/09/15 09:01:00 [Msg.go> 粉] [粉丝总人数: 395189 粉丝团人数: 2391] -。。。 +$ go run main.go +输入房间号: 213 +INFO: 2020/09/16 16:48:11 [bili_danmu.go 测试] [连接到房间 213] +INFO: 2020/09/16 16:48:11 [bili_danmu.go 测试] [连接 wss://tx-sh-live-comet-01.chat.bilibili.com/sub] +INFO: 2020/09/16 16:48:11 [bili_danmu.go 测试] [已连接到房间 213] +INFO: 2020/09/16 16:48:11 [bili_danmu.go 测试] [开始心跳] +欢迎舰长 <%初鑫不变%> 进入直播间 +C语言get DAZE! + 10 +老鸡捉小鹰 +你快扒拉他 +你这好像是补刀 +吓人 +==== +孤单猫与淋雨猪 投喂 1314 x 辣条 ( 131400 x 金瓜子 ) +==== -^CINFO: 2020/09/15 09:18:28 [ws.go>关闭] [关闭!] -INFO: 2020/09/15 09:18:28 [bili_danmu.go>测试] [停止,等待服务器断开连接] -INFO: 2020/09/15 09:18:28 [ws.go>处理] [捕获到中断] -INFO: 2020/09/15 09:18:28 [ws.go>心跳] [停止!] -ERROR: 2020/09/15 09:18:28 [ws.go>处理] [服务器意外关闭连接] -INFO: 2020/09/15 09:18:29 [bili_danmu.go>测试] [结束退出] - -ctrl+c退出,日志会同时追加记录到文件danmu.log中 +ctrl+c退出,日志会同时追加记录到文件danmu.log中(文件记录完整信息) ``` 更多内容详见注释,如有疑问请发issues,欢迎pr \ No newline at end of file diff --git a/bili_danmu.go b/bili_danmu.go index 4096b71..f91ffca 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -150,7 +150,9 @@ func headGen(datalenght,Opeation,Sequence int) []byte { func headChe(head []byte, datalenght,Bodyv,Opeation,Sequence,show int) (bool,int32) { if len(head) != WS_PACKAGE_HEADER_TOTAL_LENGTH {return false, 0} - danmulog.Base(1, "头部检查").Level(show) + danmulog.Base(-1, "头部检查").Level(show) + defer danmulog.Base(0).Level(LogLevel) + packL := Btoi32(head[:4]) headL := Btoi16(head[4:6]) @@ -163,7 +165,7 @@ func headChe(head []byte, datalenght,Bodyv,Opeation,Sequence,show int) (bool,int if OpeaT != int32(Opeation) {danmulog.E("类型错误");return false, packL} if Seque != int32(Sequence) {danmulog.E("Seq错误");return false, packL} if BodyV != int16(Bodyv) {danmulog.E("压缩算法错误");return false, packL} - danmulog.Base(0).Level(LogLevel) + return true, packL } -- 2.39.2