@@ -17,6 +17,7 @@ import (
1717 "time"
1818
1919 "github.com/Coloured-glaze/gg"
20+ bz "github.com/FloatTech/AnimeAPI/bilibili"
2021 fcext "github.com/FloatTech/floatbox/ctxext"
2122 "github.com/FloatTech/floatbox/file"
2223 "github.com/FloatTech/floatbox/img/writer"
4041 4 : "进入直播间" ,
4142 5 : "标题变动" ,
4243 }
43- cfgFile = "data/Bilibili/config.json"
44- cfg config
44+ cfg = bz .NewCookieConfig ("data/Bilibili/config.json" )
4545)
4646
4747// 查成分的
@@ -73,7 +73,7 @@ func init() {
7373 engine .OnRegex (`^>user info\s?(.{1,25})$` , getPara ).SetBlock (true ).
7474 Handle (func (ctx * zero.Ctx ) {
7575 id := ctx .State ["uid" ].(string )
76- card , err := getMemberCard (id )
76+ card , err := bz . GetMemberCard (id )
7777 if err != nil {
7878 ctx .SendChain (message .Text ("ERROR: " , err ))
7979 return
@@ -92,7 +92,7 @@ func init() {
9292 Handle (func (ctx * zero.Ctx ) {
9393 id := ctx .State ["uid" ].(string )
9494 // 获取详情
95- fo , err := getVtbDetail (id )
95+ fo , err := bz . GetVtbDetail (id )
9696 if err != nil {
9797 ctx .SendChain (message .Text ("ERROR: " , err ))
9898 return
@@ -120,7 +120,7 @@ func init() {
120120 ctx .SendChain (message .Image ("file:///" + file .BOTPATH + "/" + drawedFile ))
121121 return
122122 }
123- u , err := getMemberCard (id )
123+ u , err := bz . GetMemberCard (id )
124124 if err != nil {
125125 ctx .SendChain (message .Text ("ERROR: " , err ))
126126 return
@@ -131,13 +131,13 @@ func init() {
131131 return
132132 }
133133 vupLen := len (vups )
134- medals , err := getMedalwall ( id )
135- sort .Sort (medalSlice (medals ))
134+ medals , err := bz . GetMedalWall ( cfg , id )
135+ sort .Sort (bz . MedalSorter (medals ))
136136 if err != nil {
137137 ctx .SendChain (message .Text ("ERROR: " , err ))
138138 }
139139 frontVups := make ([]vup , 0 )
140- medalMap := make (map [int64 ]medal )
140+ medalMap := make (map [int64 ]bz. Medal )
141141 for _ , v := range medals {
142142 up := vup {
143143 Mid : v .Mid ,
@@ -173,7 +173,7 @@ func init() {
173173 back = img .Size (back , backX , backY ).Im
174174 }
175175 if len (vups ) > 50 {
176- ctx .SendChain (message .Text (u .Name + "关注的up主太多了, 只展示前50个up" ))
176+ ctx .SendChain (message .Text (u .Name + "关注的up主太多了, 只展示前50个up" ))
177177 vups = vups [:50 ]
178178 }
179179 canvas := gg .NewContext (1500 , int (500 * (1.1 + float64 (len (vups ))/ 3 )))
@@ -275,19 +275,19 @@ func init() {
275275 if pagenum == "" {
276276 pagenum = "0"
277277 }
278- u , err := getMemberCard (id )
278+ u , err := bz . GetMemberCard (id )
279279 if err != nil {
280280 ctx .SendChain (message .Text ("ERROR: " , err ))
281281 return
282282 }
283- var danmaku danmakusuki
283+ var danmaku bz. Danmakusuki
284284 tr := & http.Transport {
285285 DisableKeepAlives : true ,
286286 TLSClientConfig : & tls.Config {InsecureSkipVerify : true },
287287 }
288288
289289 client := & http.Client {Transport : tr }
290- data , err := web .RequestDataWith (client , fmt .Sprintf (danmakuAPI , id , pagenum ), "GET" , "" , web .RandUA ())
290+ data , err := web .RequestDataWith (client , fmt .Sprintf (bz . DanmakuAPI , id , pagenum ), "GET" , "" , web .RandUA ())
291291 if err != nil {
292292 ctx .SendChain (message .Text ("ERROR: " , err ))
293293 return
@@ -363,7 +363,7 @@ func init() {
363363 canvas .DrawString (u .Mid , 900 + n , 122.5 )
364364 canvas .DrawString (fmt .Sprintf ("粉丝:%d 关注:%d" , u .Fans , u .Attention ), startWidth , 222.5 )
365365 canvas .DrawString (fmt .Sprintf ("页码:[%d/%d]" , danmaku .Data .PageNum , (danmaku .Data .Total - 1 )/ 5 ), startWidth , 322.5 )
366- canvas .DrawString ("网页链接: " + fmt .Sprintf (danmakuURL , u .Mid ), startWidth , 422.5 )
366+ canvas .DrawString ("网页链接: " + fmt .Sprintf (bz . DanmakuURL , u .Mid ), startWidth , 422.5 )
367367 var channelStart float64
368368 channelStart = float64 (550 )
369369 for i := 0 ; i < len (danmaku .Data .Data ); i ++ {
@@ -527,7 +527,7 @@ func init() {
527527 engine .OnRegex (`^设置b站cookie?\s+(.*)$` , zero .SuperUserPermission ).SetBlock (true ).
528528 Handle (func (ctx * zero.Ctx ) {
529529 cookie := ctx .State ["regex_matched" ].([]string )[1 ]
530- err := setBilibiliCookie (cookie )
530+ err := cfg . Set (cookie )
531531 if err != nil {
532532 ctx .SendChain (message .Text ("ERROR: " , err ))
533533 return
@@ -571,7 +571,7 @@ func int2rbg(t int64) (int64, int64, int64) {
571571func getPara (ctx * zero.Ctx ) bool {
572572 keyword := ctx .State ["regex_matched" ].([]string )[1 ]
573573 if ! re .MatchString (keyword ) {
574- searchRes , err := searchUser ( keyword )
574+ searchRes , err := bz . SearchUser ( cfg , keyword )
575575 if err != nil {
576576 ctx .SendChain (message .Text ("ERROR: " , err ))
577577 return false
@@ -582,7 +582,7 @@ func getPara(ctx *zero.Ctx) bool {
582582 next := zero .NewFutureEvent ("message" , 999 , false , ctx .CheckSession ())
583583 recv , cancel := next .Repeat ()
584584 defer cancel ()
585- ctx .SendChain (message .Text ("输入为纯数字, 请选择查询uid还是用户名, 输入对应序号:\n 0. 查询uid\n 1. 查询用户名" ))
585+ ctx .SendChain (message .Text ("输入为纯数字, 请选择查询uid还是用户名, 输入对应序号:\n 0. 查询uid\n 1. 查询用户名" ))
586586 for {
587587 select {
588588 case <- time .After (time .Second * 10 ):
@@ -604,7 +604,7 @@ func getPara(ctx *zero.Ctx) bool {
604604 ctx .State ["uid" ] = keyword
605605 return true
606606 } else if num == 1 {
607- searchRes , err := searchUser ( keyword )
607+ searchRes , err := bz . SearchUser ( cfg , keyword )
608608 if err != nil {
609609 ctx .SendChain (message .Text ("ERROR: " , err ))
610610 return false
0 commit comments