From 9fe4031e1bd7b714653d3fd1f33626dc26ff3ba4 Mon Sep 17 00:00:00 2001 From: qydysky Date: Tue, 26 Jan 2021 23:57:39 +0800 Subject: [PATCH] =?utf8?q?=E6=B6=88=E6=81=AF=E4=BF=9D=E5=AD=98json?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Reply/F.go | 22 ++++++++++++++++++++++ Reply/Reply.go | 4 +++- bili_danmu.go | 1 + demo/config/config_K_v.json | 5 ++++- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Reply/F.go b/Reply/F.go index ff96265..9578999 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -720,4 +720,26 @@ func Jiezouf(s []string) bool { } jiezou.Unlock() return false +} + +//保存所有消息到json +func init(){ + Save_to_json(0, []interface{}{`[`}) + c.Danmu_Main_mq.Pull_tag(map[string]func(interface{})(bool){ + `change_room`:func(data interface{})(bool){//房间改变 + Save_to_json(0, []interface{}{`[`}) + return false + }, + }) +} + +func Save_to_json(Loc int,Context []interface{}) { + if path,ok := K_v[`save_to_json`].(string);ok && path != ``{ + p.File().FileWR(p.Filel{ + File:path, + Write:true, + Loc:int64(Loc), + Context:Context, + }) + } } \ No newline at end of file diff --git a/Reply/Reply.go b/Reply/Reply.go index b91f6a0..fc326f2 100644 --- a/Reply/Reply.go +++ b/Reply/Reply.go @@ -43,7 +43,9 @@ func Reply(b []byte) { contain := b[c.WS_PACKAGE_HEADER_TOTAL_LENGTH:head.PackL] switch head.OpeaT { - case c.WS_OP_MESSAGE:Msg(contain) + case c.WS_OP_MESSAGE: + Msg(contain) + Save_to_json(-1, []interface{}{contain,`,`}) case c.WS_OP_HEARTBEAT_REPLY:Heart(contain) default :reply_log.L(`W: `,"unknow reply", contain) } diff --git a/bili_danmu.go b/bili_danmu.go index 832fdf9..da796a8 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -262,6 +262,7 @@ func Demo(roomid ...int) { close(interrupt) {//附加功能 直播流 reply.Saveflv_wait() + reply.Save_to_json(-1, []interface{}{`{}]`}) } danmulog.L(`I: `,"结束退出") } diff --git a/demo/config/config_K_v.json b/demo/config/config_K_v.json index c26829c..bb29f8c 100644 --- a/demo/config/config_K_v.json +++ b/demo/config/config_K_v.json @@ -17,5 +17,8 @@ "gtk":"GTK相关", "gtk_保留弹幕数量":25, "gtk_内存头像数量":30, - "gtk_头像获取等待最大数量":30 + "gtk_头像获取等待最大数量":30, + + "save_to_json-help":"保存消息设置,将所有消息保存为json文件,输入文件名(带后缀)", + "save_to_json":"" } \ No newline at end of file -- 2.39.2