🎨 ctx.Send -> ctx.SendChain

This commit is contained in:
Kanri 2021-10-15 21:43:47 +08:00
parent 2a1cca8ebb
commit c46ca1d4c2
13 changed files with 73 additions and 57 deletions

View File

@ -140,10 +140,10 @@ func init() {
_ = ctx.Parse(&model)
service, ok := Lookup(model.Args)
if !ok {
ctx.Send("没有找到指定服务!")
ctx.SendChain(message.Text("没有找到指定服务!"))
}
service.Enable(ctx.Event.GroupID)
ctx.Send(message.Text("已启用服务: " + model.Args))
ctx.SendChain(message.Text("已启用服务: " + model.Args))
})
zero.OnCommandGroup([]string{"禁用", "disable"}, zero.AdminPermission, zero.OnlyGroup).
@ -152,10 +152,10 @@ func init() {
_ = ctx.Parse(&model)
service, ok := Lookup(model.Args)
if !ok {
ctx.Send("没有找到指定服务!")
ctx.SendChain(message.Text("没有找到指定服务!"))
}
service.Disable(ctx.Event.GroupID)
ctx.Send(message.Text("已关闭服务: " + model.Args))
ctx.SendChain(message.Text("已关闭服务: " + model.Args))
})
zero.OnCommandGroup([]string{"用法", "usage"}, zero.AdminPermission, zero.OnlyGroup).
@ -164,12 +164,12 @@ func init() {
_ = ctx.Parse(&model)
service, ok := Lookup(model.Args)
if !ok {
ctx.Send("没有找到指定服务!")
ctx.SendChain(message.Text("没有找到指定服务!"))
}
if service.options.Help != "" {
ctx.Send(service.options.Help)
ctx.SendChain(message.Text(service.options.Help))
} else {
ctx.Send("该服务无帮助!")
ctx.SendChain(message.Text("该服务无帮助!"))
}
})
@ -187,7 +187,7 @@ func init() {
}
return true
})
ctx.Send(message.Text(msg))
ctx.SendChain(message.Text(msg))
})
}
}

View File

@ -51,6 +51,7 @@ import (
"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/driver"
"github.com/wdvxdr1123/ZeroBot/message"
)
var (
@ -121,7 +122,7 @@ func main() {
// 帮助
zero.OnFullMatchGroup([]string{"/help", ".help", "菜单"}, zero.OnlyToMe).SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) {
ctx.Send(banner)
ctx.SendChain(message.Text(banner))
})
select {}
}

View File

@ -46,10 +46,10 @@ func init() { // 插件主体
Handle(func(ctx *zero.Ctx) {
url := ctx.State["regex_matched"].([]string)[1]
if !strings.HasPrefix(url, "http") {
ctx.Send("URL非法!")
ctx.SendChain(message.Text("URL非法!"))
} else {
randapi = url
ctx.Send("设置好啦")
ctx.SendChain(message.Text("设置好啦"))
}
})
// 有保护的随机图片
@ -61,14 +61,14 @@ func init() { // 插件主体
replyClass(ctx, dhash, class, false, lastvisit, comment)
}()
} else {
ctx.Send("你太快啦!")
ctx.SendChain(message.Text("你太快啦!"))
}
})
// 直接随机图片无r18保护后果自负。如果出r18图可尽快通过发送"太涩了"撤回
engine.OnFullMatch("直接随机", zero.OnlyGroup, zero.AdminPermission).SetBlock(true).SetPriority(24).
Handle(func(ctx *zero.Ctx) {
if block {
ctx.Send("请稍后再试哦")
ctx.SendChain(message.Text("请稍后再试哦"))
} else if randapi != "" {
block = true
var url string
@ -77,7 +77,7 @@ func init() { // 插件主体
} else {
url = randapi
}
setLastMsg(ctx.Event.GroupID, ctx.Send(message.Image(url).Add("cache", "0")))
setLastMsg(ctx.Event.GroupID, ctx.SendChain(message.Image(url).Add("cache", "0")))
block = false
}
})
@ -89,7 +89,7 @@ func init() { // 插件主体
// 上传一张图进行评价
engine.OnKeywordGroup([]string{"评价图片"}, zero.OnlyGroup, picture.CmdMatch, picture.MustGiven).SetBlock(true).SetPriority(24).
Handle(func(ctx *zero.Ctx) {
ctx.Send("少女祈祷中...")
ctx.SendChain(message.Text("少女祈祷中..."))
for _, url := range ctx.State["image_url"].([]string) {
go func(target string) {
class, lastvisit, dhash, comment := classify.Classify(target, true)
@ -101,7 +101,7 @@ func init() { // 插件主体
Handle(func(ctx *zero.Ctx) {
dhash := ctx.State["regex_matched"].([]string)[1]
if len(dhash) == 5*3 {
ctx.Send(message.Image(apihead + dhash))
ctx.SendChain(message.Image(apihead + dhash))
}
})
}
@ -124,19 +124,18 @@ func replyClass(ctx *zero.Ctx, dhash string, class int, noimg bool, lv int64, co
if dhash != "" && !noimg {
b14, err3 := url.QueryUnescape(dhash)
if err3 == nil {
ctx.Send(comment + "\n给你点提示哦" + b14)
ctx.SendChain(message.Text(comment + "\n给你点提示哦" + b14))
ctx.Event.GroupID = 0
ctx.Send(img)
ctx.SendChain(message.Text(img))
}
} else {
ctx.Send(comment)
ctx.SendChain(message.Text(comment))
}
} else {
comment := message.Text(comment)
if !noimg {
ctx.SendChain(img, comment)
ctx.SendChain(img, message.Text(comment))
} else {
ctx.SendChain(message.Reply(ctx.Event.MessageID), comment)
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(comment))
}
}
}

View File

@ -35,9 +35,9 @@ func init() { // 插件主体
Handle(func(ctx *zero.Ctx) {
err := os.RemoveAll("data/cache/*")
if err != nil {
ctx.Send("错误: " + err.Error())
ctx.SendChain(message.Text("错误: ", err.Error()))
} else {
ctx.Send("成功!")
ctx.SendChain(message.Text("成功!"))
}
})
}

View File

@ -2,11 +2,11 @@
package diana
import (
fmt "fmt"
"math/rand"
"time"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
"github.com/FloatTech/ZeroBot-Plugin/control"
"github.com/FloatTech/ZeroBot-Plugin/plugin_diana/data"
@ -28,22 +28,22 @@ func init() {
Handle(func(ctx *zero.Ctx) {
rand.Seed(time.Now().UnixNano())
// 绕过第一行发病
ctx.Send((*data.Array)[rand.Intn(len(*data.Array)-1)+1])
ctx.SendChain(message.Text((*data.Array)[rand.Intn(len(*data.Array)-1)+1]))
})
// 逆天
engine.OnFullMatch("发大病").SetBlock(true).
Handle(func(ctx *zero.Ctx) {
// 第一行是发病
ctx.Send((*data.Array)[0])
ctx.SendChain(message.Text((*data.Array)[0]))
})
// 增加小作文
engine.OnRegex(`^教你一篇小作文(.*)$`, zero.AdminPermission).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
err := data.AddText(ctx.State["regex_matched"].([]string)[1])
if err != nil {
ctx.Send(fmt.Sprintf("ERROR: %v", err))
ctx.SendChain(message.Text("ERROR: ", err))
} else {
ctx.Send("记住啦!")
ctx.SendChain(message.Text("记住啦!"))
}
})
}

View File

@ -37,12 +37,12 @@ func init() {
zhiwangjson := zhiwangapi(msg)
if zhiwangjson == nil || zhiwangjson.Code != 0 {
ctx.Send("api返回错误")
ctx.SendChain(message.Text("api返回错误"))
return
}
if len(zhiwangjson.Data.Related) == 0 {
ctx.Send("枝网没搜到查重率为0%,我的评价是:一眼真")
ctx.SendChain(message.Text("枝网没搜到查重率为0%,我的评价是:一眼真"))
return
}

View File

@ -58,7 +58,7 @@ func init() { // 插件主体
// 菜单
zero.OnFullMatch("群管系统", zero.AdminPermission).SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) {
ctx.Send(hint)
ctx.SendChain(message.Text(hint))
})
// 升为管理
zero.OnRegex(`^升为管理.*?(\d+)`, zero.OnlyGroup, zero.SuperUserPermission).SetBlock(true).SetPriority(40).
@ -254,9 +254,9 @@ func init() { // 插件主体
ts.Grpid = uint64(ctx.Event.GroupID)
if ts.Enable {
go timer.RegisterTimer(ts, true)
ctx.Send("记住了~")
ctx.SendChain(message.Text("记住了~"))
} else {
ctx.Send("参数非法!")
ctx.SendChain(message.Text("参数非法!"))
}
}
})
@ -273,9 +273,9 @@ func init() { // 插件主体
t.Enable = false
delete(*timer.Timers, ti) // 避免重复取消
_ = timer.SaveTimers()
ctx.Send("取消成功~")
ctx.SendChain(message.Text("取消成功~"))
} else {
ctx.Send("没有这个定时器哦~")
ctx.SendChain(message.Text("没有这个定时器哦~"))
}
}
})
@ -283,7 +283,7 @@ func init() { // 插件主体
zero.OnFullMatch("列出所有提醒", zero.AdminPermission).SetBlock(true).SetPriority(40).
Handle(func(ctx *zero.Ctx) {
if ctx.Event.GroupID > 0 {
ctx.Send(fmt.Sprint(timer.ListTimers(uint64(ctx.Event.GroupID))))
ctx.SendChain(message.Text(timer.ListTimers(uint64(ctx.Event.GroupID))))
}
})
// 随机点名
@ -330,9 +330,9 @@ func init() { // 插件主体
if ctx.Event.NoticeType == "group_increase" {
word, ok := config.Welcome[uint64(ctx.Event.GroupID)]
if ok {
ctx.Send(word)
ctx.SendChain(message.Text(word))
} else {
ctx.Send("欢迎~")
ctx.SendChain(message.Text("欢迎~"))
}
enable, ok1 := config.Checkin[uint64(ctx.Event.GroupID)]
if ok1 && enable {
@ -349,7 +349,7 @@ func init() { // 插件主体
ans, err := strconv.Atoi(text)
if err == nil {
if ans != r {
ctx.Send("答案不对哦,再想想吧~")
ctx.SendChain(message.Text("答案不对哦,再想想吧~"))
return false
}
return true
@ -362,12 +362,12 @@ func init() { // 插件主体
recv, cancel := next.Repeat()
select {
case <-time.After(time.Minute):
ctx.Send("拜拜啦~")
ctx.SendChain(message.Text("拜拜啦~"))
ctx.SetGroupKick(ctx.Event.GroupID, uid, false)
cancel()
case <-recv:
cancel()
ctx.Send("答对啦~")
ctx.SendChain(message.Text("答对啦~"))
}
}
}
@ -384,9 +384,9 @@ func init() { // 插件主体
Handle(func(ctx *zero.Ctx) {
config.Welcome[uint64(ctx.Event.GroupID)] = ctx.State["regex_matched"].([]string)[1]
if saveConfig() == nil {
ctx.Send("记住啦!")
ctx.SendChain(message.Text("记住啦!"))
} else {
ctx.Send("出错啦!")
ctx.SendChain(message.Text("出错啦!"))
}
})
// 入群验证开关
@ -402,9 +402,9 @@ func init() { // 插件主体
return
}
if saveConfig() == nil {
ctx.Send("已" + option)
ctx.SendChain(message.Text("已", option))
} else {
ctx.Send("出错啦!")
ctx.SendChain(message.Text("出错啦!"))
}
})
// 运行 CQ 码
@ -413,6 +413,7 @@ func init() { // 插件主体
var cmd = ctx.State["regex_matched"].([]string)[1]
cmd = strings.ReplaceAll(cmd, "&#91;", "[")
cmd = strings.ReplaceAll(cmd, "&#93;", "]")
// 可注入,权限为主人
ctx.Send(cmd)
})
}

View File

@ -1,3 +1,10 @@
/*
* @Author: Kanri
* @Date: 2021-10-15 21:23:14
* @LastEditors: Kanri
* @LastEditTime: 2021-10-15 21:40:37
* @Description:
*/
// Package minecraft MCSManager
package minecraft
@ -35,7 +42,7 @@ func init() {
_ = ctx.Parse(&model)
ctx.SendChain(message.Text("开启服务器: ", model.Args, "....."))
result := start(model.Args)
ctx.Send(result)
ctx.SendChain(message.Text(result))
})
engine.OnCommand("mcstop").SetBlock(true).
Handle(func(ctx *zero.Ctx) {
@ -43,7 +50,7 @@ func init() {
_ = ctx.Parse(&model)
ctx.SendChain(message.Text("开启服务器: ", model.Args, "....."))
result := stop(model.Args)
ctx.Send(result)
ctx.SendChain(message.Text(result))
})
}

View File

@ -32,7 +32,7 @@ func init() {
}).OnRegex("^(.{0,2})点歌(.{1,25})$").SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) {
if !limit.Load(ctx.Event.UserID).Acquire() {
ctx.Send("请稍后重试0x0...")
ctx.SendChain(message.Text("请稍后重试0x0..."))
return
}
// switch 平台

View File

@ -107,7 +107,7 @@ func init() {
}).OnRegex(`^>runcode\s(.+?)\s([\s\S]+)$`).SetBlock(true).SecondPriority().
Handle(func(ctx *zero.Ctx) {
if !limit.Load(ctx.Event.UserID).Acquire() {
ctx.Send("请稍后重试0x0...")
ctx.SendChain(message.Text("请稍后重试0x0..."))
} else {
language := ctx.State["regex_matched"].([]string)[1]
language = strings.ToLower(language)

View File

@ -27,7 +27,7 @@ func init() { // 插件主体
engine.OnRegex(`^搜图(\d+)$`).SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) {
id, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64)
ctx.Send("少女祈祷中......")
ctx.SendChain(message.Text("少女祈祷中......"))
// 获取P站插图信息
illust, err := pixiv.Works(id)
if err != nil {
@ -51,14 +51,14 @@ func init() { // 插件主体
),
)
} else {
ctx.Send("图片不存在!")
ctx.SendChain(message.Text("图片不存在!"))
}
})
// 以图搜图
engine.OnKeywordGroup([]string{"以图搜图", "搜索图片", "以图识图"}, picture.CmdMatch, picture.MustGiven).SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) {
// 开始搜索图片
ctx.Send("少女祈祷中......")
ctx.SendChain(message.Text("少女祈祷中......"))
for _, pic := range ctx.State["image_url"].([]string) {
fmt.Println(pic)
if result, err := saucenao.SauceNAO(pic); err != nil {

View File

@ -169,7 +169,7 @@ func init() { // 插件主体
ctx.SendChain(message.Text("ERROR: ", err))
return
}
ctx.Send("添加成功")
ctx.SendChain(message.Text("添加成功"))
})
engine.OnRegex(`^删除(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(22).
@ -180,10 +180,10 @@ func init() { // 插件主体
)
// 查询数据库
if err := pool.DB.Del(imgtype, fmt.Sprintf("WHERE pid=%d", id)); err != nil {
ctx.Send(fmt.Sprintf("ERROR: %v", err))
ctx.SendChain(message.Text("ERROR: ", err))
return
}
ctx.Send("删除成功")
ctx.SendChain(message.Text("删除成功"))
})
// 查询数据库涩图数量
@ -200,7 +200,7 @@ func init() { // 插件主体
state = append(state, ": ")
state = append(state, fmt.Sprintf("%d", num))
}
ctx.Send(strings.Join(state, ""))
ctx.SendChain(message.Text(state))
})
}

View File

@ -1,3 +1,10 @@
/*
* @Author: Kanri
* @Date: 2021-10-15 21:23:14
* @LastEditors: Kanri
* @LastEditTime: 2021-10-15 21:42:51
* @Description:
*/
// Package shindan 基于 https://shindanmaker.com 的测定小功能
package shindan
@ -52,6 +59,7 @@ func handle(ctx *zero.Ctx) {
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
}
// TODO: 可注入
ctx.Send(text)
}