mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-26 03:21:21 +08:00
🎨 🔥 统一 seed
This commit is contained in:
parent
3838d74cb8
commit
bd6925f2f1
3
main.go
3
main.go
@ -3,8 +3,10 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
// ---------以下插件均可通过前面加 // 注释,注释后停用并不加载插件--------- //
|
||||
// ----------------------插件优先级按顺序从高到低---------------------- //
|
||||
@ -220,6 +222,7 @@ func getKanban() string {
|
||||
func main() {
|
||||
order.Wait()
|
||||
printBanner()
|
||||
rand.Seed(time.Now().UnixNano()) // 全局 seed,其他插件无需再 seed
|
||||
// 帮助
|
||||
zero.OnFullMatchGroup([]string{"/help", ".help", "菜单"}, zero.OnlyToMe).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
|
||||
@ -4,7 +4,6 @@ package aiwife
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
control "github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
@ -19,7 +18,6 @@ const (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
control.Register("aiwife", order.AcquirePrio(), &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "AIWife\n" +
|
||||
|
||||
@ -2,9 +2,6 @@
|
||||
package diana
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
@ -36,7 +33,6 @@ func init() {
|
||||
// 随机发送一篇上面的小作文
|
||||
engine.OnFullMatch("小作文").SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
// 绕过第一行发病
|
||||
ctx.SendChain(message.Text(data.RandText()))
|
||||
})
|
||||
|
||||
@ -188,8 +188,8 @@ func randimage(path string, seed int64) (im image.Image, index int, err error) {
|
||||
}
|
||||
defer reader.Close()
|
||||
|
||||
rand.Seed(seed)
|
||||
index = rand.Intn(len(reader.File))
|
||||
r := rand.New(rand.NewSource(seed))
|
||||
index = r.Intn(len(reader.File))
|
||||
file := reader.File[index]
|
||||
f, err := file.Open()
|
||||
if err != nil {
|
||||
@ -206,9 +206,9 @@ func randimage(path string, seed int64) (im image.Image, index int, err error) {
|
||||
// @param seed 随机数种子
|
||||
// @return 签名 & 签文 & 错误信息
|
||||
func randtext(seed int64) (string, string) {
|
||||
rand.Seed(seed)
|
||||
r := rand.Intn(len(omikujis))
|
||||
return omikujis[r]["title"], omikujis[r]["content"]
|
||||
r := rand.New(rand.NewSource(seed))
|
||||
i := r.Intn(len(omikujis))
|
||||
return omikujis[i]["title"], omikujis[i]["content"]
|
||||
}
|
||||
|
||||
// @function draw 绘制运势图
|
||||
|
||||
@ -2,11 +2,9 @@
|
||||
package gif
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
control "github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
@ -24,7 +22,6 @@ var (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
rand.Seed(time.Now().UnixNano()) // 设置种子
|
||||
en := control.Register("gif", order.AcquirePrio(), &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "制图\n- " + strings.Join(cmds, "\n- "),
|
||||
|
||||
@ -342,7 +342,6 @@ func init() { // 插件主体
|
||||
return temp[i].Get("last_sent_time").Int() < temp[j].Get("last_sent_time").Int()
|
||||
})
|
||||
temp = temp[math.Max(0, len(temp)-10):]
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
who := temp[rand.Intn(len(temp))]
|
||||
if who.Get("user_id").Int() == ctx.Event.SelfID {
|
||||
ctx.SendChain(message.Text("幸运儿居然是我自己"))
|
||||
|
||||
@ -8,7 +8,6 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/FloatTech/zbputils/web"
|
||||
"github.com/jinzhu/gorm"
|
||||
@ -160,7 +159,6 @@ func (vdb *VtbDB) GetThirdCategory(firstIndex, secondIndex, thirdIndex int) Thir
|
||||
// RandomVtb ...
|
||||
func (vdb *VtbDB) RandomVtb() ThirdCategory {
|
||||
db := (*gorm.DB)(vdb)
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
var count int
|
||||
var tc ThirdCategory
|
||||
db.Model(&ThirdCategory{}).Count(&count).Offset(rand.Intn(count)).Take(&tc)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user