Skip to content

Commit

Permalink
✨ fortune 增加下载锁;优化 gui 插件控制
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Oct 27, 2021
1 parent 82ee2f6 commit 755bfea
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 67 deletions.
33 changes: 7 additions & 26 deletions control/web/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,11 @@ func updateAllPluginStatus(context *gin.Context) {
}
enable = parse["enable"].(bool)
}
var groups []int64
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
for _, group := range ctx.GetGroupList().Array() {
groups = append(groups, group.Get("group_id").Int())
}
return true
})

ctrl.ForEach(func(key string, manager *ctrl.Control) bool {
if enable {
for _, group := range groups {
manager.Enable(group)
}
manager.Enable(0)
} else {
for _, group := range groups {
manager.Disable(group)
}
manager.Disable(0)
}
return true
})
Expand Down Expand Up @@ -175,18 +163,11 @@ func updatePluginAllGroupStatus(context *gin.Context) {
context.JSON(404, nil)
return
}
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
for _, group := range ctx.GetGroupList().Array() {
if enable {
control.Enable(group.Get("group_id").Int())
} else {
control.Disable(group.Get("group_id").Int())
}
}

return true
})

if enable {
control.Enable(0)
} else {
control.Disable(0)
}
context.JSON(200, nil)
}

Expand Down
24 changes: 11 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,21 @@ func printBanner() {

func main() {
printBanner()
zero.Run(zero.Config{
NickName: []string{"椛椛", "ATRI", "atri", "亚托莉", "アトリ"},
CommandPrefix: "/",
// SuperUsers 某些功能需要主人权限,可通过以下两种方式修改
// []string{}:通过代码写死的方式添加主人账号
// flag.Args():通过命令行参数的方式添加主人账号
SuperUsers: append([]string{"12345678", "87654321"}, flag.Args()...),
Driver: []zero.Driver{
driver.NewWebSocketClient(*url, *token),
},
},
)

// 帮助
zero.OnFullMatchGroup([]string{"/help", ".help", "菜单"}, zero.OnlyToMe).SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) {
ctx.SendChain(message.Text(banner))
})
zero.Run(
zero.Config{
NickName: []string{"椛椛", "ATRI", "atri", "亚托莉", "アトリ"},
CommandPrefix: "/",
// SuperUsers 某些功能需要主人权限,可通过以下两种方式修改
// "12345678", "87654321":通过代码写死的方式添加主人账号
// flag.Args():通过命令行参数的方式添加主人账号,无需修改下方任何代码
SuperUsers: append([]string{"12345678", "87654321"}, flag.Args()...),
Driver: []zero.Driver{driver.NewWebSocketClient(*url, *token)},
},
)
select {}
}
1 change: 1 addition & 0 deletions plugin_bilibili/fansDaily.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func fansDaily(groupID int64) {

// 获取数据拼接消息链并发送
func fansData(groupID int64) {
// TODO: 更改为 GetBot
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
var (
diana = fansapi("672328094")
Expand Down
71 changes: 43 additions & 28 deletions plugin_fortune/fortune.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"math/rand"
"os"
"strconv"
"sync"
"time"

"github.com/fogleman/gg"
Expand All @@ -35,6 +36,8 @@ var (
table = [...]string{"车万", "DC4", "爱因斯坦", "星空列车", "樱云之恋", "富婆妹", "李清歌", "公主连结", "原神", "明日方舟", "碧蓝航线", "碧蓝幻想", "战双", "阴阳师"}
// 映射底图与 index
index = make(map[string]uint32)
// 下载锁
dlmu sync.Mutex
)

func init() {
Expand Down Expand Up @@ -77,24 +80,32 @@ func init() {
// 检查签文文件是否存在
mikuji := base + "运势签文.json"
if file.IsNotExist(mikuji) {
ctx.SendChain(message.Text("正在下载签文文件,请稍后..."))
err := file.DownloadTo(site+"运势签文.json", mikuji)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
dlmu.Lock()
if file.IsNotExist(mikuji) {
ctx.SendChain(message.Text("正在下载签文文件,请稍后..."))
err := file.DownloadTo(site+"运势签文.json", mikuji)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
ctx.SendChain(message.Text("下载签文文件完毕"))
}
ctx.SendChain(message.Text("下载签文文件完毕"))
dlmu.Unlock()
}
// 检查字体文件是否存在
ttf := base + "sakura.ttf"
if file.IsNotExist(ttf) {
ctx.SendChain(message.Text("正在下载字体文件,请稍后..."))
err := file.DownloadTo(site+"sakura.ttf", ttf)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
dlmu.Lock()
if file.IsNotExist(ttf) {
ctx.SendChain(message.Text("正在下载字体文件,请稍后..."))
err := file.DownloadTo(site+"sakura.ttf", ttf)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
ctx.SendChain(message.Text("下载字体文件完毕"))
}
ctx.SendChain(message.Text("下载字体文件完毕"))
dlmu.Unlock()
}
// 获取该群背景类型,默认车万
kind := "车万"
Expand All @@ -110,23 +121,27 @@ func init() {
// 检查背景图片是否存在
folder := base + kind
if file.IsNotExist(folder) {
ctx.SendChain(message.Text("正在下载背景图片,请稍后..."))
zipfile := kind + ".zip"
zipcache := base + zipfile
err := file.DownloadTo(site+zipfile, zipcache)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
dlmu.Lock()
if file.IsNotExist(folder) {
ctx.SendChain(message.Text("正在下载背景图片,请稍后..."))
zipfile := kind + ".zip"
zipcache := base + zipfile
err := file.DownloadTo(site+zipfile, zipcache)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
ctx.SendChain(message.Text("下载背景图片完毕"))
err = unpack(zipcache, folder+"/")
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
ctx.SendChain(message.Text("解压背景图片完毕"))
// 释放空间
os.Remove(zipcache)
}
ctx.SendChain(message.Text("下载背景图片完毕"))
err = unpack(zipcache, folder+"/")
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
ctx.SendChain(message.Text("解压背景图片完毕"))
// 释放空间
os.Remove(zipcache)
dlmu.Unlock()
}
// 生成种子
t, _ := strconv.ParseInt(time.Now().Format("20060102"), 10, 64)
Expand Down
1 change: 1 addition & 0 deletions plugin_manager/timer/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func (ts *Timer) nextWakeTime() (date time.Time) {
func (ts *Timer) judgeHM() {
if ts.Hour < 0 || ts.Hour == int32(time.Now().Hour()) {
if ts.Minute < 0 || ts.Minute == int32(time.Now().Minute()) {
//zero.GetBot(zero.BotConfig.SelfID)
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
ctx.Event = new(zero.Event)
ctx.Event.GroupID = int64(ts.Grpid)
Expand Down

0 comments on commit 755bfea

Please sign in to comment.