From: qydysky Date: Fri, 5 Mar 2021 16:37:41 +0000 (+0800) Subject: 银瓜子礼物自动赠送 X-Git-Tag: v0.5.8~1^2~24 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=794dd9e5dfddd64bd4a94cdcb299fe35198067d1;p=bili_danmu%2F.git 银瓜子礼物自动赠送 --- diff --git a/CV/Var.go b/CV/Var.go index 5c3ff0c..bdfd635 100644 --- a/CV/Var.go +++ b/CV/Var.go @@ -18,6 +18,7 @@ var ( Cookie syncmap.Map Title string//直播标题 Uname string//主播名 + UpUid int//主播uid Rev float64//营收 Renqi int//人气 GuardNum int//舰长数 diff --git a/F/api.go b/F/api.go index e75fd7d..4b58d14 100644 --- a/F/api.go +++ b/F/api.go @@ -34,7 +34,7 @@ type api struct { } var apilog = c.Log.Base(`api`) -var api_limit = p.Limit(1,2000,15000)//频率限制1次/2s,最大等待时间15s +var api_limit = p.Limit(1,2000,30000)//频率限制1次/2s,最大等待时间30s func New_api(Roomid int) (o *api) { apilog.Base_add(`新建`).L(`T: `,"ok") @@ -70,6 +70,7 @@ func (i *api) Get_info() (o *api) { apilog.L(`E: `,"uid", err) } else { o.Uid = i + c.UpUid = i } //Title if e := r.S(`"title":"`, `",`, 0, 0).Err;e == nil { @@ -163,6 +164,7 @@ func (i *api) Get_info() (o *api) { //主播id if tmp.Data.Room_info.Uid != 0{ o.Uid = tmp.Data.Room_info.Uid + c.UpUid = tmp.Data.Room_info.Uid } else { apilog.L(`W: `,"data.room_info.Uid = 0") return @@ -1558,7 +1560,9 @@ type Gift_list_type_Data struct { } type Gift_list_type_Data_List struct{ + Bag_id int `json:"bag_id"` Gift_id int `json:"gift_id"` + Gift_name string `json:"gift_name"` Gift_num int `json:"gift_num"` Expire_at int `json:"expire_at"` } diff --git a/Reply/F.go b/Reply/F.go index 5f7c314..542955a 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -784,4 +784,21 @@ func Keep_medal_light() { time.Sleep(time.Second) } flog.L(`I: `,`完成`) +} + +//自动发送即将过期的银瓜子礼物 +func AutoSend_silver_gift() { + day,_ := c.K_v.LoadV(`发送还有几天过期的礼物`).(float64) + if day <= 0 { + return + } + + flog := flog.Base_add(`自动送礼`).L(`T: `,`自动送礼`) + + for _,v := range F.Gift_list() { + if time.Now().Add(time.Hour * time.Duration(24 * int(day))).Unix() > int64(v.Expire_at) { + send.Send_gift(v.Gift_id, v.Bag_id, v.Gift_num) + } + } + flog.L(`T: `,`完成`) } \ No newline at end of file diff --git a/Send/README.md b/Send/README.md index 60f1f2c..f1fda92 100644 --- a/Send/README.md +++ b/Send/README.md @@ -6,4 +6,5 @@ |./|发送数据区| |Send.go|弹幕发送| |Send_pm.go|私信发送| +|Send_gift.go|礼物发送| --- \ No newline at end of file diff --git a/Send/Send_gift.go b/Send/Send_gift.go index 521a7a5..5fac6f6 100644 --- a/Send/Send_gift.go +++ b/Send/Send_gift.go @@ -1,260 +1,94 @@ package send -func Send_gift(){ - {//参数来源1 - //https://api.live.bilibili.com/xlive/web-room/v1/gift/bag_list?t=1614667412767&room_id=22347054 +import ( + "time" + "net/url" + "encoding/json" + "strconv" + + p "github.com/qydysky/part" + c "github.com/qydysky/bili_danmu/CV" +) + +//每2s一个令牌,最多等10秒 +var gift_limit = p.Limit(1, 2000, 10000) + +func Send_gift(gift_id,bag_id,gift_num int) { + log := c.Log.Base_add(`发送礼物`) + + if gift_limit.TO() {log.L(`W: `,"超时");return} - /* - { - "code": 0, - "message": "0", - "ttl": 1, - "data": { - "list": [ - { - "bag_id": 235312419, - "gift_id": 1, - "gift_name": "辣条", - "gift_num": 1, - "gift_type": 5, - "expire_at": 1614700800, - "corner_mark": "1天", - "corner_color": "", - "count_map": [ - { - "num": 1, - "text": "" - } - ], - "bind_roomid": 0, - "bind_room_text": "", - "type": 1, - "card_image": "", - "card_gif": "", - "card_id": 0, - "card_record_id": 0, - "is_show_send": false - }, - { - "bag_id": 235157184, - "gift_id": 30607, - "gift_name": "小心心", - "gift_num": 16, - "gift_type": 5, - "expire_at": 1615046400, - "corner_mark": "5天", - "corner_color": "", - "count_map": [ - { - "num": 1, - "text": "" - }, - { - "num": 16, - "text": "全部" - } - ], - "bind_roomid": 0, - "bind_room_text": "", - "type": 1, - "card_image": "", - "card_gif": "", - "card_id": 0, - "card_record_id": 0, - "is_show_send": false - }, - { - "bag_id": 235162609, - "gift_id": 30607, - "gift_name": "小心心", - "gift_num": 24, - "gift_type": 5, - "expire_at": 1615132800, - "corner_mark": "6天", - "corner_color": "", - "count_map": [ - { - "num": 1, - "text": "" - }, - { - "num": 24, - "text": "全部" - } - ], - "bind_roomid": 0, - "bind_room_text": "", - "type": 1, - "card_image": "", - "card_gif": "", - "card_id": 0, - "card_record_id": 0, - "is_show_send": false - }, - { - "bag_id": 235077495, - "gift_id": 1, - "gift_name": "辣条", - "gift_num": 20, - "gift_type": 5, - "expire_at": 1615132800, - "corner_mark": "6天", - "corner_color": "", - "count_map": [ - { - "num": 1, - "text": "" - }, - { - "num": 20, - "text": "全部" - } - ], - "bind_roomid": 0, - "bind_room_text": "", - "type": 1, - "card_image": "", - "card_gif": "", - "card_id": 0, - "card_record_id": 0, - "is_show_send": false - }, - { - "bag_id": 235282499, - "gift_id": 30607, - "gift_name": "小心心", - "gift_num": 3, - "gift_type": 5, - "expire_at": 1615219200, - "corner_mark": "7天", - "corner_color": "", - "count_map": [ - { - "num": 1, - "text": "" - }, - { - "num": 3, - "text": "全部" - } - ], - "bind_roomid": 0, - "bind_room_text": "", - "type": 1, - "card_image": "", - "card_gif": "", - "card_id": 0, - "card_record_id": 0, - "is_show_send": false - } - ], - "time": 0 - } - } - */ - } {//发送请求(银瓜子礼物) - //https://api.live.bilibili.com/gift/v2/live/bag_send + csrf := c.Cookie.LoadV(`bili_jct`).(string) + if csrf == `` {log.L(`E: `,"Cookie错误,无bili_jct=");return} - // req - // { - // "uid": "29183321",//客户uid - // "gift_id": "1",//礼物id from 1 - // "ruid": "623441612",//主播uid - // "send_ruid": "0",//固定值 - // "gift_num": "1",//发送数量 from 1 - // "bag_id": "235312419",//礼物包 from 1 - // "platform": "pc",//平台固定值 - // "biz_code": "live",//固定值 - // "biz_id": "22347054",//房间id - // "rnd": "1614667054",//时间戳 - // "storm_beat_id": "0",//固定值 - // "metadata": "",//固定值 - // "price": "0",//价值 - // "csrf_token": "××",//from cookie - // "csrf": "××",//from cookie - // "visit_id": ""//固定值 - // } + var sendStr = + `uid=`+strconv.Itoa(c.Uid)+`&`+ + `gift_id=`+strconv.Itoa(gift_id)+`&`+ + `ruid=`+strconv.Itoa(c.UpUid)+`&`+ + `send_ruid=0&`+ + `gift_num=`+strconv.Itoa(gift_num)+`&`+ + `coin_type=silver&`+ + `bag_id=`+strconv.Itoa(bag_id)+`&`+ + `platform=pc&`+ + `biz_code=live&`+ + `biz_id=`+strconv.Itoa(c.Roomid)+`&`+ + `rnd=`+strconv.Itoa(int(time.Now().Unix()))+`&`+ + `storm_beat_id=0&`+ + `metadata=&`+ + `price=0&`+ + `csrf_token=`+csrf+`&`+ + `csrf=`+csrf+`&`+ + `visit_id=` - // res - // { - // "code": 0, - // "msg": "success", - // "message": "success", - // "data": { - // "tid": "1614667076110100001", - // "uid": 29183321, - // "uname": "qydysky丶", - // "face": "https://i2.hdslb.com/bfs/face/8c6d1ce3f96dc86d0fc7876a2824910c92ae6802.jpg", - // "guard_level": 0, - // "ruid": 623441612, - // "rcost": 18194089, - // "gift_id": 1, - // "gift_type": 5, - // "gift_name": "辣条", - // "gift_num": 1, - // "gift_action": "投喂", - // "gift_price": 100, - // "coin_type": "silver", - // "total_coin": 100, - // "pay_coin": 100, - // "metadata": "", - // "fulltext": "", - // "rnd": "1614667054", - // "tag_image": "", - // "effect_block": 1, - // "extra": { - // "wallet": null, - // "gift_bag": { - // "bag_id": 235312419, - // "gift_num": 1 - // }, - // "top_list": [], - // "follow": null, - // "medal": null, - // "title": null, - // "pk": { - // "pk_gift_tips": "", - // "crit_prob": -1 - // }, - // "fulltext": "", - // "event": { - // "event_score": 0, - // "event_redbag_num": 0 - // }, - // "capsule": null, - // "lottery_id": "" - // }, - // "blow_switch": 0, - // "send_tips": "赠送成功", - // "discount_id": 0, - // "gift_effect": { - // "super": 0, - // "combo_timeout": 0, - // "super_gift_num": 0, - // "super_batch_gift_num": 0, - // "batch_combo_id": "", - // "broadcast_msg_list": [], - // "small_tv_list": [], - // "beat_storm": null, - // "combo_id": "", - // "smallTVCountFlag": true - // }, - // "send_master": null, - // "crit_prob": -1, - // "combo_stay_time": 3, - // "combo_total_coin": 0, - // "demarcation": 1, - // "magnification": 1, - // "combo_resources_id": 1, - // "is_special_batch": 0, - // "send_gift_countdown": 6, - // "bp_cent_balance": 0, - // "price": 0, - // "left_num": 0, - // "need_num": 0, - // "available_num": 0 - // } - // } + Cookie := make(map[string]string) + c.Cookie.Range(func(k,v interface{})(bool){ + Cookie[k.(string)] = v.(string) + return true + }) + + req := p.Req() + if e:= req.Reqf(p.Rval{ + Url:`https://api.live.bilibili.com/gift/v2/Live/send`, + PostStr:url.PathEscape(sendStr), + 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`:p.Map_2_Cookies_String(Cookie), + }, + });e != nil { + log.L(`E: `,e) + return + } + + var res struct{ + Code int `json:"code"` + Message string `json:"message"` + Data struct{ + Gift_name string `json:"gift_name"` + Gift_num int `json:"gift_num"` + } `json:"data"` + } + + if e := json.Unmarshal(req.Respon, &res);e != nil { + log.L(`E: `,e) + return + } + + if res.Code != 0 { + log.L(`W: `,res.Message) + return + } + log.L(`I: `,`给`,c.Roomid,`赠送了`,res.Data.Gift_num,`个`,res.Data.Gift_name) } } diff --git a/bili_danmu.go b/bili_danmu.go index df0bfcb..21e9904 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -265,6 +265,8 @@ func Demo(roomid ...int) { go reply.Entry_danmu() //附加功能 保持牌子点亮 go reply.Keep_medal_light() + //附加功能 自动发送即将过期礼物 + go reply.AutoSend_silver_gift() return false }, }) @@ -285,6 +287,8 @@ func Demo(roomid ...int) { go reply.ShowRevf() //附加功能 保持牌子点亮 go reply.Keep_medal_light() + //附加功能 自动发送即将过期礼物 + go reply.AutoSend_silver_gift() } }() } diff --git a/demo/config/config_K_v.json b/demo/config/config_K_v.json index c40db6b..ca83c4a 100644 --- a/demo/config/config_K_v.json +++ b/demo/config/config_K_v.json @@ -31,6 +31,7 @@ "进房弹幕_仅发首日弹幕":true, "其他":"", + "发送还有几天过期的礼物":3, "保持所有牌子亮着":true, "扫码登录自动打开标签页":true, "日志显示":["T: ","I: ","W: ","E: "],