Skip to content

Commit

Permalink
独立骂人插件 (FloatTech#102)
Browse files Browse the repository at this point in the history
* fix:vtb数据不用从zbp更新

* feat:独立骂人插件

* fix:修lint

* feat:添加关键词

Co-authored-by: Guohuiyuan <haibaraguo@yeahka.com>
  • Loading branch information
guohuiyuan and Guohuiyuan authored Jan 11, 2022
1 parent 8ea64e7 commit 16e05e0
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 40 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...**

## 使用方法
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" // 炉石
Expand Down
50 changes: 50 additions & 0 deletions plugin_curse/curse.go
Original file line number Diff line number Diff line change
@@ -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 changes: 36 additions & 0 deletions plugin_curse/data.go
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions plugin_curse/model.go
Original file line number Diff line number Diff line change
@@ -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
}
18 changes: 8 additions & 10 deletions plugin_shadiao/shadiao.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
29 changes: 0 additions & 29 deletions plugin_shadiao/zuan.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugin_vtb_quotation/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ func init() {
go func() {
process.SleepAbout1sTo2s()
_ = os.MkdirAll(dbpath, 0755)
_, _ = file.GetLazyData(dbfile, false, true)
_, _ = file.GetLazyData(dbfile, false, false)
}()
}

0 comments on commit 16e05e0

Please sign in to comment.