Skip to content

Commit f8df60f

Browse files
guohuiyuanGuohuiyuan
andauthored
fix:修复直播状态更新的bug (#107)
* feat:添加b站推送,写了一半 * feat:添加b站推送(后续看情况,替换掉chromepd) * fix:修复一直推送直播的bug * fix:添加缓存路径 * feat:添加推送列表,修复重复发消息的bug * feat:发现禁用有用,删除多余指令 * fix:修改格式 * fix:sleep无效 * fix:修改直播card * fix:增加长度 * fix:修改readme * fix:修lint,并去掉cron * fix:修lint * fix:去掉日志 * fix:更新旧状态 * fix:删掉多余方法 * fix:优化判断语句 * fix:修lint Co-authored-by: Guohuiyuan <[email protected]>
1 parent 9bd0ed0 commit f8df60f

File tree

2 files changed

+20
-31
lines changed

2 files changed

+20
-31
lines changed

plugin_bilibili_push/bilibili_push.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ import (
2626
)
2727

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

4040
var (
@@ -281,7 +281,7 @@ func unsubscribeLive(buid, groupid int64) (err error) {
281281
}
282282

283283
func getUserDynamicCard(buid int64) (cardList []gjson.Result) {
284-
data, err := web.ReqWith(fmt.Sprintf(userDynamicsURL, buid), "GET", referer, ua)
284+
data, err := web.ReqWith(fmt.Sprintf(userDynamicURL, buid), "GET", referer, ua)
285285
if err != nil {
286286
log.Errorln("[bilibilipush]:", err)
287287
}
@@ -345,11 +345,12 @@ func sendDynamic() {
345345
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
346346
for _, gid := range groupList {
347347
if m.IsEnabledIn(gid) {
348-
if gid > 0 {
348+
switch {
349+
case gid > 0:
349350
ctx.SendGroupMessage(gid, msg)
350-
} else if gid < 0 {
351+
case gid < 0:
351352
ctx.SendPrivateMessage(-gid, msg)
352-
} else {
353+
default:
353354
log.Errorln("[bilibilipush]:gid为0")
354355
}
355356
}
@@ -398,18 +399,21 @@ func sendLive() {
398399
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
399400
for _, gid := range groupList {
400401
if m.IsEnabledIn(gid) {
401-
if gid > 0 {
402+
switch {
403+
case gid > 0:
402404
ctx.SendGroupMessage(gid, msg)
403-
} else if gid < 0 {
405+
case gid < 0:
404406
ctx.SendPrivateMessage(-gid, msg)
405-
} else {
407+
default:
406408
log.Errorln("[bilibilipush]:gid为0")
407409
}
408410
}
409411
}
410412
return true
411413
})
412414
}
415+
} else if newStatus != oldStatus {
416+
liveStatus[key.Int()] = newStatus
413417
}
414418
return true
415419
})

plugin_bilibili_push/model.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,6 @@ func initialize(dbpath string) *bilibilipushdb {
5353
return (*bilibilipushdb)(gdb)
5454
}
5555

56-
// open ...
57-
func open(dbpath string) (*bilibilipushdb, error) {
58-
db, err := gorm.Open("sqlite3", dbpath)
59-
if err != nil {
60-
return nil, err
61-
}
62-
return (*bilibilipushdb)(db), nil
63-
}
64-
65-
// close ...
66-
func (bdb *bilibilipushdb) close() error {
67-
db := (*gorm.DB)(bdb)
68-
return db.Close()
69-
}
70-
7156
// insertOrUpdateLiveAndDynamic 插入或更新数据库
7257
func (bdb *bilibilipushdb) insertOrUpdateLiveAndDynamic(bpMap map[string]interface{}) (err error) {
7358
db := (*gorm.DB)(bdb)

0 commit comments

Comments
 (0)