mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
✏️ 加入 kuji.db
This commit is contained in:
parent
b1852a1de6
commit
f7a3c0e6c6
BIN
data/Omikuji/kuji.db
Normal file
BIN
data/Omikuji/kuji.db
Normal file
Binary file not shown.
@ -1,21 +1,21 @@
|
||||
package omikuji
|
||||
|
||||
import (
|
||||
"github.com/FloatTech/ZeroBot-Plugin/utils/file"
|
||||
"github.com/FloatTech/ZeroBot-Plugin/utils/sql"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/utils/file"
|
||||
"github.com/FloatTech/ZeroBot-Plugin/utils/process"
|
||||
"github.com/FloatTech/ZeroBot-Plugin/utils/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
dbpath = "data/omikuji/"
|
||||
dbfile = dbpath + "signature.db"
|
||||
dburl = "https://codechina.csdn.net/anto_july/bookreview/-/raw/master/signature.db?inline=false"
|
||||
dbpath = "data/Omikuji/"
|
||||
dbfile = dbpath + "kuji.db"
|
||||
dburl = "https://codechina.csdn.net/u011570312/ZeroBot-Plugin/-/raw/master/" + dbfile
|
||||
)
|
||||
|
||||
var db = &sql.Sqlite{DBPath: dbfile}
|
||||
@ -51,15 +51,15 @@ func init() {
|
||||
}
|
||||
}
|
||||
}
|
||||
err := db.Create("signature", &signature{})
|
||||
err := db.Create("kuji", &kuji{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
n, err := db.Count("signature")
|
||||
n, err := db.Count("kuji")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.Printf("[signature]读取%d条签文", n)
|
||||
log.Printf("[kuji]读取%d条签文", n)
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
46
plugin_omikuji/migrate/main.go
Normal file
46
plugin_omikuji/migrate/main.go
Normal file
@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/utils/sql"
|
||||
)
|
||||
|
||||
type signature struct {
|
||||
Id uint64 `db:"id"`
|
||||
Text string `db:"text"`
|
||||
}
|
||||
|
||||
type kuji struct {
|
||||
Id uint8 `db:"id"`
|
||||
Text string `db:"text"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
db := &sql.Sqlite{DBPath: os.Args[1]}
|
||||
newdb := &sql.Sqlite{DBPath: os.Args[2]}
|
||||
err := newdb.Create("kuji", &kuji{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = db.Create("signature", &signature{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(db.Count("signature"))
|
||||
s := &signature{}
|
||||
k := &kuji{}
|
||||
for i := 1; i <= 100; i++ {
|
||||
db.Find("signature", s, "where id = "+strconv.Itoa(i))
|
||||
fmt.Println("insert: ", s.Text[:57])
|
||||
k.Id = uint8(i)
|
||||
k.Text = s.Text
|
||||
newdb.Insert("kuji", k)
|
||||
}
|
||||
|
||||
db.Close()
|
||||
newdb.Close()
|
||||
}
|
||||
@ -2,13 +2,17 @@ package omikuji
|
||||
|
||||
import "strconv"
|
||||
|
||||
type signature struct {
|
||||
Id uint64 `db:"id"`
|
||||
type kuji struct {
|
||||
Id uint8 `db:"id"`
|
||||
Text string `db:"text"`
|
||||
}
|
||||
|
||||
// 返回一个解签
|
||||
func getSignatureById(id int) (s signature) {
|
||||
db.Find("signature", &s, "where id = "+strconv.Itoa(id))
|
||||
return
|
||||
func getKujiByBango(id uint8) string {
|
||||
var s kuji
|
||||
err := db.Find("kuji", &s, "where id = "+strconv.Itoa(int(id)))
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
return s.Text
|
||||
}
|
||||
|
||||
@ -27,37 +27,30 @@ var (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
|
||||
engine.OnFullMatchGroup([]string{"求签", "占卜"}).SetPriority(10).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
userId := ctx.Event.UserID
|
||||
today, err := strconv.ParseInt(time.Now().Format("20060102"), 10, 64)
|
||||
if err != nil {
|
||||
log.Errorln("string转化为int64格式有问题:", err)
|
||||
}
|
||||
seed := userId + today
|
||||
rand.Seed(seed)
|
||||
miku := rand.Intn(100) + 1
|
||||
miku := bangoToday(ctx.Event.UserID)
|
||||
ctx.SendChain(
|
||||
message.At(userId),
|
||||
message.At(ctx.Event.UserID),
|
||||
message.Image(fmt.Sprintf(bed, miku, 0)),
|
||||
message.Image(fmt.Sprintf(bed, miku, 1)),
|
||||
)
|
||||
})
|
||||
engine.OnFullMatchGroup([]string{"解签"}).SetPriority(10).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
userId := ctx.Event.UserID
|
||||
ctx.SendChain(
|
||||
message.At(ctx.Event.UserID),
|
||||
message.Text(getKujiByBango(bangoToday(ctx.Event.UserID))),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
func bangoToday(uid int64) uint8 {
|
||||
today, err := strconv.ParseInt(time.Now().Format("20060102"), 10, 64)
|
||||
if err != nil {
|
||||
log.Errorln("string转化为int64格式有问题:", err)
|
||||
}
|
||||
seed := userId + today
|
||||
rand.Seed(seed)
|
||||
miku := rand.Intn(100) + 1
|
||||
s := getSignatureById(miku)
|
||||
ctx.SendChain(
|
||||
message.At(userId),
|
||||
message.Text(s.Text),
|
||||
)
|
||||
})
|
||||
seed := uid + today
|
||||
r := rand.New(rand.NewSource(seed))
|
||||
return uint8(r.Intn(100) + 1)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user