From: qydysky Date: Mon, 4 Jan 2021 09:41:15 +0000 (+0800) Subject: 私信 X-Git-Tag: v0.5.6~2^2~31 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=3d8dbc634ba43c414a0d05ce1b62f26abd80079a;p=bili_danmu%2F.git 私信 --- diff --git a/Reply/0Init.go b/Reply/0Init.go index 039ec6d..f3af669 100644 --- a/Reply/0Init.go +++ b/Reply/0Init.go @@ -12,3 +12,14 @@ func init(){ AllF[k] = v.(bool) } } + +//k-v +var K_v =make(map[string]interface{}) + +func init() { + buf := s.New() + buf.Load("config/config_K_v.json") + for k,v := range buf.B { + K_v[k] = v + } +} diff --git a/Reply/Msg.go b/Reply/Msg.go index f9bb7d4..244a68e 100644 --- a/Reply/Msg.go +++ b/Reply/Msg.go @@ -14,6 +14,7 @@ var msglog = c.Log.Base(`Msg`) //Msg类型数据处理方法map var Msg_map = map[string]func(replyF, string) { + `CARD_MSG`:nil,//提示关注 `LIVE_INTERACTIVE_GAME`:nil, `WIDGET_BANNER`:nil,//每日任务 `ROOM_ADMINS`:nil,//房管列表 diff --git a/Reply/Reply.go b/Reply/Reply.go index 719fcb4..2a2e224 100644 --- a/Reply/Reply.go +++ b/Reply/Reply.go @@ -10,7 +10,7 @@ import ( p "github.com/qydysky/part" mq "github.com/qydysky/part/msgq" F "github.com/qydysky/bili_danmu/F" - S "github.com/qydysky/bili_danmu/Send" + send "github.com/qydysky/bili_danmu/Send" c "github.com/qydysky/bili_danmu/CV" ) @@ -130,6 +130,7 @@ func (replyF) anchor_lot_award(s string){ func (replyF) user_toast_msg(s string){ username := p.Json().GetValFromS(s, "data.username"); op_type := p.Json().GetValFromS(s, "data.op_type"); + uid := p.Json().GetValFromS(s, "data.uid"); role_name := p.Json().GetValFromS(s, "data.role_name"); num := p.Json().GetValFromS(s, "data.num"); unit := p.Json().GetValFromS(s, "data.unit"); @@ -174,9 +175,21 @@ func (replyF) user_toast_msg(s string){ msg:fmt.Sprint(sh...), }) } - {//额外 ass + {//额外 ass 私信 Assf(fmt.Sprintln(sh...)) c.Danmu_Main_mq.Push_tag(`guard_update`,nil)//使用连续付费的新舰长无法区分,刷新舰长数 + if uid != 0 { + c.Danmu_Main_mq.Push_tag(`pm`,send.Pm_item{ + Uid:int(uid.(float64)), + Msg:K_v[`上舰私信`].(string), + })//上舰私信 + } + if K_v[`额外私信对象`].(float64) != 0 { + c.Danmu_Main_mq.Push_tag(`pm`,send.Pm_item{ + Uid:int(K_v[`额外私信对象`].(float64)), + Msg:K_v[`上舰私信(额外)`].(string), + })//上舰私信-对额外 + } } fmt.Println("\n====") fmt.Println(sh...) @@ -589,7 +602,7 @@ func Msg_senddanmu(msg string){ msglog.L(`I: `, `c.Cookie == "" || c.Roomid == 0`) return } - S.Danmu_s(msg, c.Cookie, c.Roomid) + send.Danmu_s(msg, c.Cookie, c.Roomid) } //弹幕显示 @@ -612,12 +625,24 @@ func Msg_showdanmu(auth interface{}, m ...string) { Gui_show(m...) } } - {//语言tts + {//语言tts 私信 if len(m) > 1 { c.Danmu_Main_mq.Push_tag(`tts`,Danmu_mq_t{//传入消息队列 uid:m[1], msg:msg, }) + if i,e := strconv.Atoi(m[1]);e == nil { + c.Danmu_Main_mq.Push_tag(`pm`,send.Pm_item{ + Uid:i, + Msg:K_v[`弹幕私信`].(string), + })//上舰私信 + } + if K_v[`额外私信对象`].(float64) != 0 { + c.Danmu_Main_mq.Push_tag(`pm`,send.Pm_item{ + Uid:int(K_v[`额外私信对象`].(float64)), + Msg:K_v[`弹幕私信(额外)`].(string), + })//上舰私信-对额外 + } } } fmt.Println(msg) diff --git a/Send/Send_pm.go b/Send/Send_pm.go new file mode 100644 index 0000000..71a631c --- /dev/null +++ b/Send/Send_pm.go @@ -0,0 +1,92 @@ +package send + +import ( + "net/url" + "errors" + "strings" + "strconv" + p "github.com/qydysky/part" + c "github.com/qydysky/bili_danmu/CV" + uuid "github.com/gofrs/uuid" +) + +type Pm_item struct { + Uid int + Msg string +} + +//每5s一个令牌,最多等10秒 +var pm_limit = p.Limit(1, 5000, 10000) + +func Send_pm(uid int, msg string) error { + if pm_limit.TO() {return errors.New("TO")} + log := c.Log.Base_add(`私信`) + + if msg == `` || uid == 0 { + return errors.New(`msg == "" || uid == 0`) + } + + if c.Uid == 0 { + log.L(`E: `,`client uid == 0`) + return errors.New(`client uid == 0`) + } else if c.Uid == uid { + log.L(`W: `,`不能发送给自己`) + return errors.New(`不能发送给自己`) + } + + var csrf string + if i := strings.Index(c.Cookie, "bili_jct="); i == -1 { + log.L(`E: `,`Cookie错误,无bili_jct=`) + return errors.New("Cookie错误,无bili_jct=") + } else { + if d := strings.Index(c.Cookie[i + 9:], ";"); d == -1 { + csrf = c.Cookie[i + 9:] + } else { + csrf = c.Cookie[i + 9:][:d] + } + } + + var new_uuid string + { + if tmp_uuid,e := uuid.NewV4();e == nil { + new_uuid = tmp_uuid.String() + } else { + log.L(`E: `,e) + return e + } + } + + var send_str = `msg[sender_uid]=`+strconv.Itoa(c.Uid)+`&msg[receiver_id]=`+strconv.Itoa(uid)+`&msg[receiver_type]=1&msg[msg_type]=1&msg[msg_status]=0&msg[content]={"content":"`+msg+`"}&msg[timestamp]=`+strconv.Itoa(int(p.Sys().GetSTime()))+`&msg[new_face_version]=0&msg[dev_id]=`+strings.ToUpper(new_uuid)+`&from_firework=0&build=0&mobi_app=web&csrf_token=`+csrf+`&csrf=`+csrf + + req := p.Req() + if e:= req.Reqf(p.Rval{ + Url:`https://api.vc.bilibili.com/web_im/v1/web_im/send_msg`, + PostStr:url.PathEscape(send_str), + Timeout:10, + Header:map[string]string{ + `Host`: `api.vc.bilibili.com`, + `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`, + `Accept`: `application/json, text/javascript, */*; q=0.01`, + `Accept-Language`: `zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2`, + `Accept-Encoding`: `gzip, deflate, br`, + `Content-Type`: `application/x-www-form-urlencoded; charset=UTF-8`, + `Origin`: `https://message.bilibili.com`, + `Connection`: `keep-alive`, + `Pragma`: `no-cache`, + `Cache-Control`: `no-cache`, + `Referer`:"https://message.bilibili.com", + `Cookie`:c.Cookie, + }, + });e != nil { + log.L(`E: `,e) + return e + } + + if code := p.Json().GetValFromS(string(req.Respon), "code");code == nil || code.(float64) != 0 { + log.L(`E: `,string(req.Respon)) + return errors.New(string(req.Respon)) + } + + log.L(`I: `,`发送私信给`,uid,`:`,msg) + return nil +} \ No newline at end of file diff --git a/bili_danmu.go b/bili_danmu.go index 242a602..ae5d03a 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -13,6 +13,7 @@ import ( ws "github.com/qydysky/part/websocket" g "github.com/qydysky/part/get" reply "github.com/qydysky/bili_danmu/Reply" + send "github.com/qydysky/bili_danmu/Send" c "github.com/qydysky/bili_danmu/CV" F "github.com/qydysky/bili_danmu/F" ) @@ -81,6 +82,12 @@ func Demo(roomid ...int) { interrupt <- os.Interrupt return false }, + `pm`:func(data interface{})(bool){//私信 + if tmp,ok := data.(send.Pm_item);ok{ + send.Send_pm(tmp.Uid,tmp.Msg) + } + return false + }, }) <-change_room_chan diff --git a/demo/config/config_K_v.json b/demo/config/config_K_v.json new file mode 100644 index 0000000..5fe663f --- /dev/null +++ b/demo/config/config_K_v.json @@ -0,0 +1,8 @@ +{ + "help":"额外私信对象为0时,所有额外私信都不会触发;私信为空字符串时,不触发", + "额外私信对象":0, + "上舰私信":"", + "上舰私信(额外)":"[弹幕机测试 额外]:感谢上舰", + "弹幕私信":"", + "弹幕私信(额外)":"[弹幕机测试 额外]:弹幕" +} \ No newline at end of file diff --git a/demo/go.mod b/demo/go.mod index fa331e8..95f06be 100644 --- a/demo/go.mod +++ b/demo/go.mod @@ -4,6 +4,7 @@ go 1.14 require ( github.com/christopher-dG/go-obs-websocket v0.0.0-20200720193653-c4fed10356a5 // indirect + github.com/gofrs/uuid v4.0.0+incompatible // indirect github.com/gorilla/websocket v1.4.2 // indirect github.com/gotk3/gotk3 v0.5.2 // indirect github.com/klauspost/compress v1.11.4 // indirect diff --git a/demo/go.sum b/demo/go.sum index 8322422..2574424 100644 --- a/demo/go.sum +++ b/demo/go.sum @@ -9,6 +9,9 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI= github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM= +github.com/gofrs/uuid v1.2.0 h1:coDhrjgyJaglxSjxuJdqQSSdUpG3w6p1OwN2od6frBU= +github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= +github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gopherjs/gopherjs v0.0.0-20190411002643-bd77b112433e h1:XWcjeEtTFTOVA9Fs1w7n2XBftk5ib4oZrhzWk0B+3eA= github.com/gopherjs/gopherjs v0.0.0-20190411002643-bd77b112433e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=