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