模块化消息扩展、增加简易随机图片

This commit is contained in:
fumiama 2021-06-03 23:46:37 +08:00
parent 6b604d8b9f
commit c199a0ac6d
5 changed files with 59 additions and 25 deletions

View File

@ -24,6 +24,7 @@ import (
// 娱乐类
_ "github.com/Yiwen-Chan/ZeroBot-Plugin/music" // 点歌
_ "github.com/Yiwen-Chan/ZeroBot-Plugin/randimg" //简易随机图片
_ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime" // 涩图
_ "github.com/Yiwen-Chan/ZeroBot-Plugin/shindan" // 测定
)

View File

@ -4,6 +4,7 @@ import (
"strconv"
"strings"
"github.com/Yiwen-Chan/ZeroBot-Plugin/msgext"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)
@ -238,9 +239,9 @@ func init() { // 插件主体
if ts.enable {
go timer(ts, func() {
if ts.url == "" {
ctx.SendChain(AtAll(), message.Text(ts.alert))
ctx.SendChain(msgext.AtAll(), message.Text(ts.alert))
} else {
ctx.SendChain(AtAll(), message.Text(ts.alert), ImageNoCache(ts.url))
ctx.SendChain(msgext.AtAll(), message.Text(ts.alert), msgext.ImageNoCache(ts.url))
}
})
ctx.Send("记住了~")

View File

@ -6,8 +6,6 @@ import (
"strings"
"time"
"unicode"
"github.com/wdvxdr1123/ZeroBot/message"
)
type TimeStamp struct {
@ -175,24 +173,3 @@ func chineseChar2Int(c rune) int {
return 0
}
}
//@全体成员
func AtAll() message.MessageSegment {
return message.MessageSegment{
Type: "at",
Data: map[string]string{
"qq": "all",
},
}
}
//无缓存发送图片
func ImageNoCache(url string) message.MessageSegment {
return message.MessageSegment{
Type: "image",
Data: map[string]string{
"file": url,
"cache": "0",
},
}
}

26
msgext/msgext.go Normal file
View File

@ -0,0 +1,26 @@
package msgext
import (
"github.com/wdvxdr1123/ZeroBot/message"
)
//@全体成员
func AtAll() message.MessageSegment {
return message.MessageSegment{
Type: "at",
Data: map[string]string{
"qq": "all",
},
}
}
//无缓存发送图片
func ImageNoCache(url string) message.MessageSegment {
return message.MessageSegment{
Type: "image",
Data: map[string]string{
"file": url,
"cache": "0",
},
}
}

29
randimg/setu_geter.go Normal file
View File

@ -0,0 +1,29 @@
package randimg
import (
"strings"
"github.com/Yiwen-Chan/ZeroBot-Plugin/msgext"
zero "github.com/wdvxdr1123/ZeroBot"
)
var RANDOM_API_URL = "https://api.pixivweb.com/anime18r.php?return=img"
func init() { // 插件主体
zero.OnRegex(`^设置随机图片网址(.*)$`, zero.SuperUserPermission).SetBlock(true).SetPriority(20).
Handle(func(ctx *zero.Ctx) {
url := ctx.State["regex_matched"].([]string)[1]
if !strings.HasPrefix(url, "http") {
ctx.Send("URL非法!")
} else {
RANDOM_API_URL = url
}
return
})
// 随机图片
zero.OnFullMatchGroup([]string{"随机图片"}).SetBlock(true).SetPriority(24).
Handle(func(ctx *zero.Ctx) {
ctx.Send(msgext.ImageNoCache(RANDOM_API_URL))
return
})
}