独立骂人插件 (#102)

* fix:vtb数据不用从zbp更新

* feat:独立骂人插件

* fix:修lint

* feat:添加关键词

Co-authored-by: Guohuiyuan <haibaraguo@yeahka.com>
This commit is contained in:
himawari 2022-01-11 10:07:51 +08:00 committed by GitHub
parent 8ea64e7aba
commit 16e05e0320
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 112 additions and 40 deletions

View File

@ -249,6 +249,10 @@ zerobot [-h] [-t token] [-u url] [-n nickname] [-p prefix] [-d|w] [-g 监听地
- **签到得分** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_score"`
- [x] 签到
- [x] 获得签到背景[@xxx]|获得签到背景
- **骂人** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_curse"`
- [x] 骂我
- [x] 大力骂我
- [x] @bot 他妈|公交车|你妈|操|屎|去死|快死|日|逼|尼玛|艾滋|癌症|有病|戴套|啊对对对|烦你|你爹|屮|tui|cnm
- **TODO...**
## 使用方法

View File

@ -36,6 +36,7 @@ import (
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_chouxianghua" // 说抽象话
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_coser" // 三次元小姐姐
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_cpstory" // cp短打
_ "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" // 炉石

50
plugin_curse/curse.go Normal file
View File

@ -0,0 +1,50 @@
// Package curse 骂人插件(求骂,自卫)
package curse
import (
"github.com/FloatTech/ZeroBot-Plugin/control"
"github.com/FloatTech/ZeroBot-Plugin/utils/process"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"github.com/wdvxdr1123/ZeroBot/message"
"time"
)
const (
prio = 10
minLevel = "min"
maxLevel = "max"
)
var (
engine = control.Register("curse", &control.Options{
DisableOnDefault: false,
Help: "骂人(求骂,自卫)\n- 骂我\n- 大力骂我\n- @bot 他妈|公交车|你妈|操|屎|去死|快死|日|逼|尼玛|艾滋|癌症|有病|戴套|啊对对对|烦你|你爹|屮|tui|cnm",
})
limit = rate.NewManager(time.Minute, 30)
)
func init() {
engine.OnFullMatch("骂我").SetBlock(true).SetPriority(prio).Handle(func(ctx *zero.Ctx) {
if !limit.Load(ctx.Event.GroupID).Acquire() {
return
}
process.SleepAbout1sTo2s()
text := getRandomCurseByLevel(minLevel).Text
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(text))
})
engine.OnFullMatch("大力骂我").SetBlock(true).SetPriority(prio).Handle(func(ctx *zero.Ctx) {
if !limit.Load(ctx.Event.GroupID).Acquire() {
return
}
process.SleepAbout1sTo2s()
text := getRandomCurseByLevel(maxLevel).Text
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(text))
})
engine.OnKeywordGroup([]string{"他妈", "公交车", "你妈", "操", "屎", "去死", "快死", "日", "逼", "尼玛", "艾滋", "癌症", "有病", "戴套", "啊对对对", "烦你", "你爹", "屮", "tui", "cnm"}, zero.OnlyToMe).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
text := getRandomCurseByLevel(maxLevel).Text
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(text))
})
}

36
plugin_curse/data.go Normal file
View File

@ -0,0 +1,36 @@
package curse
import (
"github.com/FloatTech/ZeroBot-Plugin/utils/file"
"github.com/FloatTech/ZeroBot-Plugin/utils/process"
"github.com/FloatTech/ZeroBot-Plugin/utils/sql"
"github.com/sirupsen/logrus"
"os"
)
const (
dbpath = "data/Curse/"
dbfile = dbpath + "curse.db"
)
var (
db = &sql.Sqlite{DBPath: dbfile}
)
// 加载数据库
func init() {
go func() {
process.SleepAbout1sTo2s()
_ = os.MkdirAll(dbpath, 0755)
_, err := file.GetLazyData(dbfile, false, true)
if err != nil {
panic(err)
}
err = db.Create("curse", &curse{})
if err != nil {
panic(err)
}
c, _ := db.Count("curse")
logrus.Infoln("[curse]加载", c, "条骂人语录")
}()
}

12
plugin_curse/model.go Normal file
View File

@ -0,0 +1,12 @@
package curse
type curse struct {
ID uint32 `db:"id"`
Text string `db:"text"`
Level string `db:"level"`
}
func getRandomCurseByLevel(level string) (c curse) {
_ = db.Find("curse", &c, "where level = '"+level+"' ORDER BY RANDOM() limit 1")
return
}

View File

@ -10,28 +10,26 @@ import (
)
const (
chpURL = "https://chp.shadiao.app/api.php"
duURL = "https://du.shadiao.app/api.php"
pyqURL = "https://pyq.shadiao.app/api.php"
yduanziURL = "http://www.yduanzi.com/duanzi/getduanzi"
chayiURL = "https://api.lovelive.tools/api/SweetNothings/Web/0"
ganhaiURL = "https://api.lovelive.tools/api/SweetNothings/Web/1"
// zuanURL = "https://zuanbot.com/api.php?level=min&lang=zh_cn"
chpURL = "https://chp.shadiao.app/api.php"
duURL = "https://du.shadiao.app/api.php"
pyqURL = "https://pyq.shadiao.app/api.php"
yduanziURL = "http://www.yduanzi.com/duanzi/getduanzi"
chayiURL = "https://api.lovelive.tools/api/SweetNothings/Web/0"
ganhaiURL = "https://api.lovelive.tools/api/SweetNothings/Web/1"
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
chpReferer = "https://chp.shadiao.app/"
duReferer = "https://du.shadiao.app/"
pyqReferer = "https://pyq.shadiao.app/"
yduanziReferer = "http://www.yduanzi.com/?utm_source=shadiao.app"
loveliveReferer = "https://lovelive.tools/"
// zuanReferer = "https://zuanbot.com/"
prio = 10
prio = 10
)
var (
engine = control.Register("shadiao", &control.Options{
DisableOnDefault: false,
Help: "沙雕app\n" +
"- 骂他[@xxx]|骂他[qq号](停用)\n- 骂我(停用)\n- 哄我\n- 渣我\n- 来碗绿茶\n- 发个朋友圈\n- 来碗毒鸡汤\n- 讲个段子",
"- 哄我\n- 渣我\n- 来碗绿茶\n- 发个朋友圈\n- 来碗毒鸡汤\n- 讲个段子",
})
limit = rate.NewManager(time.Minute, 60)
)

View File

@ -1,29 +0,0 @@
package shadiao
/*
func init() {
engine.OnFullMatch("骂我").SetBlock(true).SetPriority(prio).Handle(func(ctx *zero.Ctx) {
if !limit.Load(ctx.Event.GroupID).Acquire() {
return
}
data, err := web.ReqWith(zuanURL, "GET", zuanReferer, ua)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
ctx.SendChain(message.Reply(ctx.Event.MessageID), 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(zuanURL, "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)))
})
}
*/

View File

@ -12,6 +12,6 @@ func init() {
go func() {
process.SleepAbout1sTo2s()
_ = os.MkdirAll(dbpath, 0755)
_, _ = file.GetLazyData(dbfile, false, true)
_, _ = file.GetLazyData(dbfile, false, false)
}()
}