mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-20 06:20:08 +08:00
优化每日随机
This commit is contained in:
parent
a8fba6e7b5
commit
b8a6e07095
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.18
|
|||||||
require (
|
require (
|
||||||
github.com/FloatTech/AnimeAPI v1.3.4-0.20220505052643-ddd1de623794
|
github.com/FloatTech/AnimeAPI v1.3.4-0.20220505052643-ddd1de623794
|
||||||
github.com/FloatTech/sqlite v0.2.1
|
github.com/FloatTech/sqlite v0.2.1
|
||||||
github.com/FloatTech/zbputils v1.3.4-0.20220505052538-84c0e9ec63e9
|
github.com/FloatTech/zbputils v1.3.4-0.20220505053852-f180d4b6dc51
|
||||||
github.com/antchfx/htmlquery v1.2.4
|
github.com/antchfx/htmlquery v1.2.4
|
||||||
github.com/corona10/goimagehash v1.0.3
|
github.com/corona10/goimagehash v1.0.3
|
||||||
github.com/fogleman/gg v1.3.0
|
github.com/fogleman/gg v1.3.0
|
||||||
|
|||||||
4
go.sum
4
go.sum
@ -2,8 +2,8 @@ github.com/FloatTech/AnimeAPI v1.3.4-0.20220505052643-ddd1de623794 h1:oX0/zACMcF
|
|||||||
github.com/FloatTech/AnimeAPI v1.3.4-0.20220505052643-ddd1de623794/go.mod h1:q+7q1hStGYsk69rykzt4h0c9a1EP7cuacazi5jGbPOc=
|
github.com/FloatTech/AnimeAPI v1.3.4-0.20220505052643-ddd1de623794/go.mod h1:q+7q1hStGYsk69rykzt4h0c9a1EP7cuacazi5jGbPOc=
|
||||||
github.com/FloatTech/sqlite v0.2.1 h1:9t6Me48XJJCIoPy4nLRvcdhcVKfT0c2lilp7SEKROG8=
|
github.com/FloatTech/sqlite v0.2.1 h1:9t6Me48XJJCIoPy4nLRvcdhcVKfT0c2lilp7SEKROG8=
|
||||||
github.com/FloatTech/sqlite v0.2.1/go.mod h1:6NfHRzqOo9RWeMJEoAQVuo51Omd5LFNxCNQhMF02/9U=
|
github.com/FloatTech/sqlite v0.2.1/go.mod h1:6NfHRzqOo9RWeMJEoAQVuo51Omd5LFNxCNQhMF02/9U=
|
||||||
github.com/FloatTech/zbputils v1.3.4-0.20220505052538-84c0e9ec63e9 h1:fcUZGApzmSLSF1K8lauouRuYxQjocRYGpLwL3gNG10o=
|
github.com/FloatTech/zbputils v1.3.4-0.20220505053852-f180d4b6dc51 h1:kA7WjNOf6KrmgJ1ZAryREwtkWsBB9BBRzn5LLLZsmlc=
|
||||||
github.com/FloatTech/zbputils v1.3.4-0.20220505052538-84c0e9ec63e9/go.mod h1:yYXxsdc8fouB9yd2XMr17wso2TV0fH1ukARwhV3U43M=
|
github.com/FloatTech/zbputils v1.3.4-0.20220505053852-f180d4b6dc51/go.mod h1:yYXxsdc8fouB9yd2XMr17wso2TV0fH1ukARwhV3U43M=
|
||||||
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
||||||
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c h1:cNPOdTNiVwxLpROLjXCgbIPvdkE+BwvxDvgmdYmWx6Q=
|
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c h1:cNPOdTNiVwxLpROLjXCgbIPvdkE+BwvxDvgmdYmWx6Q=
|
||||||
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c/go.mod h1:KqZzu7slNKROh3TSYEH/IUMG6f4M+1qubZ5e52QypsE=
|
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c/go.mod h1:KqZzu7slNKROh3TSYEH/IUMG6f4M+1qubZ5e52QypsE=
|
||||||
|
|||||||
@ -8,10 +8,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"image"
|
"image"
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/fogleman/gg" // 注册了 jpg png gif
|
"github.com/fogleman/gg" // 注册了 jpg png gif
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -132,19 +130,16 @@ func init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成种子
|
|
||||||
t, _ := strconv.ParseInt(time.Now().Format("20060102"), 10, 64)
|
|
||||||
seed := ctx.Event.UserID + t
|
|
||||||
|
|
||||||
// 随机获取背景
|
// 随机获取背景
|
||||||
background, index, err := randimage(zipfile, seed)
|
background, index, err := randimage(zipfile, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("ERROR:", err))
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 随机获取签文
|
// 随机获取签文
|
||||||
title, text := randtext(seed)
|
randtextindex := ctxext.RandSenderPerDayN(ctx, len(omikujis))
|
||||||
|
title, text := omikujis[randtextindex]["title"], omikujis[randtextindex]["content"]
|
||||||
digest := md5.Sum(helper.StringToBytes(zipfile + strconv.Itoa(index) + title + text))
|
digest := md5.Sum(helper.StringToBytes(zipfile + strconv.Itoa(index) + title + text))
|
||||||
cachefile := cache + hex.EncodeToString(digest[:])
|
cachefile := cache + hex.EncodeToString(digest[:])
|
||||||
|
|
||||||
@ -166,18 +161,16 @@ func init() {
|
|||||||
|
|
||||||
// @function randimage 随机选取zip内的文件
|
// @function randimage 随机选取zip内的文件
|
||||||
// @param path zip路径
|
// @param path zip路径
|
||||||
// @param seed 随机数种子
|
// @param ctx *zero.Ctx
|
||||||
// @return 文件路径 & 错误信息
|
// @return 文件路径 & 错误信息
|
||||||
func randimage(path string, seed int64) (im image.Image, index int, err error) {
|
func randimage(path string, ctx *zero.Ctx) (im image.Image, index int, err error) {
|
||||||
reader, err := zip.OpenReader(path)
|
reader, err := zip.OpenReader(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer reader.Close()
|
defer reader.Close()
|
||||||
|
|
||||||
r := rand.New(rand.NewSource(seed))
|
file := reader.File[ctxext.RandSenderPerDayN(ctx, len(reader.File))]
|
||||||
index = r.Intn(len(reader.File))
|
|
||||||
file := reader.File[index]
|
|
||||||
f, err := file.Open()
|
f, err := file.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -188,16 +181,6 @@ func randimage(path string, seed int64) (im image.Image, index int, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// @function randtext 随机选取签文
|
|
||||||
// @param file 文件路径
|
|
||||||
// @param seed 随机数种子
|
|
||||||
// @return 签名 & 签文 & 错误信息
|
|
||||||
func randtext(seed int64) (string, string) {
|
|
||||||
r := rand.New(rand.NewSource(seed))
|
|
||||||
i := r.Intn(len(omikujis))
|
|
||||||
return omikujis[i]["title"], omikujis[i]["content"]
|
|
||||||
}
|
|
||||||
|
|
||||||
// @function draw 绘制运势图
|
// @function draw 绘制运势图
|
||||||
// @param background 背景图片路径
|
// @param background 背景图片路径
|
||||||
// @param seed 随机数种子
|
// @param seed 随机数种子
|
||||||
|
|||||||
@ -3,11 +3,8 @@ package omikuji
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"math/rand"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||||
@ -29,15 +26,11 @@ func init() { // 插件主体
|
|||||||
|
|
||||||
engine.OnFullMatchGroup([]string{"求签", "占卜"}).SetBlock(true).
|
engine.OnFullMatchGroup([]string{"求签", "占卜"}).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
miku, err := bangoToday(ctx.Event.UserID)
|
i := ctxext.RandSenderPerDayN(ctx, 100) + 1
|
||||||
if err != nil {
|
|
||||||
ctx.SendChain(message.Text("ERROR:", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ctx.SendChain(
|
ctx.SendChain(
|
||||||
message.At(ctx.Event.UserID),
|
message.At(ctx.Event.UserID),
|
||||||
message.Image(fmt.Sprintf(bed, miku, 0)),
|
message.Image(fmt.Sprintf(bed, i, 0)),
|
||||||
message.Image(fmt.Sprintf(bed, miku, 1)),
|
message.Image(fmt.Sprintf(bed, i, 1)),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
engine.OnFullMatch("解签", ctxext.DoOnceOnSuccess(
|
engine.OnFullMatch("解签", ctxext.DoOnceOnSuccess(
|
||||||
@ -58,17 +51,17 @@ func init() { // 插件主体
|
|||||||
ctx.SendChain(message.Text("ERROR:", err))
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
log.Printf("[kuji]读取%d条签文", n)
|
logrus.Infof("[kuji]读取%d条签文", n)
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
)).SetBlock(true).
|
)).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
bg, err := bangoToday(ctx.Event.UserID)
|
kujiBytes, err := text.RenderToBase64(
|
||||||
if err != nil {
|
getKujiByBango(
|
||||||
ctx.SendChain(message.Text("ERROR:", err))
|
uint8(ctxext.RandSenderPerDayN(ctx, 100)+1),
|
||||||
return
|
),
|
||||||
}
|
text.FontFile, 400, 20,
|
||||||
kujiBytes, err := text.RenderToBase64(getKujiByBango(bg), text.FontFile, 400, 20)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("ERROR:", err))
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
return
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
@ -3,12 +3,12 @@ package tarot
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control"
|
"github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/ctxext"
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
)
|
)
|
||||||
@ -49,12 +49,12 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
log.Printf("[tarot]读取%d张塔罗牌", len(cardMap))
|
logrus.Infof("[tarot]读取%d张塔罗牌", len(cardMap))
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||||
i := rand.Intn(22)
|
i := ctxext.RandSenderPerDayN(ctx, 22)
|
||||||
p := rand.Intn(2)
|
p := ctxext.RandSenderPerDayN(ctx, 2)
|
||||||
card := cardMap[(strconv.Itoa(i))]
|
card := cardMap[(strconv.Itoa(i))]
|
||||||
name := card.Name
|
name := card.Name
|
||||||
var info string
|
var info string
|
||||||
@ -67,7 +67,7 @@ func init() {
|
|||||||
message.At(ctx.Event.UserID),
|
message.At(ctx.Event.UserID),
|
||||||
message.Text(reasons[rand.Intn(len(reasons))], position[p], " 的 ", name, "\n"),
|
message.Text(reasons[rand.Intn(len(reasons))], position[p], " 的 ", name, "\n"),
|
||||||
message.Image(fmt.Sprintf(bed+"MajorArcana/%d.png", i)),
|
message.Image(fmt.Sprintf(bed+"MajorArcana/%d.png", i)),
|
||||||
message.Text("\n其意义为:", info),
|
message.Text("\n其意义为: ", info),
|
||||||
); id.ID() == 0 {
|
); id.ID() == 0 {
|
||||||
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user