mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
Merge branch 'master' of https://github.com/FloatTech/ZeroBot-Plugin
This commit is contained in:
commit
202d5e41a1
@ -3,6 +3,7 @@ package lolicon
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
@ -17,7 +18,7 @@ import (
|
||||
ctrl "github.com/FloatTech/zbpctrl"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
"github.com/FloatTech/zbputils/img/pool"
|
||||
imagepool "github.com/FloatTech/zbputils/img/pool"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -26,8 +27,8 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
queue = make(chan string, capacity)
|
||||
custapi = ""
|
||||
queue = make(chan string, capacity)
|
||||
customapi = ""
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -40,10 +41,21 @@ func init() {
|
||||
}).ApplySingle(ctxext.DefaultSingle)
|
||||
en.OnPrefix("随机图片").Limit(ctxext.LimitByUser).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if imgtype := strings.TrimSpace(ctx.State["args"].(string)); imgtype != "" {
|
||||
imageurl, err := getimgurl(api + "?tag=" + url.QueryEscape(imgtype))
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
if id := ctx.Send(message.Message{ctxext.FakeSenderForwardNode(ctx, message.Image(imageurl))}).ID(); id == 0 {
|
||||
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
|
||||
}
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
for i := 0; i < math.Min(cap(queue)-len(queue), 2); i++ {
|
||||
if custapi != "" {
|
||||
data, err := web.GetData(custapi)
|
||||
if customapi != "" {
|
||||
data, err := web.GetData(customapi)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
continue
|
||||
@ -51,34 +63,22 @@ func init() {
|
||||
queue <- "base64://" + base64.StdEncoding.EncodeToString(data)
|
||||
continue
|
||||
}
|
||||
rapi := api
|
||||
args := strings.TrimSpace(ctx.State["args"].(string))
|
||||
if args != "" {
|
||||
rapi += "?tag=" + url.QueryEscape(args)
|
||||
}
|
||||
data, err := web.GetData(rapi)
|
||||
imageurl, err := getimgurl(api)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
continue
|
||||
}
|
||||
json := gjson.ParseBytes(data)
|
||||
if e := json.Get("error").Str; e != "" {
|
||||
ctx.SendChain(message.Text("ERROR: ", e))
|
||||
continue
|
||||
}
|
||||
url := json.Get("data.0.urls.original").Str
|
||||
url = strings.ReplaceAll(url, "i.pixiv.cat", "i.pixiv.re")
|
||||
name := url[strings.LastIndex(url, "/")+1 : len(url)-4]
|
||||
m, err := pool.GetImage(name)
|
||||
name := imageurl[strings.LastIndex(imageurl, "/")+1 : len(imageurl)-4]
|
||||
m, err := imagepool.GetImage(name)
|
||||
if err != nil {
|
||||
m.SetFile(url)
|
||||
_, err = m.Push(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx))
|
||||
m.SetFile(imageurl)
|
||||
_, _ = m.Push(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx))
|
||||
process.SleepAbout1sTo2s()
|
||||
}
|
||||
if err == nil {
|
||||
queue <- m.String()
|
||||
} else {
|
||||
queue <- url
|
||||
queue <- imageurl
|
||||
}
|
||||
}
|
||||
}()
|
||||
@ -98,6 +98,22 @@ func init() {
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
u := strings.TrimSpace(ctx.State["args"].(string))
|
||||
ctx.SendChain(message.Text("成功设置随机图片地址为", u))
|
||||
custapi = u
|
||||
customapi = u
|
||||
})
|
||||
}
|
||||
|
||||
func getimgurl(url string) (string, error) {
|
||||
data, err := web.GetData(url)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
json := gjson.ParseBytes(data)
|
||||
if e := json.Get("error").Str; e != "" {
|
||||
return "", errors.New(e)
|
||||
}
|
||||
var imageurl string
|
||||
if imageurl = json.Get("data.0.urls.original").Str; imageurl == "" {
|
||||
return "", errors.New("未找到相关内容, 换个tag试试吧")
|
||||
}
|
||||
return strings.ReplaceAll(imageurl, "i.pixiv.cat", "i.pixiv.re"), nil
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ func init() {
|
||||
DisableOnDefault: false,
|
||||
PrivateDataFolder: "qqwife",
|
||||
Help: "一群一天一夫一妻制群老婆\n(每天凌晨刷新CP)\n" +
|
||||
"- 娶群友\n- 群老婆列表\n- 允许/禁止自由恋爱\n- 允许/禁止牛头人\n- 设置CD为xx小时 →(默认12小时)\n- 重置花名册\n" +
|
||||
"- 娶群友\n- 群老婆列表\n- 允许/禁止自由恋爱\n- 允许/禁止牛头人\n- 设置CD为xx小时 →(默认12小时)\n- 重置花名册\n- 重置所有花名册(用于清除所有群数据及其设置)\n" +
|
||||
"--------------------------------\n以下指令存在CD,不跨天刷新,前两个受指令开关\n--------------------------------\n" +
|
||||
"- (娶|嫁)@对方QQ\n自由选择对象,自由恋爱(好感度越高成功率越高,保底30%概率)\n" +
|
||||
"- 当[对方Q号|@对方QQ]的小三\n我和你才是真爱,为了你我愿意付出一切(好感度越高成功率越高,保底10%概率)\n" +
|
||||
|
||||
@ -180,19 +180,34 @@ func (sql *婚姻登记) 清理花名册(gid string) error {
|
||||
return err
|
||||
}
|
||||
if gid != "0" {
|
||||
grouplist = []string{gid}
|
||||
grouplist = []string{"group" + gid}
|
||||
}
|
||||
for _, gid := range grouplist {
|
||||
err = sql.db.Drop("group" + gid)
|
||||
if err != nil {
|
||||
if gid == "favorability" {
|
||||
continue
|
||||
}
|
||||
err = sql.db.Drop(gid)
|
||||
if err != nil || gid == "updateinfo" {
|
||||
continue
|
||||
}
|
||||
gidint, _ := strconv.ParseInt(gid, 10, 64)
|
||||
updateinfo := updateinfo{
|
||||
upinfo := updateinfo{
|
||||
GID: gidint,
|
||||
Updatetime: time.Now().Format("2006/01/02"),
|
||||
CanMatch: 1,
|
||||
CanNtr: 1,
|
||||
CDtime: 12,
|
||||
}
|
||||
err = sql.db.Insert("updateinfo", &updateinfo)
|
||||
err = sql.db.Create("updateinfo", &updateinfo{})
|
||||
if err != nil {
|
||||
if err = sql.db.Drop("updateinfo"); err == nil {
|
||||
err = sql.db.Create("updateinfo", &updateinfo{})
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err = sql.db.Insert("updateinfo", &upinfo)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -95,15 +95,8 @@ func init() { // 插件主体
|
||||
"直链: ", "https://pixivel.moe/detail?id=", illust.Pid,
|
||||
)
|
||||
if imgs != nil {
|
||||
if zero.OnlyGroup(ctx) {
|
||||
ctx.SendGroupForwardMessage(ctx.Event.GroupID, message.Message{
|
||||
ctxext.FakeSenderForwardNode(ctx, txt),
|
||||
ctxext.FakeSenderForwardNode(ctx, imgs...),
|
||||
})
|
||||
} else {
|
||||
// 发送搜索结果
|
||||
ctx.Send(append(imgs, message.Text("\n"), txt))
|
||||
}
|
||||
ctx.Send(message.Message{ctxext.FakeSenderForwardNode(ctx, txt),
|
||||
ctxext.FakeSenderForwardNode(ctx, imgs...)})
|
||||
} else {
|
||||
// 图片下载失败,仅发送文字结果
|
||||
ctx.SendChain(txt)
|
||||
@ -113,7 +106,7 @@ func init() { // 插件主体
|
||||
}
|
||||
})
|
||||
// 以图搜图
|
||||
engine.OnKeywordGroup([]string{"以图搜图", "搜索图片", "以图识图"}, zero.OnlyGroup, zero.MustProvidePicture).SetBlock(true).
|
||||
engine.OnKeywordGroup([]string{"以图搜图", "搜索图片", "以图识图"}, zero.MustProvidePicture).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
// 开始搜索图片
|
||||
ctx.SendChain(message.Text("少女祈祷中..."))
|
||||
@ -154,7 +147,7 @@ func init() { // 插件主体
|
||||
msg = append(msg, message.Image(pic))
|
||||
}
|
||||
msg = append(msg, message.Text("\n图源: ", result.Header.IndexName, binary.BytesToString(b)))
|
||||
ctx.Send(msg)
|
||||
ctx.Send(ctxext.FakeSenderForwardNode(ctx, msg...))
|
||||
if s > 80.0 {
|
||||
continue
|
||||
}
|
||||
@ -182,10 +175,7 @@ func init() { // 插件主体
|
||||
))),
|
||||
)
|
||||
}
|
||||
if id := ctx.SendGroupForwardMessage(
|
||||
ctx.Event.GroupID,
|
||||
msg,
|
||||
).Get("message_id").Int(); id == 0 {
|
||||
if id := ctx.Send(msg).ID(); id == 0 {
|
||||
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ func init() { // 插件主体
|
||||
}
|
||||
}
|
||||
// 从缓冲池里抽一张
|
||||
if id := ctx.SendChain(*pool.pop(imgtype)); id.ID() == 0 {
|
||||
if id := ctx.Send(ctxext.FakeSenderForwardNode(ctx, *pool.pop(imgtype))); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
|
||||
}
|
||||
})
|
||||
|
||||
@ -162,7 +162,7 @@ func init() {
|
||||
message.Text("\n其释义为: ", description)}
|
||||
msg[i] = ctxext.FakeSenderForwardNode(ctx, tarotMsg...)
|
||||
}
|
||||
ctx.SendGroupForwardMessage(ctx.Event.GroupID, msg)
|
||||
ctx.Send(msg)
|
||||
})
|
||||
|
||||
engine.OnRegex(`^解塔罗牌\s?(.*)`, getTarot).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) {
|
||||
@ -248,7 +248,7 @@ func init() {
|
||||
return
|
||||
}
|
||||
msg[info.CardsNum] = ctxext.FakeSenderForwardNode(ctx, []message.MessageSegment{message.Image("base64://" + binary.BytesToString(formation))}...)
|
||||
ctx.SendGroupForwardMessage(ctx.Event.GroupID, msg)
|
||||
ctx.Send(msg)
|
||||
} else {
|
||||
ctx.SendChain(message.Text("没有找到", match, "噢~\n现有牌阵列表: \n", strings.Join(formationName, "\n")))
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user