mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-21 15:30:09 +08:00
* feat:添加文字转图片,改造长文字 * fix:修改log * fix:修改条件 * fix:不保存图片 * fix:增加block和优先级 * fix:文件夹首字母大写 * fix:修改解签为图片 * feat:添加拟声鸟 * fix:清理缓存 * fix:换一个音频 * fix:小修格式 * fix:修一下lint * fix:修一下lint * fix:修一下lint * fix:修一下lint * fix:修一下lint * fix:修一下lint * fix:修一下lint * fix:修一下lint * fix:10s一次 * fix:10s一次 * fix:修lint
74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
// Package shindan 基于 https://shindanmaker.com 的测定小功能
|
|
package shindan
|
|
|
|
import (
|
|
"github.com/FloatTech/ZeroBot-Plugin/utils/txt2img"
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
|
"time"
|
|
|
|
"github.com/FloatTech/AnimeAPI/shindanmaker"
|
|
zero "github.com/wdvxdr1123/ZeroBot"
|
|
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
|
"github.com/wdvxdr1123/ZeroBot/message"
|
|
|
|
"github.com/FloatTech/ZeroBot-Plugin/control"
|
|
"github.com/FloatTech/ZeroBot-Plugin/utils/ctxext"
|
|
)
|
|
|
|
var (
|
|
// 限制调用频率
|
|
limit = rate.NewManager(time.Minute*5, 5)
|
|
)
|
|
|
|
func init() {
|
|
engine := control.Register("shindan", &control.Options{
|
|
DisableOnDefault: false,
|
|
Help: "shindan\n" +
|
|
"- 今天是什么少女[@xxx]\n" +
|
|
"- 异世界转生[@xxx]\n" +
|
|
"- 卖萌[@xxx]\n" +
|
|
"- 抽老婆[@xxx]",
|
|
})
|
|
engine.OnPrefix("异世界转生", number(587874)).SetBlock(true).FirstPriority().Handle(handle)
|
|
engine.OnPrefix("今天是什么少女", number(162207)).SetBlock(true).FirstPriority().Handle(handle)
|
|
engine.OnPrefix("卖萌", number(360578)).SetBlock(true).FirstPriority().Handle(handle)
|
|
engine.OnPrefix("抽老婆", number(1075116)).SetBlock(true).FirstPriority().Handle(handle)
|
|
}
|
|
|
|
// shindanmaker 处理函数
|
|
func handle(ctx *zero.Ctx) {
|
|
if !limit.Load(ctx.Event.UserID).Acquire() {
|
|
ctx.SendChain(message.Text("请稍后重试0x0..."))
|
|
return
|
|
}
|
|
// 获取名字
|
|
name := ctxext.NickName(ctx)
|
|
// 调用接口
|
|
text, err := shindanmaker.Shindanmaker(ctx.State["id"].(int64), name)
|
|
if err != nil {
|
|
ctx.SendChain(message.Text("ERROR: ", err))
|
|
}
|
|
// TODO: 可注入
|
|
switch ctx.State["id"].(int64) {
|
|
case 587874, 162207:
|
|
data, err := txt2img.RenderToBase64(text, 40, 20)
|
|
if err != nil {
|
|
log.Errorln("[shindan]:", err)
|
|
}
|
|
if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id == 0 {
|
|
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
|
|
}
|
|
default:
|
|
ctx.Send(text)
|
|
}
|
|
}
|
|
|
|
// 传入 shindanmaker id
|
|
func number(id int64) func(ctx *zero.Ctx) bool {
|
|
return func(ctx *zero.Ctx) bool {
|
|
ctx.State["id"] = id
|
|
return true
|
|
}
|
|
}
|