mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-11 09:40:25 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94abf34466 | ||
|
|
91396c8885 | ||
|
|
cb3cfa054b | ||
|
|
ebf58d4b73 | ||
|
|
f704cddae8 | ||
|
|
f03d2f3940 | ||
|
|
087c6c0298 | ||
|
|
be49ba83b3 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
data/SetuTime/cache
|
||||
data/control
|
||||
data/SetuTime/search
|
||||
data/manager
|
||||
data/acgimage
|
||||
|
||||
37
README.md
37
README.md
@@ -19,7 +19,11 @@
|
||||
</div>
|
||||
|
||||
## 功能
|
||||
|
||||
- **插件控制**
|
||||
- [x] /启用 xxx
|
||||
- [x] /禁用 xxx
|
||||
- [x] /用法 xxx
|
||||
- [x] /服务列表
|
||||
- **聊天** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_chat"`
|
||||
- [x] [BOT名字]
|
||||
- [x] [戳一戳BOT]
|
||||
@@ -59,11 +63,10 @@
|
||||
- [ ] 警告[@xxx]
|
||||
- [x] run[xxx]
|
||||
- **GitHub仓库搜索** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_github"`
|
||||
- [x] > github [xxx]
|
||||
- [x] > github -p [xxx]
|
||||
- [x] >github [xxx]
|
||||
- [x] >github -p [xxx]
|
||||
- **在线代码运行** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_runcode"`
|
||||
- [x] > runcode help
|
||||
- [x] > runcode [on/off]
|
||||
- [x] > runcode [language] help
|
||||
- [x] > runcode [language] [code block]
|
||||
- **点歌** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_music"`
|
||||
- [x] 点歌[xxx]
|
||||
@@ -99,29 +102,33 @@
|
||||
- [x] 太涩了(撤回最近发的图)
|
||||
- [x] 评价图片(发送一张图片让bot评分)
|
||||
- **浅草寺求签** `github.com/FloatTech/ZeroBot-Plugin/plugin_omikuji`
|
||||
- 本插件要求`Go`版本大于等于`1.17`
|
||||
- [x] @BOT 求签|运势|占卜
|
||||
- [x] 求签|运势|占卜
|
||||
- **bilibili** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili"`
|
||||
- [x] > bili info [名字]
|
||||
- [x] >vup info [名字|uid]
|
||||
- [x] >user info [名字|uid]
|
||||
- [x] /开启粉丝日报
|
||||
- **嘉然** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_diana"`
|
||||
- [x] @BOT 小作文
|
||||
- [x] @BOT 发大病
|
||||
- [x] @BOT 教你一篇小作文[作文]
|
||||
- [x] 小作文
|
||||
- [x] 发大病
|
||||
- [x] 教你一篇小作文[作文]
|
||||
- [x] [回复]查重
|
||||
- **AIfalse** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_ai_false"`
|
||||
- [x] 查询计算机当前活跃度 [身体检查]
|
||||
- [ ] 简易语音
|
||||
- [ ] 爬图合成 [@xxx]
|
||||
- **minecraft** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_minecraft"`
|
||||
- [x] 具体指令看代码
|
||||
- [x] /mcstart xxx
|
||||
- [x] /mcstop xxx
|
||||
- [x] /mclist servername
|
||||
- 注:此功能实现依赖[MCSManager](https://github.com/Suwings/MCSManager)项目对服务器的管理api,mc服务器如果没有在该管理平台部署此功能无效
|
||||
- **炉石** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_hs"`
|
||||
- [x] 搜卡[xxxx]
|
||||
- [x] [卡组代码xxx]
|
||||
- [x] [卡组代码xxx]
|
||||
- 注:更多搜卡指令参数:https://hs.fbigame.com/misc/searchhelp
|
||||
- **青云客** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_qingyunke"`
|
||||
- [x] @Bot 任意文本(任意一句话回复)
|
||||
- [x] 关闭自动回复
|
||||
- [x] 启动自动回复
|
||||
- **关键字搜图** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_image_finder"`
|
||||
- [x] 来张 [xxx]
|
||||
- **TODO...**
|
||||
|
||||
## 使用方法
|
||||
|
||||
12
control/register.go
Normal file
12
control/register.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package control
|
||||
|
||||
import (
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
)
|
||||
|
||||
func Register(service string, o *Options) *zero.Engine {
|
||||
engine := zero.New()
|
||||
m := *New(service, o)
|
||||
engine.UsePreHandler(m.Handler())
|
||||
return engine
|
||||
}
|
||||
179
control/rule.go
Normal file
179
control/rule.go
Normal file
@@ -0,0 +1,179 @@
|
||||
// Package control 控制插件的启用与优先级等
|
||||
package control
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
. "github.com/FloatTech/ZeroBot-Plugin/data"
|
||||
)
|
||||
|
||||
var (
|
||||
db = &Sqlite{DBPath: "data/control/plugins.db"}
|
||||
// managers 每个插件对应的管理
|
||||
managers = map[string]*Control{}
|
||||
mu = sync.RWMutex{}
|
||||
)
|
||||
|
||||
// Control is to control the plugins.
|
||||
type Control struct {
|
||||
sync.RWMutex
|
||||
service string
|
||||
options Options
|
||||
}
|
||||
|
||||
// New returns Manager with settings.
|
||||
func New(service string, o *Options) *Control {
|
||||
m := &Control{service: service,
|
||||
options: func() Options {
|
||||
if o == nil {
|
||||
return Options{}
|
||||
}
|
||||
return *o
|
||||
}(),
|
||||
}
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
managers[service] = m
|
||||
err := db.Create(service, &grpcfg{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// Enable enables a group to pass the Manager.
|
||||
func (m *Control) Enable(groupID int64) {
|
||||
m.Lock()
|
||||
err := db.Insert(m.service, &grpcfg{groupID, 0})
|
||||
if err != nil {
|
||||
logrus.Errorf("[control] %v", err)
|
||||
}
|
||||
m.Unlock()
|
||||
}
|
||||
|
||||
// Disable disables a group to pass the Manager.
|
||||
func (m *Control) Disable(groupID int64) {
|
||||
m.Lock()
|
||||
err := db.Insert(m.service, &grpcfg{groupID, 1})
|
||||
if err != nil {
|
||||
logrus.Errorf("[control] %v", err)
|
||||
}
|
||||
m.Unlock()
|
||||
}
|
||||
|
||||
// Handler 返回 预处理器
|
||||
func (m *Control) Handler() zero.Rule {
|
||||
return func(ctx *zero.Ctx) bool {
|
||||
m.RLock()
|
||||
ctx.State["manager"] = m
|
||||
var c grpcfg
|
||||
err := db.Find(m.service, &c, "WHERE gid = "+strconv.FormatInt(ctx.Event.GroupID, 10))
|
||||
if err == nil {
|
||||
m.RUnlock()
|
||||
logrus.Debugf("[control] plugin %s of grp %d : %d", m.service, c.GroupID, c.Disable)
|
||||
return c.Disable == 0
|
||||
} else {
|
||||
logrus.Errorf("[control] %v", err)
|
||||
}
|
||||
m.RUnlock()
|
||||
if m.options.DisableOnDefault {
|
||||
m.Disable(ctx.Event.GroupID)
|
||||
} else {
|
||||
m.Enable(ctx.Event.GroupID)
|
||||
}
|
||||
return !m.options.DisableOnDefault
|
||||
}
|
||||
}
|
||||
|
||||
// Lookup returns a Manager by the service name, if
|
||||
// not exist, it will returns nil.
|
||||
func Lookup(service string) (*Control, bool) {
|
||||
mu.RLock()
|
||||
defer mu.RUnlock()
|
||||
m, ok := managers[service]
|
||||
return m, ok
|
||||
}
|
||||
|
||||
// ForEach iterates through managers.
|
||||
func ForEach(iterator func(key string, manager *Control) bool) {
|
||||
mu.RLock()
|
||||
m := copyMap(managers)
|
||||
mu.RUnlock()
|
||||
for k, v := range m {
|
||||
if !iterator(k, v) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func copyMap(m map[string]*Control) map[string]*Control {
|
||||
ret := make(map[string]*Control, len(m))
|
||||
for k, v := range m {
|
||||
ret[k] = v
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func Init() {
|
||||
err := os.MkdirAll("data/control", 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
zero.OnCommandGroup([]string{"启用", "enable"}, zero.AdminPermission, zero.OnlyGroup).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
model := extension.CommandModel{}
|
||||
_ = ctx.Parse(&model)
|
||||
service, ok := Lookup(model.Args)
|
||||
if !ok {
|
||||
ctx.Send("没有找到指定服务!")
|
||||
}
|
||||
service.Enable(ctx.Event.GroupID)
|
||||
ctx.Send(message.Text("已启用服务: " + model.Args))
|
||||
})
|
||||
|
||||
zero.OnCommandGroup([]string{"禁用", "disable"}, zero.AdminPermission, zero.OnlyGroup).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
model := extension.CommandModel{}
|
||||
_ = ctx.Parse(&model)
|
||||
service, ok := Lookup(model.Args)
|
||||
if !ok {
|
||||
ctx.Send("没有找到指定服务!")
|
||||
}
|
||||
service.Disable(ctx.Event.GroupID)
|
||||
ctx.Send(message.Text("已关闭服务: " + model.Args))
|
||||
})
|
||||
|
||||
zero.OnCommandGroup([]string{"用法", "usage"}, zero.AdminPermission, zero.OnlyGroup).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
model := extension.CommandModel{}
|
||||
_ = ctx.Parse(&model)
|
||||
service, ok := Lookup(model.Args)
|
||||
if !ok {
|
||||
ctx.Send("没有找到指定服务!")
|
||||
}
|
||||
if service.options.Help != "" {
|
||||
ctx.Send(service.options.Help)
|
||||
} else {
|
||||
ctx.Send("该服务无帮助!")
|
||||
}
|
||||
})
|
||||
|
||||
zero.OnCommandGroup([]string{"服务列表", "service_list"}, zero.AdminPermission, zero.OnlyGroup).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
msg := `---服务列表---`
|
||||
i := 0
|
||||
ForEach(func(key string, manager *Control) bool {
|
||||
i++
|
||||
msg += "\n" + strconv.Itoa(i) + `: ` + key
|
||||
return true
|
||||
})
|
||||
ctx.Send(message.Text(msg))
|
||||
})
|
||||
}
|
||||
13
control/tables.go
Normal file
13
control/tables.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package control
|
||||
|
||||
// grpcfg holds the group config for the Manager.
|
||||
type grpcfg struct {
|
||||
GroupID int64 `db:"gid"` // GroupID 群号
|
||||
Disable int64 `db:"disable"` // Disable 默认启用该插件
|
||||
}
|
||||
|
||||
// Options holds the optional parameters for the Manager.
|
||||
type Options struct {
|
||||
DisableOnDefault bool
|
||||
Help string // 帮助文本信息
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package setutime
|
||||
package data
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
@@ -8,16 +8,16 @@ import (
|
||||
_ "modernc.org/sqlite" // 引入sqlite
|
||||
)
|
||||
|
||||
// sqlite 数据库对象
|
||||
type sqlite struct {
|
||||
// Sqlite 数据库对象
|
||||
type Sqlite struct {
|
||||
DB *sql.DB
|
||||
DBPath string
|
||||
}
|
||||
|
||||
// create 生成数据库
|
||||
// Create 生成数据库
|
||||
// 默认结构体的第一个元素为主键
|
||||
// 返回错误
|
||||
func (db *sqlite) create(table string, objptr interface{}) (err error) {
|
||||
func (db *Sqlite) Create(table string, objptr interface{}) (err error) {
|
||||
if db.DB == nil {
|
||||
database, err := sql.Open("sqlite", db.DBPath)
|
||||
if err != nil {
|
||||
@@ -53,10 +53,10 @@ func (db *sqlite) create(table string, objptr interface{}) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// insert 插入数据集
|
||||
// Insert 插入数据集
|
||||
// 默认结构体的第一个元素为主键
|
||||
// 返回错误
|
||||
func (db *sqlite) insert(table string, objptr interface{}) (err error) {
|
||||
func (db *Sqlite) Insert(table string, objptr interface{}) (err error) {
|
||||
rows, err := db.DB.Query("SELECT * FROM " + table)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -71,7 +71,7 @@ func (db *sqlite) insert(table string, objptr interface{}) (err error) {
|
||||
top = len(tags) - 1
|
||||
cmd = []string{}
|
||||
)
|
||||
cmd = append(cmd, "INSERT INTO")
|
||||
cmd = append(cmd, "REPLACE INTO")
|
||||
cmd = append(cmd, table)
|
||||
for i := range tags {
|
||||
switch i {
|
||||
@@ -112,11 +112,11 @@ func (db *sqlite) insert(table string, objptr interface{}) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// find 查询数据库
|
||||
// Find 查询数据库
|
||||
// condition 可为"WHERE id = 0"
|
||||
// 默认字段与结构体元素顺序一致
|
||||
// 返回错误
|
||||
func (db *sqlite) find(table string, objptr interface{}, condition string) (err error) {
|
||||
func (db *Sqlite) Find(table string, objptr interface{}, condition string) (err error) {
|
||||
var cmd = []string{}
|
||||
cmd = append(cmd, "SELECT * FROM ")
|
||||
cmd = append(cmd, table)
|
||||
@@ -142,10 +142,35 @@ func (db *sqlite) find(table string, objptr interface{}, condition string) (err
|
||||
return nil
|
||||
}
|
||||
|
||||
// del 删除数据库
|
||||
// ListTables 列出所有表名
|
||||
// 返回所有表名+错误
|
||||
func (db *Sqlite) ListTables() (s []string, err error) {
|
||||
rows, err := db.DB.Query("SELECT name FROM sqlite_master where type='table' order by name;")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
return nil, rows.Err()
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
objptr := new(string)
|
||||
err = rows.Scan(objptr)
|
||||
if err == nil {
|
||||
s = append(s, *objptr)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Del 删除数据库
|
||||
// condition 可为"WHERE id = 0"
|
||||
// 返回错误
|
||||
func (db *sqlite) del(table string, condition string) (err error) {
|
||||
func (db *Sqlite) Del(table string, condition string) (err error) {
|
||||
var cmd = []string{}
|
||||
cmd = append(cmd, "DELETE FROM")
|
||||
cmd = append(cmd, table)
|
||||
@@ -161,9 +186,9 @@ func (db *sqlite) del(table string, condition string) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// count 查询数据库行数
|
||||
// Count 查询数据库行数
|
||||
// 返回行数以及错误
|
||||
func (db *sqlite) count(table string) (num int, err error) {
|
||||
func (db *Sqlite) Count(table string) (num int, err error) {
|
||||
var cmd = []string{}
|
||||
cmd = append(cmd, "SELECT * FROM")
|
||||
cmd = append(cmd, table)
|
||||
2
go.sum
2
go.sum
@@ -22,6 +22,7 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
@@ -68,6 +69,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
|
||||
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
|
||||
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 h1:J6v8awz+me+xeb/cUTotKgceAYouhIB3pjzgRd6IlGk=
|
||||
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go.mod h1:tzym/CEb5jnFI+Q0k4Qq3+LvRF4gO3E2pxS8fHP8jcA=
|
||||
|
||||
2
main.go
2
main.go
@@ -8,6 +8,7 @@ import (
|
||||
// 注:以下插件均可通过前面加 // 注释,注释后停用并不加载插件
|
||||
// 下列插件可与 wdvxdr1123/ZeroBot v1.1.2 以上配合单独使用
|
||||
// 词库类
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_atri" // ATRI词库
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_chat" // 基础词库
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_qingyunke" //青云客
|
||||
@@ -60,6 +61,7 @@ func init() {
|
||||
LogFormat: "[zero][%time%][%lvl%]: %msg% \n",
|
||||
})
|
||||
log.SetLevel(log.DebugLevel)
|
||||
control.Init()
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
"github.com/FloatTech/AnimeAPI/picture"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -31,7 +33,16 @@ var (
|
||||
func init() { // 插件主体
|
||||
// 初始化 classify
|
||||
classify.Init(datapath)
|
||||
zero.OnRegex(`^设置随机图片网址(.*)$`, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).SetPriority(20).
|
||||
engine := control.Register("acgimage", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "随机图片与AI点评\n" +
|
||||
"- 随机图片(评级大于6的图将私发)\n" +
|
||||
"- 直接随机(无r18检测,务必小心,仅管理可用)\n" +
|
||||
"- 设置随机图片网址[url]\n" +
|
||||
"- 太涩了(撤回最近发的图)\n" +
|
||||
"- 评价图片(发送一张图片让bot评分)",
|
||||
})
|
||||
engine.OnRegex(`^设置随机图片网址(.*)$`, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).SetPriority(20).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
url := ctx.State["regex_matched"].([]string)[1]
|
||||
if !strings.HasPrefix(url, "http") {
|
||||
@@ -42,7 +53,7 @@ func init() { // 插件主体
|
||||
}
|
||||
})
|
||||
// 有保护的随机图片
|
||||
zero.OnFullMatch("随机图片", zero.OnlyGroup).SetBlock(true).SetPriority(24).
|
||||
engine.OnFullMatch("随机图片", zero.OnlyGroup).SetBlock(true).SetPriority(24).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if classify.CanVisit(5) {
|
||||
go func() {
|
||||
@@ -54,7 +65,7 @@ func init() { // 插件主体
|
||||
}
|
||||
})
|
||||
// 直接随机图片,无r18保护,后果自负。如果出r18图可尽快通过发送"太涩了"撤回
|
||||
zero.OnFullMatch("直接随机", zero.OnlyGroup, zero.AdminPermission).SetBlock(true).SetPriority(24).
|
||||
engine.OnFullMatch("直接随机", zero.OnlyGroup, zero.AdminPermission).SetBlock(true).SetPriority(24).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if block {
|
||||
ctx.Send("请稍后再试哦")
|
||||
@@ -71,12 +82,12 @@ func init() { // 插件主体
|
||||
}
|
||||
})
|
||||
// 撤回最后的直接随机图片
|
||||
zero.OnFullMatch("太涩了").SetBlock(true).SetPriority(24).
|
||||
engine.OnFullMatch("太涩了").SetBlock(true).SetPriority(24).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
go cancel(ctx)
|
||||
})
|
||||
// 上传一张图进行评价
|
||||
zero.OnKeywordGroup([]string{"评价图片"}, zero.OnlyGroup, picture.CmdMatch, picture.MustGiven).SetBlock(true).SetPriority(24).
|
||||
engine.OnKeywordGroup([]string{"评价图片"}, zero.OnlyGroup, picture.CmdMatch, picture.MustGiven).SetBlock(true).SetPriority(24).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
ctx.Send("少女祈祷中...")
|
||||
for _, url := range ctx.State["image_url"].([]string) {
|
||||
@@ -86,7 +97,7 @@ func init() { // 插件主体
|
||||
}(url)
|
||||
}
|
||||
})
|
||||
zero.OnRegex(`^给你点提示哦:(.*)$`, zero.OnlyPrivate).SetBlock(true).SetPriority(20).
|
||||
engine.OnRegex(`^给你点提示哦:(.*)$`, zero.OnlyPrivate).SetBlock(true).SetPriority(20).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
dhash := ctx.State["regex_matched"].([]string)[1]
|
||||
if len(dhash) == 5*3 {
|
||||
|
||||
@@ -9,12 +9,19 @@ import (
|
||||
"github.com/shirou/gopsutil/disk"
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
zero.OnFullMatchGroup([]string{"检查身体", "自检", "启动自检", "系统状态"}, zero.AdminPermission).
|
||||
engine := control.Register("aifalse", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "AIfalse\n" +
|
||||
"- 查询计算机当前活跃度[检查身体|自检|启动自检|系统状态",
|
||||
})
|
||||
engine.OnFullMatchGroup([]string{"检查身体", "自检", "启动自检", "系统状态"}, zero.AdminPermission).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
ctx.SendChain(message.Text(
|
||||
"* CPU占用率: ", cpuPercent(), "%\n",
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -18,7 +20,11 @@ func init() { // 插件主体
|
||||
// TODO: 1.17 特性暂不增加
|
||||
// rand.Seed(time.Now().UnixMicro())
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
zero.OnFullMatchGroup([]string{"waifu", "随机waifu"}).SetPriority(10).
|
||||
control.Register("aiwife", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "AIWife\n" +
|
||||
"- waifu|随机waifu",
|
||||
}).OnFullMatchGroup([]string{"waifu", "随机waifu"}).SetPriority(10).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
miku := rand.Intn(100000) + 1
|
||||
ctx.SendChain(message.At(ctx.Event.UserID), message.Image(fmt.Sprintf(bed, miku)))
|
||||
|
||||
@@ -23,7 +23,7 @@ type follower struct {
|
||||
|
||||
// 开启日报推送
|
||||
func init() {
|
||||
zero.OnFullMatch("/开启粉丝日报", zero.AdminPermission).
|
||||
engine.OnFullMatch("/开启粉丝日报", zero.AdminPermission).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
fansDaily(ctx.Event.GroupID) // 群号传进去给下面发信息的函数
|
||||
})
|
||||
|
||||
@@ -8,11 +8,22 @@ import (
|
||||
"github.com/tidwall/gjson"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
)
|
||||
|
||||
var engine *zero.Engine
|
||||
|
||||
// 查成分的
|
||||
func init() {
|
||||
zero.OnRegex(`^>user info\s(.{1,25})$`).
|
||||
engine = control.Register("bilibili", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "bilibili\n" +
|
||||
"- >vup info [名字|uid]\n" +
|
||||
"- >user info [名字|uid]\n" +
|
||||
"- /开启粉丝日报",
|
||||
})
|
||||
engine.OnRegex(`^>user info\s(.{1,25})$`).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
keyword := ctx.State["regex_matched"].([]string)[1]
|
||||
rest, err := uid(keyword)
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
// 查vup粉丝数据
|
||||
func init() {
|
||||
zero.OnRegex(`^>vup info\s?(.{1,25})$`).
|
||||
engine.OnRegex(`^>vup info\s?(.{1,25})$`).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
keyword := ctx.State["regex_matched"].([]string)[1]
|
||||
res, err := uid(keyword)
|
||||
|
||||
@@ -8,25 +8,36 @@ import (
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
"github.com/FloatTech/ZeroBot-Plugin/plugin_diana/data"
|
||||
)
|
||||
|
||||
var engine *zero.Engine
|
||||
|
||||
func init() {
|
||||
engine = control.Register("diana", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "嘉然\n" +
|
||||
"- 小作文\n" +
|
||||
"- 发大病\n" +
|
||||
"- 教你一篇小作文[作文]\n" +
|
||||
"- [回复]查重",
|
||||
})
|
||||
// 随机发送一篇上面的小作文
|
||||
zero.OnFullMatch("小作文", zero.OnlyToMe).
|
||||
engine.OnFullMatch("小作文").
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
// 绕过第一行发病
|
||||
ctx.Send((*data.Array)[rand.Intn(len(*data.Array)-1)+1])
|
||||
})
|
||||
// 逆天
|
||||
zero.OnFullMatch("发大病", zero.OnlyToMe).
|
||||
engine.OnFullMatch("发大病").
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
// 第一行是发病
|
||||
ctx.Send((*data.Array)[0])
|
||||
})
|
||||
// 增加小作文
|
||||
zero.OnRegex(`^教你一篇小作文(.*)$`, zero.AdminPermission).
|
||||
engine.OnRegex(`^教你一篇小作文(.*)$`, zero.AdminPermission).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
err := data.AddText(ctx.State["regex_matched"].([]string)[1])
|
||||
if err != nil {
|
||||
|
||||
@@ -93,6 +93,8 @@ func LoadText() error {
|
||||
func AddText(txt string) error {
|
||||
sum := md5.Sum(str2bytes(txt))
|
||||
if txt != "" && !isin(sum) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
compo.Array = append(compo.Array, txt)
|
||||
md5s = append(md5s, sum)
|
||||
return savecompo()
|
||||
@@ -114,13 +116,10 @@ func savecompo() error {
|
||||
data, err := compo.Marshal()
|
||||
if err == nil {
|
||||
if _, err := os.Stat(datapath); err == nil || os.IsExist(err) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
f, err1 := os.OpenFile(pbfile, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
|
||||
if err1 == nil {
|
||||
_, err2 := f.Write(data)
|
||||
f.Close()
|
||||
|
||||
return err2
|
||||
}
|
||||
return err1
|
||||
|
||||
@@ -28,7 +28,7 @@ type zhiwang struct {
|
||||
|
||||
// 小作文查重: 回复要查的消息 查重
|
||||
func init() {
|
||||
zero.OnMessage(fullmatch("查重")).
|
||||
engine.OnMessage(fullmatch("查重")).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
msg := ctx.Event.Message
|
||||
if msg[0].Type == "reply" {
|
||||
|
||||
@@ -12,11 +12,18 @@ import (
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
zero.OnRegex(`^>github\s(-.{1,10}? )?(.*)$`).SetBlock(true).FirstPriority().
|
||||
control.Register("github", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "GitHub仓库搜索\n" +
|
||||
"- >github [xxx]\n" +
|
||||
"- >github -p [xxx]",
|
||||
}).OnRegex(`^>github\s(-.{1,10}? )?(.*)$`).SetBlock(true).FirstPriority().
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
// 发送请求
|
||||
header := http.Header{
|
||||
|
||||
@@ -12,6 +12,8 @@ import (
|
||||
"github.com/tidwall/gjson"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
)
|
||||
|
||||
const cachedir = "data/hs/"
|
||||
@@ -27,7 +29,15 @@ func init() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
zero.OnRegex(`^搜卡(.+)$`).
|
||||
|
||||
engine := control.Register("hs", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "炉石\n" +
|
||||
"- 搜卡[xxxx]\n" +
|
||||
"- [卡组代码xxx]\n" +
|
||||
"- 更多搜卡指令参数:https://hs.fbigame.com/misc/searchhelp",
|
||||
})
|
||||
engine.OnRegex(`^搜卡(.+)$`).
|
||||
SetBlock(true).SetPriority(20).Handle(func(ctx *zero.Ctx) {
|
||||
List := ctx.State["regex_matched"].([]string)[1]
|
||||
g := sh(List)
|
||||
@@ -67,7 +77,7 @@ func init() {
|
||||
}
|
||||
})
|
||||
// 卡组
|
||||
zero.OnRegex(`^[\s\S]*?(AAE[a-zA-Z0-9/\+=]{70,})[\s\S]*$`).
|
||||
engine.OnRegex(`^[\s\S]*?(AAE[a-zA-Z0-9/\+=]{70,})[\s\S]*$`).
|
||||
SetBlock(true).SetPriority(20).Handle(func(ctx *zero.Ctx) {
|
||||
fmt.Print("成功")
|
||||
List := ctx.State["regex_matched"].([]string)[1]
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
)
|
||||
|
||||
type resultjson struct {
|
||||
@@ -59,7 +61,11 @@ type resultjson struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
zero.OnRegex(`^来张 (.*)$`, zero.AdminPermission).
|
||||
control.Register("imgfinder", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "关键字搜图\n" +
|
||||
"- 来张 [xxx]",
|
||||
}).OnRegex(`^来张 (.*)$`, zero.AdminPermission).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
keyword := ctx.State["regex_matched"].([]string)[1]
|
||||
soutujson := soutuapi(keyword)
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
"github.com/tidwall/gjson"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -21,7 +23,11 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
zero.OnFullMatch("来份萝莉").
|
||||
control.Register("lolicon", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "lolicon\n" +
|
||||
"- 来份萝莉",
|
||||
}).OnFullMatch("来份萝莉").
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
go func() {
|
||||
for i := 0; i < min(cap(queue)-len(queue), 2); i++ {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
@@ -36,30 +37,28 @@ type resultjson struct {
|
||||
} `json:"players"`
|
||||
}
|
||||
|
||||
var (
|
||||
servers = make(map[string]string)
|
||||
)
|
||||
|
||||
func init() {
|
||||
zero.OnRegex(`^/list (.*)$`).
|
||||
// 这里填对应mc服务器的登录地址
|
||||
servers["ftbi"] = "115.28.186.22:25710"
|
||||
servers["ges"] = "115.28.186.22:25701"
|
||||
|
||||
engine.OnCommand("mclist").
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
model := extension.CommandModel{}
|
||||
_ = ctx.Parse(&model)
|
||||
// 支持多个服务器
|
||||
switch ctx.State["regex_matched"].([]string)[1] {
|
||||
case "ftbi": // 这里对应触发指令里的服务器名称
|
||||
ftbijson := infoapi("115.28.186.22:25710") // 这里填对应mc服务器的登录地址
|
||||
var str = ftbijson.Players.List
|
||||
cs := strings.Join(str, "\n")
|
||||
ctx.SendChain(message.Text(
|
||||
"服务器名字: ", ftbijson.Motd.Raw[0], "\n",
|
||||
"在线人数: ", ftbijson.Players.Online, "/", ftbijson.Players.Max, "\n",
|
||||
"以下为玩家名字: ", "\n", cs,
|
||||
))
|
||||
case "ges": // 这里对应触发指令里的服务器名称
|
||||
gesjson := infoapi("115.28.186.22:25701") // 这里填对应mc服务器的登录地址
|
||||
var str = gesjson.Players.List
|
||||
cs := strings.Join(str, "\n")
|
||||
ctx.SendChain(message.Text(
|
||||
"服务器名字: ", gesjson.Motd.Raw[0], "\n",
|
||||
"在线人数: ", gesjson.Players.Online, "/", gesjson.Players.Max, "\n",
|
||||
"以下为玩家名字: ", "\n", cs,
|
||||
))
|
||||
}
|
||||
gesjson := infoapi(servers[model.Args])
|
||||
var str = gesjson.Players.List
|
||||
cs := strings.Join(str, "\n")
|
||||
ctx.SendChain(message.Text(
|
||||
"服务器名字: ", gesjson.Motd.Raw[0], "\n",
|
||||
"在线人数: ", gesjson.Players.Online, "/", gesjson.Players.Max, "\n",
|
||||
"以下为玩家名字: ", "\n", cs,
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -7,36 +7,50 @@ import (
|
||||
"net/http"
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
)
|
||||
|
||||
// 此功能实现依赖MCSManager项目对服务器的管理api,mc服务器如果没有在该管理平台部署此功能无效
|
||||
// 项目地址: https://github.com/Suwings/MCSManager
|
||||
// 项目的api文档: https://github.com/Suwings/MCSManager/wiki/API-Documentation
|
||||
|
||||
func init() {
|
||||
zero.OnRegex(`^/start (.*)$`).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
name := ctx.State["regex_matched"].([]string)[1]
|
||||
ctx.SendChain(message.Text("开启服务器: ", name, "....."))
|
||||
result := start(name)
|
||||
ctx.Send(result)
|
||||
})
|
||||
}
|
||||
const api = "http://your.addr:23333/api/start_server/%s/?apikey=apikey"
|
||||
|
||||
var engine *zero.Engine
|
||||
|
||||
func init() {
|
||||
zero.OnRegex(`^/stop (.*)$`).
|
||||
engine = control.Register("minecraft", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "minecraft\n" +
|
||||
"- /mcstart xxx\n" +
|
||||
"- /mcstop xxx\n" +
|
||||
"- /mclist servername\n" +
|
||||
"- https://github.com/Suwings/MCSManager",
|
||||
})
|
||||
engine.OnCommand("mcstart").
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
name := ctx.State["regex_matched"].([]string)[1]
|
||||
ctx.SendChain(message.Text("关闭服务器: ", name, "....."))
|
||||
result := stop(name)
|
||||
model := extension.CommandModel{}
|
||||
_ = ctx.Parse(&model)
|
||||
ctx.SendChain(message.Text("开启服务器: ", model.Args, "....."))
|
||||
result := start(model.Args)
|
||||
ctx.Send(result)
|
||||
})
|
||||
engine.OnCommand("mcstop").
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
model := extension.CommandModel{}
|
||||
_ = ctx.Parse(&model)
|
||||
ctx.SendChain(message.Text("开启服务器: ", model.Args, "....."))
|
||||
result := stop(model.Args)
|
||||
ctx.Send(result)
|
||||
})
|
||||
}
|
||||
|
||||
// 开启服务器的api请求
|
||||
func start(name string) string {
|
||||
url := fmt.Sprintf("http://your.addr:23333/api/start_server/%s/?apikey=apikey", name)
|
||||
url := fmt.Sprintf(api, name)
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
@@ -57,7 +71,7 @@ func start(name string) string {
|
||||
|
||||
// 关闭服务器的api请求
|
||||
func stop(name string) string {
|
||||
url := fmt.Sprintf("http://your.addr:23333/api/stop_server/%s/?apikey=apikey", name)
|
||||
url := fmt.Sprintf(api, name)
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -15,12 +15,21 @@ import (
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
)
|
||||
|
||||
var limit = rate.NewManager(time.Minute*3, 5)
|
||||
|
||||
func init() {
|
||||
zero.OnRegex("^(.{0,2})点歌(.{1,25})$").SetBlock(true).FirstPriority().
|
||||
control.Register("music", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "点歌\n" +
|
||||
"- 点歌[xxx]\n" +
|
||||
"- 网易点歌[xxx]\n" +
|
||||
"- 酷我点歌[xxx]\n" +
|
||||
"- 酷狗点歌[xxx]",
|
||||
}).OnRegex("^(.{0,2})点歌(.{1,25})$").SetBlock(true).FirstPriority().
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if !limit.Load(ctx.Event.UserID).Acquire() {
|
||||
ctx.Send("请稍后重试0x0...")
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -18,7 +20,11 @@ func init() { // 插件主体
|
||||
// TODO: 1.17 特性暂不增加
|
||||
// rand.Seed(time.Now().UnixMicro())
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
zero.OnFullMatchGroup([]string{"求签", "运势", "占卜"}, zero.OnlyToMe).SetPriority(10).
|
||||
control.Register("omikuji", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "浅草寺求签\n" +
|
||||
"- 求签|运势|占卜",
|
||||
}).OnFullMatchGroup([]string{"求签", "运势", "占卜"}).SetPriority(10).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
miku := rand.Intn(100) + 1
|
||||
ctx.SendChain(
|
||||
|
||||
@@ -17,28 +17,24 @@ import (
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
)
|
||||
|
||||
var (
|
||||
prio = 3
|
||||
bucket = rate.NewManager(time.Minute, 20) // 青云客接口回复
|
||||
enable = true
|
||||
engine *zero.Engine
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
// 开关
|
||||
zero.OnFullMatch("开启自动回复", zero.SuperUserPermission).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
enable = true
|
||||
ctx.SendChain(message.Text("自动回复开启"))
|
||||
})
|
||||
zero.OnFullMatch("关闭自动回复", zero.SuperUserPermission).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
enable = false
|
||||
ctx.SendChain(message.Text("自动回复关闭"))
|
||||
})
|
||||
engine = control.Register("qingyunke", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "青云客\n" +
|
||||
"- @Bot 任意文本(任意一句话回复)",
|
||||
})
|
||||
// 回复
|
||||
zero.OnRegex("(^.{1,30}$)", zero.OnlyToMe, switchQYK()).SetBlock(false).SetPriority(prio).
|
||||
engine.OnRegex("(^.{1,30}$)", zero.OnlyToMe).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if !bucket.Load(ctx.Event.UserID).Acquire() {
|
||||
// 频繁触发,不回复
|
||||
@@ -152,9 +148,3 @@ func getAgent() string {
|
||||
len1 := len(agent)
|
||||
return agent[r.Intn(len1)]
|
||||
}
|
||||
|
||||
func switchQYK() zero.Rule {
|
||||
return func(ctx *zero.Ctx) bool {
|
||||
return enable
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,12 @@ import (
|
||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
var (
|
||||
enable = true
|
||||
limit = rate.NewManager(time.Minute*3, 5)
|
||||
templates = map[string]string{
|
||||
"py2": "print 'Hello World!'",
|
||||
@@ -92,40 +93,18 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
zero.OnFullMatch(">runcode help").SetBlock(true).FirstPriority().
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
ctx.SendChain(message.Text(
|
||||
"使用说明: ", "\n",
|
||||
">runcode [language] [code block]", "\n",
|
||||
"模板查看: ", "\n",
|
||||
">runcode [language] help", "\n",
|
||||
"支持语种: ", "\n",
|
||||
"Go || Python || C/C++ || C# || Java || Lua ", "\n",
|
||||
"JavaScript || TypeScript || PHP || Shell ", "\n",
|
||||
"Kotlin || Rust || Erlang || Ruby || Swift ", "\n",
|
||||
"R || VB || Py2 || Perl || Pascal || Scala ", "\n",
|
||||
))
|
||||
})
|
||||
|
||||
zero.OnFullMatch(">runcode on", zero.AdminPermission).SetBlock(true).FirstPriority().
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
enable = true
|
||||
ctx.SendChain(
|
||||
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
||||
message.Text("在线运行代码功能已启用"),
|
||||
)
|
||||
})
|
||||
|
||||
zero.OnFullMatch(">runcode off", zero.AdminPermission).SetBlock(true).FirstPriority().
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
enable = false
|
||||
ctx.SendChain(
|
||||
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
||||
message.Text("在线运行代码功能已禁用"),
|
||||
)
|
||||
})
|
||||
|
||||
zero.OnRegex(`^>runcode\s(.+?)\s([\s\S]+)$`).SetBlock(true).SecondPriority().
|
||||
control.Register("runcode", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "在线代码运行: \n" +
|
||||
">runcode [language] [code block]\n" +
|
||||
"模板查看: \n" +
|
||||
">runcode [language] help\n" +
|
||||
"支持语种: \n" +
|
||||
"Go || Python || C/C++ || C# || Java || Lua \n" +
|
||||
"JavaScript || TypeScript || PHP || Shell \n" +
|
||||
"Kotlin || Rust || Erlang || Ruby || Swift \n" +
|
||||
"R || VB || Py2 || Perl || Pascal || Scala",
|
||||
}).OnRegex(`^>runcode\s(.+?)\s([\s\S]+)$`).SetBlock(true).SecondPriority().
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if !limit.Load(ctx.Event.UserID).Acquire() {
|
||||
ctx.Send("请稍后重试0x0...")
|
||||
@@ -139,39 +118,31 @@ func init() {
|
||||
message.Text("语言不是受支持的编程语种呢~"),
|
||||
)
|
||||
} else {
|
||||
if !enable {
|
||||
// 运行代码被禁用
|
||||
// 执行运行
|
||||
block := ctx.State["regex_matched"].([]string)[2]
|
||||
block = message.UnescapeCQCodeText(block)
|
||||
if block == "help" {
|
||||
// 输出模板
|
||||
ctx.SendChain(
|
||||
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
||||
message.Text("在线运行代码功能已被禁用"),
|
||||
message.Text("> ", ctx.Event.Sender.NickName, " ", language, "-template:\n"),
|
||||
message.Text(
|
||||
">runcode ", language, "\n",
|
||||
templates[language],
|
||||
),
|
||||
)
|
||||
} else {
|
||||
// 执行运行
|
||||
block := ctx.State["regex_matched"].([]string)[2]
|
||||
block = message.UnescapeCQCodeText(block)
|
||||
if block == "help" {
|
||||
// 输出模板
|
||||
if output, err := runCode(block, runType); err != nil {
|
||||
// 运行失败
|
||||
ctx.SendChain(
|
||||
message.Text("> ", ctx.Event.Sender.NickName, " ", language, "-template:\n"),
|
||||
message.Text(
|
||||
">runcode ", language, "\n",
|
||||
templates[language],
|
||||
),
|
||||
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
||||
message.Text("ERROR: ", err),
|
||||
)
|
||||
} else {
|
||||
if output, err := runCode(block, runType); err != nil {
|
||||
// 运行失败
|
||||
ctx.SendChain(
|
||||
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
||||
message.Text("ERROR: ", err),
|
||||
)
|
||||
} else {
|
||||
// 运行成功
|
||||
ctx.SendChain(
|
||||
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
||||
message.Text(output),
|
||||
)
|
||||
}
|
||||
// 运行成功
|
||||
ctx.SendChain(
|
||||
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
||||
message.Text(output),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,19 @@ import (
|
||||
"github.com/FloatTech/AnimeAPI/picture"
|
||||
"github.com/FloatTech/AnimeAPI/pixiv"
|
||||
"github.com/FloatTech/AnimeAPI/saucenao"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("saucenao", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "搜图\n" +
|
||||
"- 以图搜图|搜索图片|以图识图[图片]\n" +
|
||||
"- 搜图[P站图片ID]",
|
||||
})
|
||||
// 根据 PID 搜图
|
||||
zero.OnRegex(`^搜图(\d+)$`).SetBlock(true).FirstPriority().
|
||||
engine.OnRegex(`^搜图(\d+)$`).SetBlock(true).FirstPriority().
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
id, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64)
|
||||
ctx.Send("少女祈祷中......")
|
||||
@@ -27,24 +35,28 @@ func init() { // 插件主体
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
// 改用 i.pixiv.cat 镜像站
|
||||
link := illust.ImageUrls
|
||||
link = strings.ReplaceAll(link, "i.pximg.net", "i.pixiv.cat")
|
||||
// 发送搜索结果
|
||||
ctx.SendChain(
|
||||
message.Image(link),
|
||||
message.Text(
|
||||
"\n",
|
||||
"标题:", illust.Title, "\n",
|
||||
"插画ID:", illust.Pid, "\n",
|
||||
"画师:", illust.UserName, "\n",
|
||||
"画师ID:", illust.UserId, "\n",
|
||||
"直链:", "https://pixivel.moe/detail?id=", illust.Pid,
|
||||
),
|
||||
)
|
||||
if illust.Pid > 0 {
|
||||
// 改用 i.pixiv.cat 镜像站
|
||||
link := illust.ImageUrls
|
||||
link = strings.ReplaceAll(link, "i.pximg.net", "i.pixiv.cat")
|
||||
// 发送搜索结果
|
||||
ctx.SendChain(
|
||||
message.Image(link),
|
||||
message.Text(
|
||||
"\n",
|
||||
"标题:", illust.Title, "\n",
|
||||
"插画ID:", illust.Pid, "\n",
|
||||
"画师:", illust.UserName, "\n",
|
||||
"画师ID:", illust.UserId, "\n",
|
||||
"直链:", "https://pixivel.moe/detail?id=", illust.Pid,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
ctx.Send("图片不存在!")
|
||||
}
|
||||
})
|
||||
// 以图搜图
|
||||
zero.OnKeywordGroup([]string{"以图搜图", "搜索图片", "以图识图"}, picture.CmdMatch, picture.MustGiven).SetBlock(true).FirstPriority().
|
||||
engine.OnKeywordGroup([]string{"以图搜图", "搜索图片", "以图识图"}, picture.CmdMatch, picture.MustGiven).SetBlock(true).FirstPriority().
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
// 开始搜索图片
|
||||
ctx.Send("少女祈祷中......")
|
||||
|
||||
@@ -16,12 +16,15 @@ import (
|
||||
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/data"
|
||||
)
|
||||
|
||||
// Pools 图片缓冲池
|
||||
type imgpool struct {
|
||||
Lock sync.Mutex
|
||||
DB *sqlite
|
||||
DB *Sqlite
|
||||
Path string
|
||||
Group int64
|
||||
List []string
|
||||
@@ -37,7 +40,7 @@ const (
|
||||
// NewPoolsCache 返回一个缓冲池对象
|
||||
func newPools() *imgpool {
|
||||
cache := &imgpool{
|
||||
DB: &sqlite{DBPath: "data/SetuTime/SetuTime.db"},
|
||||
DB: &Sqlite{DBPath: "data/SetuTime/SetuTime.db"},
|
||||
Path: "data/SetuTime/cache/",
|
||||
Group: 0,
|
||||
List: []string{"涩图", "二次元", "风景", "车万"}, // 可以自己加类别,得自己加图片进数据库
|
||||
@@ -71,7 +74,7 @@ func newPools() *imgpool {
|
||||
}
|
||||
}
|
||||
for i := range cache.List {
|
||||
if err := cache.DB.create(cache.List[i], &pixiv.Illust{}); err != nil {
|
||||
if err := cache.DB.Create(cache.List[i], &pixiv.Illust{}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -84,7 +87,15 @@ var (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
zero.OnRegex(`^来份(.*)$`, firstValueInList(pool.List)).SetBlock(true).SetPriority(20).
|
||||
engine := control.Register("setutime", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "涩图\n" +
|
||||
"- 来份[涩图/二次元/风景/车万]\n" +
|
||||
"- 添加[涩图/二次元/风景/车万][P站图片ID]\n" +
|
||||
"- 删除[涩图/二次元/风景/车万][P站图片ID]\n" +
|
||||
"- >setu status",
|
||||
})
|
||||
engine.OnRegex(`^来份(.*)$`, firstValueInList(pool.List)).SetBlock(true).SetPriority(20).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if !limit.Load(ctx.Event.UserID).Acquire() {
|
||||
ctx.SendChain(message.Text("请稍后重试0x0..."))
|
||||
@@ -97,7 +108,7 @@ func init() { // 插件主体
|
||||
for i := 0; i < times; i++ {
|
||||
illust := &pixiv.Illust{}
|
||||
// 查询出一张图片
|
||||
if err := pool.DB.find(imgtype, illust, "ORDER BY RANDOM() limit 1"); err != nil {
|
||||
if err := pool.DB.Find(imgtype, illust, "ORDER BY RANDOM() limit 1"); err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
continue
|
||||
}
|
||||
@@ -128,7 +139,7 @@ func init() { // 插件主体
|
||||
}
|
||||
})
|
||||
|
||||
zero.OnRegex(`^添加(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(21).
|
||||
engine.OnRegex(`^添加(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(21).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
var (
|
||||
imgtype = ctx.State["regex_matched"].([]string)[1]
|
||||
@@ -152,21 +163,21 @@ func init() { // 插件主体
|
||||
return
|
||||
}
|
||||
// 添加插画到对应的数据库table
|
||||
if err := pool.DB.insert(imgtype, illust); err != nil {
|
||||
if err := pool.DB.Insert(imgtype, illust); err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.Send("添加成功")
|
||||
})
|
||||
|
||||
zero.OnRegex(`^删除(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(22).
|
||||
engine.OnRegex(`^删除(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(22).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
var (
|
||||
imgtype = ctx.State["regex_matched"].([]string)[1]
|
||||
id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
|
||||
)
|
||||
// 查询数据库
|
||||
if err := pool.DB.del(imgtype, fmt.Sprintf("WHERE pid=%d", id)); err != nil {
|
||||
if err := pool.DB.Del(imgtype, fmt.Sprintf("WHERE pid=%d", id)); err != nil {
|
||||
ctx.Send(fmt.Sprintf("ERROR: %v", err))
|
||||
return
|
||||
}
|
||||
@@ -174,11 +185,11 @@ func init() { // 插件主体
|
||||
})
|
||||
|
||||
// 查询数据库涩图数量
|
||||
zero.OnFullMatchGroup([]string{">setu status"}).SetBlock(true).SetPriority(23).
|
||||
engine.OnFullMatchGroup([]string{">setu status"}).SetBlock(true).SetPriority(23).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
state := []string{"[SetuTime]"}
|
||||
for i := range pool.List {
|
||||
num, err := pool.DB.count(pool.List[i])
|
||||
num, err := pool.DB.Count(pool.List[i])
|
||||
if err != nil {
|
||||
num = 0
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -17,10 +19,18 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
zero.OnPrefix("异世界转生", number(587874)).SetBlock(true).FirstPriority().Handle(handle)
|
||||
zero.OnPrefix("今天是什么少女", number(162207)).SetBlock(true).FirstPriority().Handle(handle)
|
||||
zero.OnPrefix("卖萌", number(360578)).SetBlock(true).FirstPriority().Handle(handle)
|
||||
zero.OnPrefix("抽老婆", number(1075116)).SetBlock(true).FirstPriority().Handle(handle)
|
||||
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 处理函数
|
||||
|
||||
Reference in New Issue
Block a user