Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:修复直播状态更新的bug #107

Merged
merged 23 commits into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions plugin_bilibili_push/bilibili_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ import (
)

const (
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"
referer = "https://www.bilibili.com/"
infoURL = "https://api.bilibili.com/x/space/acc/info?mid=%d"
userDynamicsURL = "https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?host_uid=%d&offset_dynamic_id=0&need_top=0"
liveListURL = "https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids"
tURL = "https://t.bilibili.com/"
liveURL = "https://live.bilibili.com/"
prio = 10
serviceName = "bilibilipush"
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"
referer = "https://www.bilibili.com/"
infoURL = "https://api.bilibili.com/x/space/acc/info?mid=%d"
userDynamicURL = "https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?host_uid=%d&offset_dynamic_id=0&need_top=0"
liveListURL = "https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids"
tURL = "https://t.bilibili.com/"
liveURL = "https://live.bilibili.com/"
prio = 10
serviceName = "bilibilipush"
)

var (
Expand Down Expand Up @@ -281,7 +281,7 @@ func unsubscribeLive(buid, groupid int64) (err error) {
}

func getUserDynamicCard(buid int64) (cardList []gjson.Result) {
data, err := web.ReqWith(fmt.Sprintf(userDynamicsURL, buid), "GET", referer, ua)
data, err := web.ReqWith(fmt.Sprintf(userDynamicURL, buid), "GET", referer, ua)
if err != nil {
log.Errorln("[bilibilipush]:", err)
}
Expand Down Expand Up @@ -345,11 +345,12 @@ func sendDynamic() {
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
for _, gid := range groupList {
if m.IsEnabledIn(gid) {
if gid > 0 {
switch {
case gid > 0:
ctx.SendGroupMessage(gid, msg)
} else if gid < 0 {
case gid < 0:
ctx.SendPrivateMessage(-gid, msg)
} else {
default:
log.Errorln("[bilibilipush]:gid为0")
}
}
Expand Down Expand Up @@ -398,18 +399,21 @@ func sendLive() {
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
for _, gid := range groupList {
if m.IsEnabledIn(gid) {
if gid > 0 {
switch {
case gid > 0:
ctx.SendGroupMessage(gid, msg)
} else if gid < 0 {
case gid < 0:
ctx.SendPrivateMessage(-gid, msg)
} else {
default:
log.Errorln("[bilibilipush]:gid为0")
}
}
}
return true
})
}
} else if newStatus != oldStatus {
liveStatus[key.Int()] = newStatus
}
return true
})
Expand Down
15 changes: 0 additions & 15 deletions plugin_bilibili_push/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,6 @@ func initialize(dbpath string) *bilibilipushdb {
return (*bilibilipushdb)(gdb)
}

// open ...
func open(dbpath string) (*bilibilipushdb, error) {
db, err := gorm.Open("sqlite3", dbpath)
if err != nil {
return nil, err
}
return (*bilibilipushdb)(db), nil
}

// close ...
func (bdb *bilibilipushdb) close() error {
db := (*gorm.DB)(bdb)
return db.Close()
}

// insertOrUpdateLiveAndDynamic 插入或更新数据库
func (bdb *bilibilipushdb) insertOrUpdateLiveAndDynamic(bpMap map[string]interface{}) (err error) {
db := (*gorm.DB)(bdb)
Expand Down