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
+ }
+}
//Msg类型数据处理方法map
var Msg_map = map[string]func(replyF, string) {
+ `CARD_MSG`:nil,//提示关注
`LIVE_INTERACTIVE_GAME`:nil,
`WIDGET_BANNER`:nil,//每日任务
`ROOM_ADMINS`:nil,//房管列表
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"
)
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");
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...)
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)
}
//弹幕显示
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)
--- /dev/null
+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
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"
)
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
--- /dev/null
+{
+ "help":"额外私信对象为0时,所有额外私信都不会触发;私信为空字符串时,不触发",
+ "额外私信对象":0,
+ "上舰私信":"",
+ "上舰私信(额外)":"[弹幕机测试 额外]:感谢上舰",
+ "弹幕私信":"",
+ "弹幕私信(额外)":"[弹幕机测试 额外]:弹幕"
+}
\ No newline at end of file
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
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=