mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
✏️ drop pb in fortune
This commit is contained in:
parent
4c1926e395
commit
65f9203597
@ -1,5 +0,0 @@
|
|||||||
package fortune
|
|
||||||
|
|
||||||
type Conf struct {
|
|
||||||
Kind map[int64]uint32 `protobuf:"bytes,1,rep" protobuf_key:"varint,1,opt" protobuf_val:"varint,0,opt"`
|
|
||||||
}
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
package fortune
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
io "io"
|
|
||||||
"os"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/RomiChan/protobuf/proto"
|
|
||||||
|
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/utils/file"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
conf Conf
|
|
||||||
mu sync.Mutex
|
|
||||||
)
|
|
||||||
|
|
||||||
func loadcfg(name string) error {
|
|
||||||
name = base + name
|
|
||||||
if file.IsExist(name) {
|
|
||||||
f, err := os.Open(name)
|
|
||||||
if err == nil {
|
|
||||||
defer f.Close()
|
|
||||||
data, err1 := io.ReadAll(f)
|
|
||||||
if err1 == nil {
|
|
||||||
if len(data) > 0 {
|
|
||||||
return proto.Unmarshal(data, &conf)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err1
|
|
||||||
}
|
|
||||||
} else { // 如果没有 cfg,则使用空 map
|
|
||||||
conf.Kind = make(map[int64]uint32)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func savecfg(name string) error {
|
|
||||||
name = base + name
|
|
||||||
data, err := proto.Marshal(&conf)
|
|
||||||
if err == nil {
|
|
||||||
if file.IsExist(base) {
|
|
||||||
f, err1 := os.OpenFile(name, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
|
|
||||||
if err1 == nil {
|
|
||||||
mu.Lock()
|
|
||||||
_, err2 := f.Write(data)
|
|
||||||
f.Close()
|
|
||||||
mu.Unlock()
|
|
||||||
return err2
|
|
||||||
}
|
|
||||||
return err1
|
|
||||||
}
|
|
||||||
return errors.New("base dir is not exist")
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
@ -35,20 +35,16 @@ var (
|
|||||||
// 公主连结 原神 明日方舟 碧蓝航线 碧蓝幻想 战双 阴阳师
|
// 公主连结 原神 明日方舟 碧蓝航线 碧蓝幻想 战双 阴阳师
|
||||||
table = [...]string{"车万", "DC4", "爱因斯坦", "星空列车", "樱云之恋", "富婆妹", "李清歌", "公主连结", "原神", "明日方舟", "碧蓝航线", "碧蓝幻想", "战双", "阴阳师"}
|
table = [...]string{"车万", "DC4", "爱因斯坦", "星空列车", "樱云之恋", "富婆妹", "李清歌", "公主连结", "原神", "明日方舟", "碧蓝航线", "碧蓝幻想", "战双", "阴阳师"}
|
||||||
// 映射底图与 index
|
// 映射底图与 index
|
||||||
index = make(map[string]uint32)
|
index = make(map[string]uint8)
|
||||||
// 下载锁
|
// 下载锁
|
||||||
dlmu sync.Mutex
|
dlmu sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
err := loadcfg("cfg.pb")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
for i, s := range table {
|
for i, s := range table {
|
||||||
index[s] = uint32(i)
|
index[s] = uint8(i)
|
||||||
}
|
}
|
||||||
err = os.MkdirAll(base, 0755)
|
err := os.MkdirAll(base, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -68,12 +64,16 @@ func init() {
|
|||||||
}
|
}
|
||||||
i, ok := index[ctx.State["regex_matched"].([]string)[1]]
|
i, ok := index[ctx.State["regex_matched"].([]string)[1]]
|
||||||
if ok {
|
if ok {
|
||||||
conf.Kind[gid] = i
|
c, ok := control.Lookup("fortune")
|
||||||
savecfg("cfg.pb")
|
if ok {
|
||||||
ctx.SendChain(message.Text("设置成功~"))
|
c.SetData(gid, int64(i)&0xff)
|
||||||
} else {
|
ctx.SendChain(message.Text("设置成功~"))
|
||||||
ctx.SendChain(message.Text("没有这个底图哦~"))
|
return
|
||||||
|
}
|
||||||
|
ctx.SendChain(message.Text("设置失败!"))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
ctx.SendChain(message.Text("没有这个底图哦~"))
|
||||||
})
|
})
|
||||||
en.OnFullMatchGroup([]string{"运势", "抽签"}).SetBlock(true).SecondPriority().
|
en.OnFullMatchGroup([]string{"运势", "抽签"}).SetBlock(true).SecondPriority().
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
@ -115,8 +115,12 @@ func init() {
|
|||||||
gid = -ctx.Event.UserID
|
gid = -ctx.Event.UserID
|
||||||
}
|
}
|
||||||
logrus.Debugln("[fortune]gid:", ctx.Event.GroupID, "uid:", ctx.Event.UserID)
|
logrus.Debugln("[fortune]gid:", ctx.Event.GroupID, "uid:", ctx.Event.UserID)
|
||||||
if v, ok := conf.Kind[gid]; ok {
|
c, ok := control.Lookup("fortune")
|
||||||
kind = table[v]
|
if ok {
|
||||||
|
v := uint8(c.GetData(gid) & 0xff)
|
||||||
|
if int(v) < len(table) {
|
||||||
|
kind = table[v]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 检查背景图片是否存在
|
// 检查背景图片是否存在
|
||||||
folder := base + kind
|
folder := base + kind
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user