mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-12 18:20:27 +00:00
feat:添加定时早安
This commit is contained in:
73
plugin_qingyunke/cron.go
Normal file
73
plugin_qingyunke/cron.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package qingyunke
|
||||
|
||||
//定时早安,晚安
|
||||
import (
|
||||
"github.com/robfig/cron"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
"log"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
//所有群添加定时早安
|
||||
zero.OnMessage().SetBlock(false).FirstPriority().Handle(func(ctx *zero.Ctx) {
|
||||
log.Println(ctx.GetGroupList())
|
||||
result := ctx.GetGroupList()
|
||||
for _, v := range result.Array() {
|
||||
Daily(v.Get("group_id").Int())
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Daily(780549442)
|
||||
|
||||
}
|
||||
|
||||
func morningData(groupId int64) {
|
||||
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendGroupMessage(groupId, message.Image(getPicture()))
|
||||
ctx.SendGroupMessage(groupId, randText("啊......早上好...(哈欠)",
|
||||
"唔......吧唧...早上...哈啊啊~~~\n早上好......",
|
||||
"早上好......",
|
||||
"早上好呜......呼啊啊~~~~",
|
||||
"啊......早上好。\n昨晚也很激情呢!",
|
||||
"吧唧吧唧......怎么了...已经早上了么...",
|
||||
"早上好!",
|
||||
"......看起来像是傍晚,其实已经早上了吗?",
|
||||
"早上好......欸~~~脸好近呢"))
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
func eveningData(groupId int64) {
|
||||
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendGroupMessage(groupId, message.Image(getPicture()))
|
||||
ctx.SendGroupMessage(groupId, randText("嗯哼哼~睡吧,就像平常一样安眠吧~o(≧▽≦)o",
|
||||
"......(打瞌睡)",
|
||||
"呼...呼...已经睡着了哦~...呼......",
|
||||
"......我、我会在这守着你的,请务必好好睡着"))
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
func Daily(groupId int64) {
|
||||
log.Println("给" + strconv.FormatInt(groupId, 10) + "添加定时任务")
|
||||
c := cron.New()
|
||||
_ = c.AddFunc("0 30 7 * * ?", func() {
|
||||
morningData(groupId)
|
||||
})
|
||||
_ = c.AddFunc("0 30 22 * * ?", func() {
|
||||
eveningData(groupId)
|
||||
})
|
||||
c.Start()
|
||||
}
|
||||
|
||||
func randText(text ...string) message.MessageSegment {
|
||||
length := len(text)
|
||||
return message.Text(text[rand.Intn(length)])
|
||||
}
|
||||
@@ -10,18 +10,18 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
reImg = `https?://[^"]+?(\.((jpg)|(png)|(jpeg)|(gif)|(bmp)))`
|
||||
reImg = `https?://[^"]+?(\.((jpg)|(png)|(jpeg)|(gif)|(bmp)))`
|
||||
)
|
||||
|
||||
func getPicture() string {
|
||||
prefix:="https://www.fabiaoqing.com/search/bqb/keyword/%E5%88%AB%E5%8F%91%E5%9B%BE%E7%89%87/type/bq/page/"
|
||||
url :=fmt.Sprintf("%d.html",rand.Intn(5)+1)
|
||||
prefix := "https://fabiaoqing.com/tag/detail/id/5682/page"
|
||||
url := fmt.Sprintf("%d.html", rand.Intn(11)+1)
|
||||
url = prefix + url
|
||||
log.Println("正在"+url+"寻找图片")
|
||||
log.Println("正在" + url + "寻找图片")
|
||||
urls := getImgs(url)
|
||||
fmt.Println(urls)
|
||||
imageUrl := urls[rand.Intn(len(urls))]
|
||||
log.Println("取到"+imageUrl)
|
||||
log.Println("取到" + imageUrl)
|
||||
return imageUrl
|
||||
}
|
||||
|
||||
@@ -21,9 +21,8 @@ var enable = true
|
||||
|
||||
func init() { // 插件主体
|
||||
// 被喊名字
|
||||
zero.OnRegex("(^.{1,30}$)", zero.OnlyToMe,atriSwitch()).SetBlock(false).FirstPriority().
|
||||
zero.OnRegex("(^.{1,30}$)", zero.OnlyToMe, atriSwitch()).SetBlock(false).FirstPriority().
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
//var nickname = zero.BotConfig.NickName[0]
|
||||
switch {
|
||||
case poke.Load(ctx.Event.UserID).Acquire():
|
||||
time.Sleep(time.Second * 1)
|
||||
@@ -40,61 +39,62 @@ func init() { // 插件主体
|
||||
} else {
|
||||
textReply = reply
|
||||
}
|
||||
textReply = strings.Replace(textReply,"菲菲","椛椛",-1)
|
||||
textReply = strings.Replace(textReply, "菲菲", "椛椛", -1)
|
||||
if ctx.Event.DetailType == "group" {
|
||||
ctx.SendChain(message.Text(textReply))
|
||||
|
||||
if faceReply != -1 {
|
||||
ctx.SendChain(message.Face(faceReply))
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(textReply), message.Face(faceReply))
|
||||
} else {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(textReply))
|
||||
}
|
||||
|
||||
}
|
||||
if ctx.Event.DetailType == "private" {
|
||||
ctx.SendChain(message.Text(textReply))
|
||||
if faceReply != -1 {
|
||||
ctx.SendChain(message.Face(faceReply))
|
||||
ctx.SendChain(message.Text(textReply), message.Face(faceReply))
|
||||
} else {
|
||||
ctx.SendChain(message.Text(textReply))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
//频繁触发,不回复
|
||||
}
|
||||
|
||||
})
|
||||
zero.OnRegex("CQ:image,file=|CQ:face,id=", zero.OnlyToMe,atriSwitch()).SetBlock(false).FirstPriority().
|
||||
zero.OnRegex("CQ:image,file=|CQ:face,id=", zero.OnlyToMe, atriSwitch()).SetBlock(false).FirstPriority().
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
imageUrl := getPicture()
|
||||
time.Sleep(time.Second * 1)
|
||||
ctx.SendChain(message.Image(imageUrl))
|
||||
if ctx.Event.DetailType == "group" {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image(imageUrl))
|
||||
}
|
||||
if ctx.Event.DetailType == "private" {
|
||||
ctx.SendChain(message.Image(imageUrl))
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
zero.OnFullMatch("启动",zero.SuperUserPermission).SetBlock(true).SetPriority(prio).
|
||||
zero.OnFullMatch("启动自动回复", zero.SuperUserPermission).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
|
||||
enable = true
|
||||
ctx.SendChain(message.Text("自动回复启动"))
|
||||
|
||||
|
||||
enable = true
|
||||
ctx.SendChain(message.Text("自动回复启动"))
|
||||
|
||||
})
|
||||
zero.OnFullMatch("关闭",zero.SuperUserPermission).SetBlock(true).SetPriority(prio).
|
||||
zero.OnFullMatch("关闭自动回复", zero.SuperUserPermission).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
|
||||
enable = false
|
||||
ctx.SendChain(message.Text("自动回复关闭"))
|
||||
|
||||
|
||||
enable = false
|
||||
ctx.SendChain(message.Text("自动回复关闭"))
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
// 群空调
|
||||
|
||||
}
|
||||
|
||||
type Data struct {
|
||||
type QYData struct {
|
||||
Result int `json:"result"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
@@ -127,11 +127,11 @@ func getMessage(msg string) string {
|
||||
fmt.Println("ioutil.ReadAll", err)
|
||||
}
|
||||
fmt.Println(string(bytes))
|
||||
var data Data
|
||||
if err := json.Unmarshal(bytes, &data); err != nil {
|
||||
var QYData QYData
|
||||
if err := json.Unmarshal(bytes, &QYData); err != nil {
|
||||
fmt.Println("json transform", err)
|
||||
}
|
||||
return data.Content
|
||||
return QYData.Content
|
||||
}
|
||||
|
||||
func getAgent() string {
|
||||
@@ -157,4 +157,3 @@ func atriSwitch() zero.Rule {
|
||||
return enable
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user