mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 05:30:07 +08:00
添加 早报插件及设置欢迎语增加更多自定义 (#147)
* 添加 早报插件
* 添加 早报插件
* 添加 早报插件
* 添加 设置欢迎语更多自定义
* 添加 help说明
* 添加 manager设置欢迎语说明
* 怪
* 🎨 改进代码样式
* Update zaobao.go
* Update zaobao.go
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: 源文雨 <41315874+fumiama@users.noreply.github.com>
This commit is contained in:
parent
ebca124c86
commit
a862e5be7c
@ -145,7 +145,7 @@ print("run[CQ:image,file="+j["img"]+"]")
|
||||
- [x] 退出群聊[群号]@Bot
|
||||
- [x] *入群欢迎
|
||||
- [x] *退群通知
|
||||
- [x] 设置欢迎语[欢迎~]
|
||||
- [x] 设置欢迎语[欢迎~] 可选添加 [{at}] [{nickname}] [{avatar}]
|
||||
- [x] 在[MM]月[dd]日的[hh]点[mm]分时(用[url])提醒大家[xxx]
|
||||
- [x] 在[MM]月[每周 | 周几]的[hh]点[mm]分时(用[url])提醒大家[xxx]
|
||||
- [x] 取消在[MM]月[dd]日的[hh]点[mm]分的提醒
|
||||
@ -161,6 +161,7 @@ print("run[CQ:image,file="+j["img"]+"]")
|
||||
- [ ] 警告[@xxx]
|
||||
- [x] run[xxx]
|
||||
- 注:使用gist加群自动审批,请在群介绍添加以下说明,同时开启`需要回答问题并由管理员审核`:加群请在github新建一个gist,其文件名为本群群号的字符串的md5(小写),内容为一行,是当前unix时间戳(10分钟内有效)。然后请将您的用户名和gist哈希(小写)按照username/gisthash的格式填写到回答即可。
|
||||
- 设置欢迎语可选添加参数说明:{at}可在发送时艾特被欢迎者 {nickname}是被欢迎者名字 {avatar}是被欢迎者头像
|
||||
- **GitHub仓库搜索** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/github"`
|
||||
- [x] >github [xxx]
|
||||
- [x] >github -p [xxx]
|
||||
@ -347,6 +348,9 @@ print("run[CQ:image,file="+j["img"]+"]")
|
||||
- [x] 更新gal
|
||||
- **城市疫情查询** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/epidemic"`
|
||||
- [x] xxx疫情
|
||||
- **早报** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/zaobao"`
|
||||
- [x] /启用 zaobao
|
||||
- [x] /禁用 zaobao
|
||||
- **TODO...**
|
||||
|
||||
## 使用方法
|
||||
|
||||
1
main.go
1
main.go
@ -105,6 +105,7 @@ import (
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wangyiyun" // 网易云音乐热评
|
||||
_ "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站推送
|
||||
|
||||
@ -48,7 +48,7 @@ const (
|
||||
"- 取消在\"cron\"的提醒\n" +
|
||||
"- 列出所有提醒\n" +
|
||||
"- 翻牌\n" +
|
||||
"- 设置欢迎语XXX(可加{at}在欢迎时@对方)\n" +
|
||||
"- 设置欢迎语XXX 可选添加 [{at}] [{nickname}] [{avatar}] {at}可在发送时艾特被欢迎者 {nickname}是被欢迎者名字 {avatar}是被欢迎者头像\n" +
|
||||
"- 测试欢迎语\n" +
|
||||
"- [开启 | 关闭]入群验证"
|
||||
)
|
||||
@ -381,7 +381,7 @@ func init() { // 插件主体
|
||||
var w welcome
|
||||
err := db.Find("welcome", &w, "where gid = "+strconv.FormatInt(ctx.Event.GroupID, 10))
|
||||
if err == nil {
|
||||
ctx.SendGroupMessage(ctx.Event.GroupID, message.ParseMessageFromString(strings.ReplaceAll(w.Msg, "{at}", "[CQ:at,qq="+strconv.FormatInt(ctx.Event.UserID, 10)+"]")))
|
||||
ctx.SendGroupMessage(ctx.Event.GroupID, message.ParseMessageFromString(welcometocq(ctx, w.Msg)))
|
||||
} else {
|
||||
ctx.SendChain(message.Text("欢迎~"))
|
||||
}
|
||||
@ -454,7 +454,7 @@ func init() { // 插件主体
|
||||
var w welcome
|
||||
err := db.Find("welcome", &w, "where gid = "+strconv.FormatInt(ctx.Event.GroupID, 10))
|
||||
if err == nil {
|
||||
ctx.SendGroupMessage(ctx.Event.GroupID, message.ParseMessageFromString(strings.ReplaceAll(w.Msg, "{at}", "[CQ:at,qq="+strconv.FormatInt(ctx.Event.UserID, 10)+"]")))
|
||||
ctx.SendGroupMessage(ctx.Event.GroupID, message.ParseMessageFromString(welcometocq(ctx, w.Msg)))
|
||||
} else {
|
||||
ctx.SendChain(message.Text("欢迎~"))
|
||||
}
|
||||
@ -540,3 +540,14 @@ func init() { // 插件主体
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 传入 ctx 和 welcome格式string 返回cq格式string 使用方法:welcometocq(ctx,w.Msg)
|
||||
func welcometocq(ctx *zero.Ctx, welcome string) string {
|
||||
nickname := ctx.GetGroupMemberInfo(ctx.Event.GroupID, ctx.Event.UserID, false).Get("nickname").Str
|
||||
at := "[CQ:at,qq=" + strconv.FormatInt(ctx.Event.UserID, 10) + "]"
|
||||
avatar := "[CQ:image,file=" + "http://q4.qlogo.cn/g?b=qq&nk=" + strconv.FormatInt(ctx.Event.UserID, 10) + "&s=640]"
|
||||
cqstring := strings.ReplaceAll(welcome, "{at}", at)
|
||||
cqstring = strings.ReplaceAll(cqstring, "{nickname}", nickname)
|
||||
cqstring = strings.ReplaceAll(cqstring, "{avatar}", avatar)
|
||||
return cqstring
|
||||
}
|
||||
|
||||
72
plugin/zaobao/zaobao.go
Normal file
72
plugin/zaobao/zaobao.go
Normal file
@ -0,0 +1,72 @@
|
||||
// Package zaobao 易即今日公众号api的今日早报
|
||||
package zaobao
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
control "github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/file"
|
||||
"github.com/FloatTech/zbputils/web"
|
||||
|
||||
"github.com/FloatTech/zbputils/control/order"
|
||||
)
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("zaobao", order.AcquirePrio(), &control.Options{
|
||||
DisableOnDefault: true,
|
||||
Help: "zaobao\n" +
|
||||
"api早上8点更新,推荐定时在8点30后\n" +
|
||||
"配合插件job中的记录在'cron'触发的指令使用\n" +
|
||||
"------示例------\n" +
|
||||
"每天早上九点定时发送\n" +
|
||||
"记录在'00 9 * * *'触发的指令\n" +
|
||||
"今日早报",
|
||||
PrivateDataFolder: "zaobao",
|
||||
})
|
||||
cachePath := engine.DataFolder()
|
||||
os.RemoveAll(cachePath)
|
||||
err := os.MkdirAll(cachePath, 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
zaobaoFile := cachePath + "zaobao_" + time.Now().Format("2006-01-02") + ".jpg"
|
||||
engine.OnFullMatch("今日早报", zero.OnlyGroup).SetBlock(false).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
err := download(zaobaoFile)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + zaobaoFile))
|
||||
})
|
||||
}
|
||||
|
||||
func download(zaobaoFile string) error { // 获取图片链接并且下载
|
||||
if file.IsNotExist(zaobaoFile) {
|
||||
data, err := web.GetDataWith(web.NewDefaultClient(), api, "GET", "", ua)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
zaobaoURL := gjson.Get(string(data), "url").String()
|
||||
data, err = web.GetDataWith(web.NewDefaultClient(), zaobaoURL, "GET", referer, ua)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.WriteFile(zaobaoFile, data, 0666)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user