mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
模块化消息扩展、增加简易随机图片
This commit is contained in:
parent
6b604d8b9f
commit
c199a0ac6d
1
main.go
1
main.go
@ -24,6 +24,7 @@ import (
|
|||||||
|
|
||||||
// 娱乐类
|
// 娱乐类
|
||||||
_ "github.com/Yiwen-Chan/ZeroBot-Plugin/music" // 点歌
|
_ "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/setutime" // 涩图
|
||||||
_ "github.com/Yiwen-Chan/ZeroBot-Plugin/shindan" // 测定
|
_ "github.com/Yiwen-Chan/ZeroBot-Plugin/shindan" // 测定
|
||||||
)
|
)
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Yiwen-Chan/ZeroBot-Plugin/msgext"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
)
|
)
|
||||||
@ -238,9 +239,9 @@ func init() { // 插件主体
|
|||||||
if ts.enable {
|
if ts.enable {
|
||||||
go timer(ts, func() {
|
go timer(ts, func() {
|
||||||
if ts.url == "" {
|
if ts.url == "" {
|
||||||
ctx.SendChain(AtAll(), message.Text(ts.alert))
|
ctx.SendChain(msgext.AtAll(), message.Text(ts.alert))
|
||||||
} else {
|
} 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("记住了~")
|
ctx.Send("记住了~")
|
||||||
|
|||||||
@ -6,8 +6,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TimeStamp struct {
|
type TimeStamp struct {
|
||||||
@ -175,24 +173,3 @@ func chineseChar2Int(c rune) int {
|
|||||||
return 0
|
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
26
msgext/msgext.go
Normal 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
29
randimg/setu_geter.go
Normal 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
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user