mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-09 00:20:24 +00:00
Compare commits
11 Commits
v1.2.2-bet
...
v1.2.2-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce8d98b77d | ||
|
|
2858d0b0a4 | ||
|
|
1f982566e0 | ||
|
|
779ec5b2fe | ||
|
|
8499921d67 | ||
|
|
1e49bad1a6 | ||
|
|
1d3a61386d | ||
|
|
25ef2ca220 | ||
|
|
b953385bc5 | ||
|
|
4fdedd0a7b | ||
|
|
f4bc43e7a5 |
@@ -52,6 +52,8 @@ zerobot -h -t token -u url [-d|w] [-g 监听地址:端口] qq1 qq2 qq3 ...
|
||||
- [x] /全局启用 xxx
|
||||
- [x] /全局禁用 xxx
|
||||
- [x] /还原 xxx (在发送的群/用户还原xxx的开启状态到初始状态)
|
||||
- [x] /禁止 service qq1 qq2... (禁止 qqs 使用服务 service)
|
||||
- [x] /允许 service qq1 qq2... (重新允许 qqs 使用服务 service)
|
||||
- [x] /用法 xxx
|
||||
- [x] /服务列表
|
||||
- [x] /服务详情
|
||||
@@ -63,6 +65,7 @@ zerobot -h -t token -u url [-d|w] [-g 监听地址:端口] qq1 qq2 qq3 ...
|
||||
- [x] 空调关
|
||||
- [x] 群温度
|
||||
- [x] 设置温度[正整数]
|
||||
- [x] mua|啾咪|摸|上你|傻|裸|贴|老婆|抱|亲|一下|咬|操|123|进去|调教|搓|让|捏|挤|略|呐|原味|胖次|内裤|内衣|衣服|ghs|批|憨批|kkp|咕|骚|喜欢|suki|好き|看|不能|砸了|透|口我|草我|自慰|onani|オナニー|炸了|色图|涩图|告白|对不起|回来|吻|软|壁咚|掰开|女友|是|喵|嗷呜|叫|拜|佬|awsl|臭|香|腿|张开|脚|脸|头发|手|pr|舔|小穴|腰|诶嘿嘿|可爱|扭蛋|鼻|眼|色气|推|床|举|手冲|饿|变|敲|爬|怕|冲|射|不穿|迫害|猫粮|揪尾巴|薄荷|早|晚安|揉|榨|掐|胸|奶子|欧派|嫩|蹭|牵手|握手|拍照|w|睡不着|欧尼酱|哥|爱你|过来|自闭|打不过|么么哒|很懂|膝枕|累了|安慰|洗澡|一起睡觉|一起|多大|姐姐|糖|嗦|牛子|🐂子|🐮子|嫌弃|紧|baka|笨蛋|插|插进来|屁股|翘|翘起来|抬|抬起|爸|傲娇|rua|咕噜咕噜|咕噜|上床|做爱|吃掉|吃|揪|种草莓|种草|掀|妹|病娇|嘻
|
||||
- **ATRI** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_atri"`
|
||||
- [x] 具体指令看 /用法 atri
|
||||
- 注:本插件基于 [ATRI](https://github.com/Kyomotoi/ATRI) ,为 Golang 移植版
|
||||
@@ -215,8 +218,12 @@ zerobot -h -t token -u url [-d|w] [-g 监听地址:端口] qq1 qq2 qq3 ...
|
||||
- [x] 随机书评
|
||||
- **coser** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_coser" `
|
||||
- [x] coser
|
||||
- **novel** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_novel" `
|
||||
- **小说** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_novel" `
|
||||
- [x] 小说[xxx]
|
||||
- **骂人** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_curse"`
|
||||
- [x] 骂他[@xxx]|骂他[qq号]
|
||||
- **笑话** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_funny"`
|
||||
- [x] 讲个笑话[@xxx]|讲个笑话[qq号]
|
||||
- **TODO...**
|
||||
|
||||
## 使用方法
|
||||
|
||||
@@ -9,7 +9,7 @@ var enmap = make(map[string]*zero.Engine)
|
||||
// Register 注册插件控制器
|
||||
func Register(service string, o *Options) *zero.Engine {
|
||||
engine := zero.New()
|
||||
engine.UsePreHandler(newctrl(service, o).Handler())
|
||||
engine.UsePreHandler(newctrl(service, o).Handler)
|
||||
enmap[service] = engine
|
||||
return engine
|
||||
}
|
||||
|
||||
141
control/rule.go
141
control/rule.go
@@ -2,6 +2,9 @@
|
||||
package control
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -11,6 +14,7 @@ import (
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/utils/sql"
|
||||
)
|
||||
@@ -47,6 +51,10 @@ func newctrl(service string, o *Options) *Control {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = db.Create(service+"ban", &ban{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
@@ -125,6 +133,78 @@ func (m *Control) IsEnabledIn(gid int64) bool {
|
||||
return !m.options.DisableOnDefault
|
||||
}
|
||||
|
||||
// Ban 禁止某人在某群使用本插件
|
||||
func (m *Control) Ban(uid, gid int64) {
|
||||
var err error
|
||||
var digest [16]byte
|
||||
logrus.Debugln("[control] Ban recv gid =", gid, "uid =", uid)
|
||||
if gid != 0 { // 特定群
|
||||
digest = md5.Sum(helper.StringToBytes(fmt.Sprintf("%d_%d", uid, gid)))
|
||||
m.RLock()
|
||||
err = db.Insert(m.service+"ban", &ban{ID: int64(binary.LittleEndian.Uint64(digest[:8])), UserID: uid, GroupID: gid})
|
||||
m.RUnlock()
|
||||
if err == nil {
|
||||
logrus.Debugf("[control] plugin %s is banned in grp %d for usr %d.", m.service, gid, uid)
|
||||
return
|
||||
}
|
||||
}
|
||||
// 所有群
|
||||
digest = md5.Sum(helper.StringToBytes(fmt.Sprintf("%d_all", uid)))
|
||||
m.RLock()
|
||||
err = db.Insert(m.service+"ban", &ban{ID: int64(binary.LittleEndian.Uint64(digest[:8])), UserID: uid, GroupID: 0})
|
||||
m.RUnlock()
|
||||
if err == nil {
|
||||
logrus.Debugf("[control] plugin %s is banned in all grp for usr %d.", m.service, uid)
|
||||
}
|
||||
}
|
||||
|
||||
// Permit 允许某人在某群使用本插件
|
||||
func (m *Control) Permit(uid, gid int64) {
|
||||
var digest [16]byte
|
||||
logrus.Debugln("[control] Permit recv gid =", gid, "uid =", uid)
|
||||
if gid != 0 { // 特定群
|
||||
digest = md5.Sum(helper.StringToBytes(fmt.Sprintf("%d_%d", uid, gid)))
|
||||
m.RLock()
|
||||
_ = db.Del(m.service+"ban", "WHERE id = "+strconv.FormatInt(int64(binary.LittleEndian.Uint64(digest[:8])), 10))
|
||||
m.RUnlock()
|
||||
logrus.Debugf("[control] plugin %s is permitted in grp %d for usr %d.", m.service, gid, uid)
|
||||
return
|
||||
}
|
||||
// 所有群
|
||||
digest = md5.Sum(helper.StringToBytes(fmt.Sprintf("%d_all", uid)))
|
||||
m.RLock()
|
||||
_ = db.Del(m.service+"ban", "WHERE id = "+strconv.FormatInt(int64(binary.LittleEndian.Uint64(digest[:8])), 10))
|
||||
m.RUnlock()
|
||||
logrus.Debugf("[control] plugin %s is permitted in all grp for usr %d.", m.service, uid)
|
||||
}
|
||||
|
||||
// IsBannedIn 某人是否在某群被 ban
|
||||
func (m *Control) IsBannedIn(uid, gid int64) bool {
|
||||
var b ban
|
||||
var err error
|
||||
var digest [16]byte
|
||||
logrus.Debugln("[control] IsBannedIn recv gid =", gid, "uid =", uid)
|
||||
if gid != 0 {
|
||||
digest = md5.Sum(helper.StringToBytes(fmt.Sprintf("%d_%d", uid, gid)))
|
||||
m.RLock()
|
||||
err = db.Find(m.service+"ban", &b, "WHERE id = "+strconv.FormatInt(int64(binary.LittleEndian.Uint64(digest[:8])), 10))
|
||||
m.RUnlock()
|
||||
if err == nil && gid == b.GroupID && uid == b.UserID {
|
||||
logrus.Debugf("[control] plugin %s is banned in grp %d for usr %d.", m.service, b.GroupID, b.UserID)
|
||||
return true
|
||||
}
|
||||
}
|
||||
digest = md5.Sum(helper.StringToBytes(fmt.Sprintf("%d_all", uid)))
|
||||
m.RLock()
|
||||
err = db.Find(m.service+"ban", &b, "WHERE id = "+strconv.FormatInt(int64(binary.LittleEndian.Uint64(digest[:8])), 10))
|
||||
m.RUnlock()
|
||||
if err == nil && b.GroupID == 0 && uid == b.UserID {
|
||||
logrus.Debugf("[control] plugin %s is banned in all grp for usr %d.", m.service, b.UserID)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetData 获取某个群的 63 字节配置信息
|
||||
func (m *Control) GetData(gid int64) int64 {
|
||||
var c grpcfg
|
||||
@@ -173,21 +253,19 @@ func (m *Control) SetData(groupID int64, data int64) error {
|
||||
}
|
||||
|
||||
// Handler 返回 预处理器
|
||||
func (m *Control) Handler() zero.Rule {
|
||||
return func(ctx *zero.Ctx) bool {
|
||||
ctx.State["manager"] = m
|
||||
grp := ctx.Event.GroupID
|
||||
if grp == 0 {
|
||||
// 个人用户
|
||||
grp = -ctx.Event.UserID
|
||||
}
|
||||
logrus.Debugln("[control] handler get gid =", grp)
|
||||
return m.IsEnabledIn(grp)
|
||||
func (m *Control) Handler(ctx *zero.Ctx) bool {
|
||||
ctx.State["manager"] = m
|
||||
grp := ctx.Event.GroupID
|
||||
if grp == 0 {
|
||||
// 个人用户
|
||||
return m.IsEnabledIn(-ctx.Event.UserID)
|
||||
}
|
||||
logrus.Debugln("[control] handler get gid =", grp)
|
||||
return m.IsEnabledIn(grp) && !m.IsBannedIn(ctx.Event.UserID, grp)
|
||||
}
|
||||
|
||||
// Lookup returns a Manager by the service name, if
|
||||
// not exist, it will returns nil.
|
||||
// not exist, it will return nil.
|
||||
func Lookup(service string) (*Control, bool) {
|
||||
mu.RLock()
|
||||
m, ok := managers[service]
|
||||
@@ -276,6 +354,47 @@ func init() {
|
||||
ctx.SendChain(message.Text("已还原服务的默认启用状态: " + model.Args))
|
||||
})
|
||||
|
||||
zero.OnCommandGroup([]string{
|
||||
"禁止", "ban", "允许", "permit",
|
||||
"全局禁止", "banall", "全局允许", "permitall",
|
||||
}, zero.OnlyGroup, zero.AdminPermission).Handle(func(ctx *zero.Ctx) {
|
||||
model := extension.CommandModel{}
|
||||
_ = ctx.Parse(&model)
|
||||
args := strings.Split(model.Args, " ")
|
||||
if len(args) >= 2 {
|
||||
service, ok := Lookup(args[0])
|
||||
if !ok {
|
||||
ctx.SendChain(message.Text("没有找到指定服务!"))
|
||||
return
|
||||
}
|
||||
grp := ctx.Event.GroupID
|
||||
if strings.Contains(model.Command, "全局") || strings.Contains(model.Command, "all") {
|
||||
grp = 0
|
||||
}
|
||||
msg := "**" + args[0] + "报告**"
|
||||
if strings.Contains(model.Command, "允许") || strings.Contains(model.Command, "permit") {
|
||||
for _, usr := range args[1:] {
|
||||
uid, err := strconv.ParseInt(usr, 10, 64)
|
||||
if err == nil {
|
||||
service.Permit(uid, grp)
|
||||
msg += "\n+ 已允许" + usr
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, usr := range args[1:] {
|
||||
uid, err := strconv.ParseInt(usr, 10, 64)
|
||||
if err == nil {
|
||||
service.Ban(uid, grp)
|
||||
msg += "\n- 已禁止" + usr
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.SendChain(message.Text(msg))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text("参数错误!"))
|
||||
})
|
||||
|
||||
zero.OnCommandGroup([]string{"用法", "usage"}, userOrGrpAdmin).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
model := extension.CommandModel{}
|
||||
|
||||
@@ -6,6 +6,12 @@ type grpcfg struct {
|
||||
Disable int64 `db:"disable"` // Disable 默认启用该插件
|
||||
}
|
||||
|
||||
type ban struct {
|
||||
ID int64 `db:"id"`
|
||||
UserID int64 `db:"uid"`
|
||||
GroupID int64 `db:"gid"`
|
||||
}
|
||||
|
||||
// Options holds the optional parameters for the Manager.
|
||||
type Options struct {
|
||||
DisableOnDefault bool
|
||||
|
||||
1607
data/Chat/kimoi.json
Normal file
1607
data/Chat/kimoi.json
Normal file
File diff suppressed because it is too large
Load Diff
BIN
data/Funny/jokes.db
Normal file
BIN
data/Funny/jokes.db
Normal file
Binary file not shown.
2
main.go
2
main.go
@@ -33,7 +33,9 @@ import (
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_book_review" // 哀伤雪刃吧推书记录
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_choose" // 选择困难症帮手
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_coser" // 三次元小姐姐
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_curse" // 骂人
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_fortune" // 运势
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_funny" // 笑话
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_hs" // 炉石
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_minecraft" // MCSManager
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_moyu" // 摸鱼
|
||||
|
||||
@@ -20,9 +20,9 @@ const (
|
||||
// 服务名
|
||||
servicename = "atri"
|
||||
// ATRI 所有命令的优先级
|
||||
prio = 5
|
||||
prio = 15
|
||||
// ATRI 表情的 codechina 镜像
|
||||
res = "https://codechina.csdn.net/u011570312/ZeroBot-Plugin/-/raw/master/plugin_atri/"
|
||||
res = "https://gitcode.net/u011570312/ZeroBot-Plugin/-/raw/master/plugin_atri/"
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/utils/sql"
|
||||
)
|
||||
|
||||
type book struct {
|
||||
Id uint64 `db:"id"`
|
||||
BookReview string `db:"bookreview"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
db, err := Open(os.Args[1])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
newdb := &sql.Sqlite{DBPath: os.Args[2]}
|
||||
err = newdb.Create("bookreview", &book{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
rs, err := db.Table("book_review").Select("book_review", "").Rows()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var d string
|
||||
var i uint64
|
||||
for rs.Next() {
|
||||
err := rs.Scan(&d)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
i++
|
||||
err = newdb.Insert("bookreview", &book{i, d})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
db.Close()
|
||||
newdb.Close()
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/logoove/sqlite"
|
||||
)
|
||||
|
||||
type BrDB = gorm.DB
|
||||
|
||||
func Initialize(dbpath string) *BrDB {
|
||||
var err error
|
||||
if _, err = os.Stat(dbpath); err != nil || os.IsNotExist(err) {
|
||||
// 生成文件
|
||||
f, err := os.Create(dbpath)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
defer f.Close()
|
||||
}
|
||||
gdb, err := gorm.Open("sqlite3", dbpath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
gdb.AutoMigrate(&BookReview{})
|
||||
return (*BrDB)(gdb)
|
||||
}
|
||||
|
||||
func Open(dbpath string) (*BrDB, error) {
|
||||
db, err := gorm.Open("sqlite3", dbpath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return (*BrDB)(db), nil
|
||||
}
|
||||
}
|
||||
|
||||
type BookReview struct {
|
||||
gorm.Model
|
||||
BookReview string `gorm:"column:book_review"`
|
||||
}
|
||||
|
||||
func (BookReview) TableName() string {
|
||||
return "book_review"
|
||||
}
|
||||
@@ -13,16 +13,25 @@ import (
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
)
|
||||
|
||||
var poke = rate.NewManager(time.Minute*5, 8) // 戳一戳
|
||||
const (
|
||||
dbpath = "data/Chat/"
|
||||
dbfile = dbpath + "kimoi.json"
|
||||
prio = 10
|
||||
)
|
||||
|
||||
var engine = control.Register("chat", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "chat\n- [BOT名字]\n- [戳一戳BOT]\n- 空调开\n- 空调关\n- 群温度\n- 设置温度[正整数]",
|
||||
})
|
||||
var (
|
||||
poke = rate.NewManager(time.Minute*5, 8) // 戳一戳
|
||||
engine = control.Register("chat", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "chat\n- [BOT名字]\n- [戳一戳BOT]\n- 空调开\n- 空调关\n- 群温度\n- 设置温度[正整数]\n- mua|啾咪|摸|上你|傻|裸|贴|老婆|抱|亲|一下|咬|操|123|进去|调教|搓|让|捏|挤|略|呐|原味|胖次|内裤|内衣|衣服|ghs|批|憨批|kkp|咕|骚|喜欢|suki|好き|看|不能|砸了|透|口我|草我|自慰|onani|オナニー|炸了|色图|涩图|告白|对不起|回来|吻|软|壁咚|掰开|女友|是|喵|嗷呜|叫|拜|佬|awsl|臭|香|腿|张开|脚|脸|头发|手|pr|舔|小穴|腰|诶嘿嘿|可爱|扭蛋|鼻|眼|色气|推|床|举|手冲|饿|变|敲|爬|怕|冲|射|不穿|迫害|猫粮|揪尾巴|薄荷|早|晚安|揉|榨|掐|胸|奶子|欧派|嫩|蹭|牵手|握手|拍照|w|睡不着|欧尼酱|哥|爱你|过来|自闭|打不过|么么哒|很懂|膝枕|累了|安慰|洗澡|一起睡觉|一起|多大|姐姐|糖|嗦|牛子|🐂子|🐮子|嫌弃|紧|baka|笨蛋|插|插进来|屁股|翘|翘起来|抬|抬起|爸|傲娇|rua|咕噜咕噜|咕噜|上床|做爱|吃掉|吃|揪|种草莓|种草|掀|妹|病娇|嘻",
|
||||
})
|
||||
kimomap = make(kimo, 256)
|
||||
chatList = make([]string, 0, 256)
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
// 被喊名字
|
||||
engine.OnFullMatch("", zero.OnlyToMe).SetBlock(true).FirstPriority().
|
||||
engine.OnFullMatch("", zero.OnlyToMe).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
var nickname = zero.BotConfig.NickName[0]
|
||||
time.Sleep(time.Second * 1)
|
||||
@@ -36,7 +45,7 @@ func init() { // 插件主体
|
||||
))
|
||||
})
|
||||
// 戳一戳
|
||||
engine.On("notice/notify/poke", zero.OnlyToMe).SetBlock(false).FirstPriority().
|
||||
engine.On("notice/notify/poke", zero.OnlyToMe).SetBlock(false).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
var nickname = zero.BotConfig.NickName[0]
|
||||
switch {
|
||||
@@ -55,18 +64,18 @@ func init() { // 插件主体
|
||||
// 群空调
|
||||
var AirConditTemp = map[int64]int{}
|
||||
var AirConditSwitch = map[int64]bool{}
|
||||
engine.OnFullMatch("空调开").SetBlock(true).FirstPriority().
|
||||
engine.OnFullMatch("空调开").SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
AirConditSwitch[ctx.Event.GroupID] = true
|
||||
ctx.SendChain(message.Text("❄️哔~"))
|
||||
})
|
||||
engine.OnFullMatch("空调关").SetBlock(true).FirstPriority().
|
||||
engine.OnFullMatch("空调关").SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
AirConditSwitch[ctx.Event.GroupID] = false
|
||||
delete(AirConditTemp, ctx.Event.GroupID)
|
||||
ctx.SendChain(message.Text("💤哔~"))
|
||||
})
|
||||
engine.OnRegex(`设置温度(\d+)`).SetBlock(true).FirstPriority().
|
||||
engine.OnRegex(`设置温度(\d+)`).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if _, exist := AirConditTemp[ctx.Event.GroupID]; !exist {
|
||||
AirConditTemp[ctx.Event.GroupID] = 26
|
||||
@@ -85,7 +94,7 @@ func init() { // 插件主体
|
||||
))
|
||||
}
|
||||
})
|
||||
engine.OnFullMatch(`群温度`).SetBlock(true).FirstPriority().
|
||||
engine.OnFullMatch(`群温度`).SetBlock(true).SetPriority(prio).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if _, exist := AirConditTemp[ctx.Event.GroupID]; !exist {
|
||||
AirConditTemp[ctx.Event.GroupID] = 26
|
||||
@@ -102,4 +111,13 @@ func init() { // 插件主体
|
||||
))
|
||||
}
|
||||
})
|
||||
initChatList(func() {
|
||||
engine.OnFullMatchGroup(chatList, zero.OnlyToMe).SetBlock(true).SetPriority(prio).Handle(
|
||||
func(ctx *zero.Ctx) {
|
||||
key := ctx.MessageString()
|
||||
val := *kimomap[key]
|
||||
text := val[rand.Intn(len(val))]
|
||||
ctx.SendChain(message.At(ctx.Event.UserID), message.Text(text))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
30
plugin_chat/data.go
Normal file
30
plugin_chat/data.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/utils/file"
|
||||
"github.com/FloatTech/ZeroBot-Plugin/utils/process"
|
||||
)
|
||||
|
||||
type kimo = map[string]*[]string
|
||||
|
||||
func initChatList(postinit func()) {
|
||||
go func() {
|
||||
process.SleepAbout1sTo2s()
|
||||
_ = os.MkdirAll(dbpath, 0755)
|
||||
data, err := file.GetLazyData(dbfile, true, true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
json.Unmarshal(data, &kimomap)
|
||||
for k := range kimomap {
|
||||
chatList = append(chatList, k)
|
||||
}
|
||||
logrus.Infoln("[chat]加载", len(chatList), "条kimoi")
|
||||
postinit()
|
||||
}()
|
||||
}
|
||||
54
plugin_curse/curse.go
Normal file
54
plugin_curse/curse.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package curse
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||
"github.com/FloatTech/ZeroBot-Plugin/utils/math"
|
||||
"github.com/FloatTech/ZeroBot-Plugin/utils/web"
|
||||
)
|
||||
|
||||
const (
|
||||
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"
|
||||
curseURL = "https://zuanbot.com/api.php?level=min&lang=zh_cn"
|
||||
)
|
||||
|
||||
var (
|
||||
engine = control.Register("curse", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "骂人\n" +
|
||||
"- 骂他[@xxx]|骂他[qq号]\n",
|
||||
})
|
||||
limit = rate.NewManager(time.Minute, 20)
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine.OnPrefix("骂我").SetBlock(true).FirstPriority().Handle(func(ctx *zero.Ctx) {
|
||||
if !limit.Load(ctx.Event.GroupID).Acquire() {
|
||||
return
|
||||
}
|
||||
data, err := web.ReqWith(curseURL, "GET", "", ua)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.At(ctx.Event.UserID), message.Text(helper.BytesToString(data)))
|
||||
})
|
||||
engine.OnRegex(`^骂他.*?(\d+)`, zero.OnlyGroup).SetBlock(true).SetPriority(40).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if !limit.Load(ctx.Event.GroupID).Acquire() {
|
||||
return
|
||||
}
|
||||
data, err := web.ReqWith(curseURL, "GET", "", ua)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.At(math.Str2Int64(ctx.State["regex_matched"].([]string)[1])), message.Text(helper.BytesToString(data)))
|
||||
})
|
||||
}
|
||||
38
plugin_funny/data.go
Normal file
38
plugin_funny/data.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package funny
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/utils/file"
|
||||
"github.com/FloatTech/ZeroBot-Plugin/utils/process"
|
||||
)
|
||||
|
||||
type joke struct {
|
||||
ID uint32 `db:"id"`
|
||||
Text string `db:"text"`
|
||||
}
|
||||
|
||||
const (
|
||||
dbpath = "data/Funny/"
|
||||
dbfile = dbpath + "jokes.db"
|
||||
)
|
||||
|
||||
// 加载数据库
|
||||
func init() {
|
||||
go func() {
|
||||
process.SleepAbout1sTo2s()
|
||||
_ = os.MkdirAll(dbpath, 0755)
|
||||
_, err := file.GetLazyData(dbfile, false, true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = db.Create("jokes", &joke{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c, _ := db.Count("jokes")
|
||||
logrus.Infoln("[funny]加载", c, "个笑话")
|
||||
}()
|
||||
}
|
||||
33
plugin_funny/data_test.go
Normal file
33
plugin_funny/data_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package funny
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/binary"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/utils/sql"
|
||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||
)
|
||||
|
||||
func TestFillData(t *testing.T) {
|
||||
data, err := os.ReadFile("laugh.txt")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
db := &sql.Sqlite{DBPath: "jokes.db"}
|
||||
err = db.Create("jokes", &joke{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
jokes := strings.Split(helper.BytesToString(data), "\n")
|
||||
for _, j := range jokes {
|
||||
s := md5.Sum(helper.StringToBytes(j))
|
||||
db.Insert("jokes", &joke{ID: binary.LittleEndian.Uint32(s[:4]), Text: j})
|
||||
}
|
||||
err = db.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
47
plugin_funny/laugh.go
Normal file
47
plugin_funny/laugh.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package funny
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
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/sql"
|
||||
)
|
||||
|
||||
var (
|
||||
engine = control.Register("curse", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "讲个笑话\n" +
|
||||
"- 讲个笑话[@xxx]|讲个笑话[qq号]\n",
|
||||
})
|
||||
limit = rate.NewManager(time.Minute, 20)
|
||||
db = &sql.Sqlite{DBPath: dbfile}
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine.OnPrefix("讲个笑话").SetBlock(true).FirstPriority().Handle(func(ctx *zero.Ctx) {
|
||||
if !limit.Load(ctx.Event.GroupID).Acquire() {
|
||||
return
|
||||
}
|
||||
// 获取名字
|
||||
name := ctx.State["args"].(string)
|
||||
if len(ctx.Event.Message) > 1 && ctx.Event.Message[1].Type == "at" {
|
||||
qq, _ := strconv.ParseInt(ctx.Event.Message[1].Data["qq"], 10, 64)
|
||||
name = ctx.GetGroupMemberInfo(ctx.Event.GroupID, qq, false).Get("nickname").Str
|
||||
} else if name == "" {
|
||||
name = ctx.Event.Sender.NickName
|
||||
}
|
||||
var j joke
|
||||
err := db.Pick("jokes", &j)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text(strings.ReplaceAll(j.Text, "%name", name)))
|
||||
})
|
||||
}
|
||||
@@ -74,12 +74,12 @@ func init() { // 插件主体
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
ctx.SetGroupAdmin(
|
||||
ctx.Event.GroupID,
|
||||
strToInt(ctx.State["regex_matched"].([]string)[1]), // 被升为管理的人的qq
|
||||
math.Str2Int64(ctx.State["regex_matched"].([]string)[1]), // 被升为管理的人的qq
|
||||
true,
|
||||
)
|
||||
nickname := ctx.GetGroupMemberInfo( // 被升为管理的人的昵称
|
||||
ctx.Event.GroupID,
|
||||
strToInt(ctx.State["regex_matched"].([]string)[1]), // 被升为管理的人的qq
|
||||
math.Str2Int64(ctx.State["regex_matched"].([]string)[1]), // 被升为管理的人的qq
|
||||
false,
|
||||
).Get("nickname").Str
|
||||
ctx.SendChain(message.Text(nickname + " 升为了管理~"))
|
||||
@@ -89,12 +89,12 @@ func init() { // 插件主体
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
ctx.SetGroupAdmin(
|
||||
ctx.Event.GroupID,
|
||||
strToInt(ctx.State["regex_matched"].([]string)[1]), // 被取消管理的人的qq
|
||||
math.Str2Int64(ctx.State["regex_matched"].([]string)[1]), // 被取消管理的人的qq
|
||||
false,
|
||||
)
|
||||
nickname := ctx.GetGroupMemberInfo( // 被取消管理的人的昵称
|
||||
ctx.Event.GroupID,
|
||||
strToInt(ctx.State["regex_matched"].([]string)[1]), // 被取消管理的人的qq
|
||||
math.Str2Int64(ctx.State["regex_matched"].([]string)[1]), // 被取消管理的人的qq
|
||||
false,
|
||||
).Get("nickname").Str
|
||||
ctx.SendChain(message.Text("残念~ " + nickname + " 暂时失去了管理员的资格"))
|
||||
@@ -104,12 +104,12 @@ func init() { // 插件主体
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
ctx.SetGroupKick(
|
||||
ctx.Event.GroupID,
|
||||
strToInt(ctx.State["regex_matched"].([]string)[1]), // 被踢出群聊的人的qq
|
||||
math.Str2Int64(ctx.State["regex_matched"].([]string)[1]), // 被踢出群聊的人的qq
|
||||
false,
|
||||
)
|
||||
nickname := ctx.GetGroupMemberInfo( // 被踢出群聊的人的昵称
|
||||
ctx.Event.GroupID,
|
||||
strToInt(ctx.State["regex_matched"].([]string)[1]), // 被踢出群聊的人的qq
|
||||
math.Str2Int64(ctx.State["regex_matched"].([]string)[1]), // 被踢出群聊的人的qq
|
||||
false,
|
||||
).Get("nickname").Str
|
||||
ctx.SendChain(message.Text("残念~ " + nickname + " 被放逐"))
|
||||
@@ -118,7 +118,7 @@ func init() { // 插件主体
|
||||
engine.OnRegex(`^退出群聊.*?(\d+)`, zero.OnlyToMe, zero.SuperUserPermission).SetBlock(true).SetPriority(40).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
ctx.SetGroupLeave(
|
||||
strToInt(ctx.State["regex_matched"].([]string)[1]), // 要退出的群的群号
|
||||
math.Str2Int64(ctx.State["regex_matched"].([]string)[1]), // 要退出的群的群号
|
||||
true,
|
||||
)
|
||||
})
|
||||
@@ -143,7 +143,7 @@ func init() { // 插件主体
|
||||
// 禁言
|
||||
engine.OnRegex(`^禁言.*?(\d+).*?\s(\d+)(.*)`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).SetPriority(40).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
duration := strToInt(ctx.State["regex_matched"].([]string)[2])
|
||||
duration := math.Str2Int64(ctx.State["regex_matched"].([]string)[2])
|
||||
switch ctx.State["regex_matched"].([]string)[3] {
|
||||
case "分钟":
|
||||
//
|
||||
@@ -159,7 +159,7 @@ func init() { // 插件主体
|
||||
}
|
||||
ctx.SetGroupBan(
|
||||
ctx.Event.GroupID,
|
||||
strToInt(ctx.State["regex_matched"].([]string)[1]), // 要禁言的人的qq
|
||||
math.Str2Int64(ctx.State["regex_matched"].([]string)[1]), // 要禁言的人的qq
|
||||
duration*60, // 要禁言的时间(分钟)
|
||||
)
|
||||
ctx.SendChain(message.Text("小黑屋收留成功~"))
|
||||
@@ -169,7 +169,7 @@ func init() { // 插件主体
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
ctx.SetGroupBan(
|
||||
ctx.Event.GroupID,
|
||||
strToInt(ctx.State["regex_matched"].([]string)[1]), // 要解除禁言的人的qq
|
||||
math.Str2Int64(ctx.State["regex_matched"].([]string)[1]), // 要解除禁言的人的qq
|
||||
0,
|
||||
)
|
||||
ctx.SendChain(message.Text("小黑屋释放成功~"))
|
||||
@@ -177,7 +177,7 @@ func init() { // 插件主体
|
||||
// 自闭禁言
|
||||
engine.OnRegex(`^(我要自闭|禅定).*?(\d+)(.*)`, zero.OnlyGroup).SetBlock(true).SetPriority(40).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
duration := strToInt(ctx.State["regex_matched"].([]string)[2])
|
||||
duration := math.Str2Int64(ctx.State["regex_matched"].([]string)[2])
|
||||
switch ctx.State["regex_matched"].([]string)[3] {
|
||||
case "分钟", "min", "mins", "m":
|
||||
break
|
||||
@@ -203,8 +203,8 @@ func init() { // 插件主体
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
ctx.SetGroupCard(
|
||||
ctx.Event.GroupID,
|
||||
strToInt(ctx.State["regex_matched"].([]string)[1]), // 被修改群名片的人
|
||||
ctx.State["regex_matched"].([]string)[2], // 修改成的群名片
|
||||
math.Str2Int64(ctx.State["regex_matched"].([]string)[1]), // 被修改群名片的人
|
||||
ctx.State["regex_matched"].([]string)[2], // 修改成的群名片
|
||||
)
|
||||
ctx.SendChain(message.Text("嗯!已经修改了"))
|
||||
})
|
||||
@@ -213,8 +213,8 @@ func init() { // 插件主体
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
ctx.SetGroupSpecialTitle(
|
||||
ctx.Event.GroupID,
|
||||
strToInt(ctx.State["regex_matched"].([]string)[1]), // 被修改群头衔的人
|
||||
ctx.State["regex_matched"].([]string)[2], // 修改成的群头衔
|
||||
math.Str2Int64(ctx.State["regex_matched"].([]string)[1]), // 被修改群头衔的人
|
||||
ctx.State["regex_matched"].([]string)[2], // 修改成的群头衔
|
||||
)
|
||||
ctx.SendChain(message.Text("嗯!已经修改了"))
|
||||
})
|
||||
@@ -236,7 +236,7 @@ func init() { // 插件主体
|
||||
content = strings.ReplaceAll(content, "[", "[")
|
||||
content = strings.ReplaceAll(content, "]", "]")
|
||||
ctx.SendGroupMessage(
|
||||
strToInt(ctx.State["regex_matched"].([]string)[1]), // 需要发送的群
|
||||
math.Str2Int64(ctx.State["regex_matched"].([]string)[1]), // 需要发送的群
|
||||
content, // 需要发送的信息
|
||||
)
|
||||
ctx.SendChain(message.Text("📧 --> " + ctx.State["regex_matched"].([]string)[1]))
|
||||
@@ -249,7 +249,7 @@ func init() { // 插件主体
|
||||
content = strings.ReplaceAll(content, "[", "[")
|
||||
content = strings.ReplaceAll(content, "]", "]")
|
||||
ctx.SendPrivateMessage(
|
||||
strToInt(ctx.State["regex_matched"].([]string)[1]), // 需要发送的人的qq
|
||||
math.Str2Int64(ctx.State["regex_matched"].([]string)[1]), // 需要发送的人的qq
|
||||
content, // 需要发送的信息
|
||||
)
|
||||
ctx.SendChain(message.Text("📧 --> " + ctx.State["regex_matched"].([]string)[1]))
|
||||
@@ -521,8 +521,3 @@ func init() { // 插件主体
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func strToInt(str string) int64 {
|
||||
val, _ := strconv.ParseInt(str, 10, 64)
|
||||
return val
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
bed = "https://codechina.csdn.net/u011570312/senso-ji-omikuji/-/raw/main/%d_%d.jpg"
|
||||
bed = "https://gitcode.net/u011570312/senso-ji-omikuji/-/raw/main/%d_%d.jpg"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -67,17 +67,17 @@ var (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("setutime", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "涩图\n" +
|
||||
"- 来份[涩图/二次元/风景/车万]\n" +
|
||||
"- 添加[涩图/二次元/风景/车万][P站图片ID]\n" +
|
||||
"- 删除[涩图/二次元/风景/车万][P站图片ID]\n" +
|
||||
"- >setu status",
|
||||
})
|
||||
go func() {
|
||||
process.SleepAbout1sTo2s()
|
||||
pool = newPools()
|
||||
engine := control.Register("setutime", &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "涩图\n" +
|
||||
"- 来份[涩图/二次元/风景/车万]\n" +
|
||||
"- 添加[涩图/二次元/风景/车万][P站图片ID]\n" +
|
||||
"- 删除[涩图/二次元/风景/车万][P站图片ID]\n" +
|
||||
"- >setu status",
|
||||
})
|
||||
engine.OnRegex(`^来份(.*)$`, rule.FirstValueInList(pool.List)).SetBlock(true).SetPriority(20).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if !limit.Load(ctx.Event.UserID).Acquire() {
|
||||
|
||||
2
run.bat
2
run.bat
@@ -3,5 +3,5 @@ go env -w GOPROXY=https://goproxy.cn,direct
|
||||
go env -w GO111MODULE=auto
|
||||
go mod tidy
|
||||
::go build -ldflags="-s -w" -o ZeroBot-Plugin.exe
|
||||
go run main.go
|
||||
go run main.go main_win.go
|
||||
pause
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
dataurl = "https://codechina.csdn.net/u011570312/ZeroBot-Plugin/-/raw/master/"
|
||||
dataurl = "https://gitcode.net/u011570312/ZeroBot-Plugin/-/raw/master/"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -38,7 +38,7 @@ func GetLazyData(path string, isReturnDataBytes, isDataMustEqual bool) ([]byte,
|
||||
} else {
|
||||
ms, err = registry.Get(path)
|
||||
if err != nil || len(ms) != 16 {
|
||||
logrus.Errorln("[file]获取md5失败,请自行确保下载文件 %s 的正确性:", path, err)
|
||||
logrus.Errorln("[file]获取md5失败,请自行确保下载文件", path, "的正确性:", err)
|
||||
} else {
|
||||
filemd5 = (*[16]byte)(*(*unsafe.Pointer)(unsafe.Pointer(&ms)))
|
||||
logrus.Infoln("[file]从验证服务器获得文件md5:", hex.EncodeToString(filemd5[:]))
|
||||
|
||||
8
utils/math/conv.go
Normal file
8
utils/math/conv.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package math
|
||||
|
||||
import "strconv"
|
||||
|
||||
func Str2Int64(str string) int64 {
|
||||
val, _ := strconv.ParseInt(str, 10, 64)
|
||||
return val
|
||||
}
|
||||
Reference in New Issue
Block a user