mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 05:30:07 +08:00
parent
01bf6f049b
commit
84363b1513
17
README.md
17
README.md
@ -926,23 +926,6 @@ print("run[CQ:image,file="+j["img"]+"]")
|
||||
|
||||
- [x] 更新gal
|
||||
|
||||
</details>
|
||||
<details>
|
||||
<summary>早报</summary>
|
||||
|
||||
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/zaobao"`
|
||||
|
||||
- api早上8点更新,推荐定时在8点30后。配合插件`job`中的记录在"cron"触发的指令使用
|
||||
|
||||
- [x] /启用 zaobao
|
||||
|
||||
- [x] /禁用 zaobao
|
||||
|
||||
```
|
||||
记录在"00 9 * * *"触发的指令
|
||||
今日早报
|
||||
```
|
||||
|
||||
</details>
|
||||
<details>
|
||||
<summary>舔狗日记</summary>
|
||||
|
||||
1
main.go
1
main.go
@ -113,7 +113,6 @@ import (
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/word_count" // 聊天热词
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wordle" // 猜单词
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ymgal" // 月幕galgame
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/zaobao" // 早报
|
||||
|
||||
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/wtf" // 鬼东西
|
||||
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/bilibili_push" // b站推送
|
||||
|
||||
@ -1,66 +0,0 @@
|
||||
// Package zaobao 易即今日公众号api的今日早报
|
||||
package zaobao
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
ctrl "github.com/FloatTech/zbpctrl"
|
||||
"github.com/FloatTech/zbputils/binary"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/web"
|
||||
)
|
||||
|
||||
const (
|
||||
api = "http://api.soyiji.com/news_jpg"
|
||||
referer = "safe.soyiji.com"
|
||||
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66"
|
||||
)
|
||||
|
||||
var (
|
||||
picdata []byte
|
||||
mu sync.Mutex
|
||||
pictime time.Time
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("zaobao", &ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: true,
|
||||
Help: "易即今日公众号api的今日早报\n" +
|
||||
"api早上8点更新,推荐定时在8点30后\n" +
|
||||
"配合插件job中的记录在\"cron\"触发的指令使用\n" +
|
||||
"- 记录在\"0 9 * * *\"触发的指令\n" +
|
||||
" - 今日早报",
|
||||
})
|
||||
engine.OnFullMatch("今日早报", zero.OnlyGroup).SetBlock(false).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
err := getdata()
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.ImageBytes(picdata))
|
||||
})
|
||||
}
|
||||
|
||||
func getdata() error { // 获取图片链接并且下载
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if picdata != nil && time.Since(pictime) <= time.Hour*8 && time.Now().Day() == pictime.Day() {
|
||||
return nil
|
||||
}
|
||||
data, err := web.RequestDataWith(web.NewDefaultClient(), api, "GET", "", ua)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
picdata, err = web.RequestDataWith(web.NewDefaultClient(), gjson.Get(binary.BytesToString(data), "url").String(), "GET", referer, ua)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pictime = time.Now()
|
||||
return nil
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user