mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
用结果数组的长度作为随机数最大值、防止越界
This commit is contained in:
parent
e667fb8708
commit
217fa62004
@ -70,7 +70,7 @@ func init() {
|
|||||||
keyword := ctx.State["regex_matched"].([]string)[1]
|
keyword := ctx.State["regex_matched"].([]string)[1]
|
||||||
soutujson := soutuapi(keyword)
|
soutujson := soutuapi(keyword)
|
||||||
pom1 := "https://i.pixiv.cat"
|
pom1 := "https://i.pixiv.cat"
|
||||||
rannum := randint()
|
rannum := randint(len(soutujson.Illusts))
|
||||||
pom2 := soutujson.Illusts[rannum].ImageUrls.Large[19:]
|
pom2 := soutujson.Illusts[rannum].ImageUrls.Large[19:]
|
||||||
ctx.SendChain(message.Image(pom1 + pom2))
|
ctx.SendChain(message.Image(pom1 + pom2))
|
||||||
})
|
})
|
||||||
@ -103,7 +103,7 @@ func soutuapi(keyword string) *resultjson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// randint 从json里的30条数据中随机获取一条返回
|
// randint 从json里的30条数据中随机获取一条返回
|
||||||
func randint() int {
|
func randint(len int) int {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
return rand.Intn(30)
|
return rand.Intn(len)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user