mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-12 10:10:25 +00:00
优化每日随机
This commit is contained in:
@@ -3,11 +3,8 @@ package omikuji
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||
@@ -29,15 +26,11 @@ func init() { // 插件主体
|
||||
|
||||
engine.OnFullMatchGroup([]string{"求签", "占卜"}).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
miku, err := bangoToday(ctx.Event.UserID)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
i := ctxext.RandSenderPerDayN(ctx, 100) + 1
|
||||
ctx.SendChain(
|
||||
message.At(ctx.Event.UserID),
|
||||
message.Image(fmt.Sprintf(bed, miku, 0)),
|
||||
message.Image(fmt.Sprintf(bed, miku, 1)),
|
||||
message.Image(fmt.Sprintf(bed, i, 0)),
|
||||
message.Image(fmt.Sprintf(bed, i, 1)),
|
||||
)
|
||||
})
|
||||
engine.OnFullMatch("解签", ctxext.DoOnceOnSuccess(
|
||||
@@ -58,17 +51,17 @@ func init() { // 插件主体
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return false
|
||||
}
|
||||
log.Printf("[kuji]读取%d条签文", n)
|
||||
logrus.Infof("[kuji]读取%d条签文", n)
|
||||
return true
|
||||
},
|
||||
)).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
bg, err := bangoToday(ctx.Event.UserID)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
kujiBytes, err := text.RenderToBase64(getKujiByBango(bg), text.FontFile, 400, 20)
|
||||
kujiBytes, err := text.RenderToBase64(
|
||||
getKujiByBango(
|
||||
uint8(ctxext.RandSenderPerDayN(ctx, 100)+1),
|
||||
),
|
||||
text.FontFile, 400, 20,
|
||||
)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
@@ -78,13 +71,3 @@ func init() { // 插件主体
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func bangoToday(uid int64) (uint8, error) {
|
||||
today, err := strconv.ParseInt(time.Now().Format("20060102"), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
seed := uid + today
|
||||
r := rand.New(rand.NewSource(seed))
|
||||
return uint8(r.Intn(100) + 1), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user