From 7402d875de2c85fc7f26f8aa56b49406bca7bb7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=7E?= <158024940+xyy0411@users.noreply.github.com> Date: Sun, 12 Jan 2025 15:13:12 +0800 Subject: [PATCH 1/3] fix(niu): jj (#66) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add files via upload * 修改jj函数 --- niu/main.go | 40 +++++++++++++++++++++++----------------- niu/models.go | 18 ++++++++---------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/niu/main.go b/niu/main.go index c348061..ec5c7a6 100644 --- a/niu/main.go +++ b/niu/main.go @@ -170,7 +170,7 @@ func HitGlue(gid, uid int64, prop string) (string, error) { return "", ErrNoNiuNiuTwo } - messages, err := niuniu.processNiuNiuAction(prop) + messages, err := niuniu.processDaJiao(prop) if err != nil { return "", err } @@ -213,7 +213,7 @@ func JJ(gid, uid, adduser int64, prop string) (message string, adduserLength flo return "", 0, ErrCannotFight } - message, err = myniuniu.processJJuAction(adduserniuniu, prop) + message, err = myniuniu.processJJ(adduserniuniu, prop) if err != nil { return "", 0, err } @@ -227,6 +227,11 @@ func JJ(gid, uid, adduser int64, prop string) (message string, adduserLength flo } adduserLength = adduserniuniu.Length + + if err = db.setWordNiuNiu(gid, adduserniuniu); err != nil { + return "", 0, err + } + return } @@ -327,39 +332,40 @@ func ShowAuction(gid int64) ([]AuctionInfo, error) { // Auction 购买牛牛 func Auction(gid, uid int64, i int) (string, error) { - auction, err := db.getAllNiuNiuAuction(gid) + infos, err := db.getAllNiuNiuAuction(gid) if err != nil { return "", ErrNoNiuNiuINAuction } - err = wallet.InsertWalletOf(uid, -auction[i].Money) - if err != nil { + index := i - 1 + if err := wallet.InsertWalletOf(uid, -infos[index].Money); err != nil { return "", ErrNoMoney } niu, err := db.getWordNiuNiu(gid, uid) + if err != nil { - niu = &userInfo{ - UID: uid, - } + niu.UID = uid } - niu.Length = auction[i].Length - if auction[i].Money > 500 { + niu.Length = infos[index].Length + + if infos[index].Money >= 500 { niu.WeiGe += 2 - niu.Artifact += 2 + niu.Philter += 2 } - if err = db.setWordNiuNiu(gid, niu); err != nil { + if err = db.deleteNiuNiuAuction(gid, uint(index)); err != nil { return "", err } - err = db.deleteNiuNiuAuction(gid, auction[i].ID) - if err != nil { + + if err = db.setWordNiuNiu(gid, niu); err != nil { return "", err } - if auction[i].Money > 500 { - return fmt.Sprintf("恭喜你购买成功,当前长度为%.2fcm,此次购买将赠送你2个伟哥,2个媚药", - niu.Length), nil + + if infos[index].Money >= 500 { + return fmt.Sprintf("恭喜你购买成功,当前长度为%.2fcm,此次购买将赠送你2个伟哥,2个媚药", niu.Length), nil } + return fmt.Sprintf("恭喜你购买成功,当前长度为%.2fcm", niu.Length), nil } diff --git a/niu/models.go b/niu/models.go index b8f8daa..87db7dc 100644 --- a/niu/models.go +++ b/niu/models.go @@ -268,7 +268,7 @@ func (u *userInfo) purchaseItem(n int) (int, error) { return money, err } -func (u *userInfo) processNiuNiuAction(props string) (string, error) { +func (u *userInfo) processDaJiao(props string) (string, error) { var ( messages string info userInfo @@ -301,7 +301,7 @@ func (u *userInfo) processNiuNiuAction(props string) (string, error) { return messages, err } -func (u *userInfo) processJJuAction(adduserniuniu *userInfo, props string) (string, error) { +func (u *userInfo) processJJ(adduserniuniu *userInfo, props string) (string, error) { var ( fencingResult string f float64 @@ -378,7 +378,8 @@ func (db *model) getAllNiuNiuOfGroup(gid int64) (users, error) { var useras users err := db.sql.FindFor(fmt.Sprintf("%d", gid), &user, "", func() error { - useras = append(useras, &user) + newUser := user + useras = append(useras, &newUser) return nil }) return useras, err @@ -388,25 +389,22 @@ func (db *model) setNiuNiuAuction(gid int64, u *AuctionInfo) error { db.Lock() defer db.Unlock() num, err := db.sql.Count(fmt.Sprintf("auction_%d", gid)) - if err != nil { - num = 1 - } - u.ID = uint(num) - err = db.sql.Insert(fmt.Sprintf("auction_%d", gid), u) if err != nil { err = db.sql.Create(fmt.Sprintf("auction_%d", gid), &AuctionInfo{}) if err != nil { return err } - err = db.sql.Insert(fmt.Sprintf("auction_%d", gid), u) + num = -1 } + u.ID = uint(num + 1) + err = db.sql.Insert(fmt.Sprintf("auction_%d", gid), u) return err } func (db *model) deleteNiuNiuAuction(gid int64, id uint) error { db.Lock() defer db.Unlock() - return db.sql.Del(strconv.FormatInt(gid, 10), "WHERE ID = ?", id) + return db.sql.Del(fmt.Sprintf("auction_%d", gid), "WHERE id = ?", id) } func (db *model) getAllNiuNiuAuction(gid int64) ([]AuctionInfo, error) { From caa5852980c306774d528bd918895415d9e8de38 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 12 Jan 2025 16:15:43 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=8E=A8=20=E6=94=B9=E8=BF=9B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=A0=B7=E5=BC=8F=20(#67)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- niu/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/niu/main.go b/niu/main.go index ec5c7a6..7131b50 100644 --- a/niu/main.go +++ b/niu/main.go @@ -231,7 +231,7 @@ func JJ(gid, uid, adduser int64, prop string) (message string, adduserLength flo if err = db.setWordNiuNiu(gid, adduserniuniu); err != nil { return "", 0, err } - + return } From df647215d1069f278aae316a5d93298183ab6f90 Mon Sep 17 00:00:00 2001 From: vatebur <67186678+vatebur@users.noreply.github.com> Date: Sun, 12 Jan 2025 15:18:24 +0800 Subject: [PATCH 3/3] fix: bilibili API ,Rollback types (#64) --- bilibili/api.go | 6 +-- bilibili/types.go | 119 +++++++--------------------------------------- 2 files changed, 20 insertions(+), 105 deletions(-) diff --git a/bilibili/api.go b/bilibili/api.go index b785479..7101fe5 100644 --- a/bilibili/api.go +++ b/bilibili/api.go @@ -95,7 +95,7 @@ func GetDynamicDetail(cookiecfg *CookieConfig, dynamicIDStr string) (card Dynami // GetMemberCard 获取b站个人详情 func GetMemberCard(uid any) (result MemberCard, err error) { - data, err := web.RequestDataWith(web.NewDefaultClient(), fmt.Sprintf(MemberCardURL, uid), "GET", "", web.RandUA(), nil) + data, err := web.RequestDataWith(web.NewDefaultClient(), fmt.Sprintf(MemberCardURL, uid), "GET", "", ConstUA, nil) if err != nil { return } @@ -157,7 +157,7 @@ func GetAllGuard(mid string) (guardUser GuardUser, err error) { // GetArticleInfo 用id查专栏信息 func GetArticleInfo(id string) (card Card, err error) { var data []byte - data, err = web.GetData(fmt.Sprintf(ArticleInfoURL, id)) + data, err = web.RequestDataWith(web.NewDefaultClient(), fmt.Sprintf(ArticleInfoURL, id), "GET", "", ConstUA, nil) if err != nil { return } @@ -168,7 +168,7 @@ func GetArticleInfo(id string) (card Card, err error) { // GetLiveRoomInfo 用直播间id查直播间信息 func GetLiveRoomInfo(roomID string) (card RoomCard, err error) { var data []byte - data, err = web.GetData(fmt.Sprintf(LiveRoomInfoURL, roomID)) + data, err = web.RequestDataWith(web.NewDefaultClient(), fmt.Sprintf(LiveRoomInfoURL, roomID), "GET", "", ConstUA, nil) if err != nil { return } diff --git a/bilibili/types.go b/bilibili/types.go index 42b1cb1..f135dd4 100644 --- a/bilibili/types.go +++ b/bilibili/types.go @@ -49,6 +49,8 @@ const ( VideoSummaryURL = "https://api.bilibili.com/x/web-interface/view/conclusion/get?bvid=%v&cid=%v&up_mid=%v" // NavURL 导航URL NavURL = "https://api.bilibili.com/x/web-interface/nav" + // ConstUA 浏览器UA + ConstUA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0" ) // DynamicCard 总动态结构体,包括desc,card @@ -198,108 +200,21 @@ type Vote struct { // MemberCard 个人信息卡片 type MemberCard struct { - Code int `json:"code"` - Message string `json:"message"` - TTL int `json:"ttl"` - Data struct { - Card struct { - Mid string `json:"mid"` - Name string `json:"name"` - Approve bool `json:"approve"` - Sex string `json:"sex"` - Rank string `json:"rank"` - Face string `json:"face"` - FaceNft int `json:"face_nft"` - FaceNftType int `json:"face_nft_type"` - DisplayRank string `json:"DisplayRank"` - Regtime int64 `json:"regtime"` - Spacesta int `json:"spacesta"` - Birthday string `json:"birthday"` - Place string `json:"place"` - Description string `json:"description"` - Article int `json:"article"` - Attentions []int64 `json:"attentions"` - Fans int `json:"fans"` - Friend int `json:"friend"` - Attention int `json:"attention"` - Sign string `json:"sign"` - LevelInfo struct { - CurrentLevel int `json:"current_level"` - CurrentMin int `json:"current_min"` - CurrentExp int `json:"current_exp"` - NextExp int `json:"next_exp"` - } `json:"level_info"` - Pendant struct { - Pid int `json:"pid"` - Name string `json:"name"` - Image string `json:"image"` - Expire int `json:"expire"` - ImageEnhance string `json:"image_enhance"` - ImageEnhanceFrame string `json:"image_enhance_frame"` - NPid int `json:"n_pid"` - } `json:"pendant"` - Nameplate struct { - Nid int `json:"nid"` - Name string `json:"name"` - Image string `json:"image"` - ImageSmall string `json:"image_small"` - Level string `json:"level"` - Condition string `json:"condition"` - } `json:"nameplate"` - Official struct { - Role int `json:"role"` - Title string `json:"title"` - Desc string `json:"desc"` - Type int `json:"type"` - } `json:"Official"` - OfficialVerify struct { - Type int `json:"type"` - Desc string `json:"desc"` - } `json:"official_verify"` - Vip struct { - Type int `json:"type"` - Status int `json:"status"` - DueDate int64 `json:"due_date"` - VipPayType int `json:"vip_pay_type"` - ThemeType int `json:"theme_type"` - Label struct { - Path string `json:"path"` - Text string `json:"text"` - LabelTheme string `json:"label_theme"` - TextColor string `json:"text_color"` - BgStyle int `json:"bg_style"` - BgColor string `json:"bg_color"` - BorderColor string `json:"border_color"` - UseImgLabel bool `json:"use_img_label"` - ImgLabelURIHans string `json:"img_label_uri_hans"` - ImgLabelURIHant string `json:"img_label_uri_hant"` - ImgLabelURIHansStatic string `json:"img_label_uri_hans_static"` - ImgLabelURIHantStatic string `json:"img_label_uri_hant_static"` - } `json:"label"` - AvatarSubscript int `json:"avatar_subscript"` - NicknameColor string `json:"nickname_color"` - Role int `json:"role"` - AvatarSubscriptURL string `json:"avatar_subscript_url"` - TvVipStatus int `json:"tv_vip_status"` - TvVipPayType int `json:"tv_vip_pay_type"` - TvDueDate int `json:"tv_due_date"` - AvatarIcon struct { - IconType int `json:"icon_type"` - IconResource struct { - } `json:"icon_resource"` - } `json:"avatar_icon"` - VipType int `json:"vipType"` - VipStatus int `json:"vipStatus"` - } `json:"vip"` - IsSeniorMember int `json:"is_senior_member"` - NameRender interface{} `json:"name_render"` - } `json:"card"` - Following bool `json:"following"` - ArchiveCount int `json:"archive_count"` - ArticleCount int `json:"article_count"` - Follower int `json:"follower"` - LikeNum int `json:"like_num"` - } `json:"data"` + Mid string `json:"mid"` + Name string `json:"name"` + Sex string `json:"sex"` + Face string `json:"face"` + Coins float64 `json:"coins"` + Regtime int64 `json:"regtime"` + Birthday string `json:"birthday"` + Sign string `json:"sign"` + Attentions []int64 `json:"attentions"` + Fans int `json:"fans"` + Friend int `json:"friend"` + Attention int `json:"attention"` + LevelInfo struct { + CurrentLevel int `json:"current_level"` + } `json:"level_info"` } // RoomCard 直播间卡片