Skip to content

Commit 486160f

Browse files
authored
添加cp短打 (#94)
* feat:添加cp短打插件 * feat:匹配中英文标点符号和中文字符
1 parent 3939e07 commit 486160f

File tree

7 files changed

+112
-1
lines changed

7 files changed

+112
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ zerobot -h -t token -u url [-d|w] [-g 监听地址:端口] qq1 qq2 qq3 ...
238238
- **藏头诗** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_cangtoushi"`
239239
- [x] 藏头诗[xxx]
240240
- [x] 藏尾诗[xxx]
241+
- **cp短打** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_cpstory"`
242+
- [x] 组cp[@xxx][@xxx]
243+
- [x] 组cp大老师 雪乃
241244
- **TODO...**
242245

243246
## 使用方法

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_choose" // 选择困难症帮手
3636
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_chouxianghua" // 说抽象话
3737
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_coser" // 三次元小姐姐
38+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_cpstory" // cp短打
3839
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_fortune" // 运势
3940
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_funny" // 笑话
4041
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_hs" // 炉石

plugin_chouxianghua/chouxianghua.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func init() {
1313
control.Register("chouxianghua", &control.Options{
1414
DisableOnDefault: false,
1515
Help: "抽象话\n- 抽象翻译xxx\n",
16-
}).OnRegex("^抽象翻译((\\s|[\\r\\n]|[\u4E00-\u9FA5A-Za-z0-9“”,;、。《》=?\\x22])+)$").SetBlock(true).SetPriority(prio).
16+
}).OnRegex("^抽象翻译((\\s|[\\r\\n]|[\\p{Han}\\p{P}A-Za-z0-9])+)$").SetBlock(true).SetPriority(prio).
1717
Handle(func(ctx *zero.Ctx) {
1818
r := cx(ctx.State["regex_matched"].([]string)[1])
1919
ctx.SendChain(message.Text(r))

plugin_cpstory/cpstory.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package cpstory
2+
3+
import (
4+
"github.com/FloatTech/ZeroBot-Plugin/control"
5+
"github.com/FloatTech/ZeroBot-Plugin/utils/math"
6+
zero "github.com/wdvxdr1123/ZeroBot"
7+
"github.com/wdvxdr1123/ZeroBot/extension/rate"
8+
"github.com/wdvxdr1123/ZeroBot/message"
9+
"strings"
10+
"time"
11+
)
12+
13+
const (
14+
prio = 20
15+
)
16+
17+
var (
18+
engine = control.Register("cpstory", &control.Options{
19+
DisableOnDefault: false,
20+
Help: "cp短打\n- 组cp[@xxx][@xxx]\n- 组cp大老师 雪乃",
21+
})
22+
limit = rate.NewManager(time.Minute, 20)
23+
)
24+
25+
func init() {
26+
engine.OnRegex("^组cp.*?(\\d+).*?(\\d+)").SetBlock(true).SetPriority(prio).Handle(func(ctx *zero.Ctx) {
27+
cs := getRandomCpStory()
28+
gong := getCardOrNickName(ctx, math.Str2Int64(ctx.State["regex_matched"].([]string)[1]))
29+
shou := getCardOrNickName(ctx, math.Str2Int64(ctx.State["regex_matched"].([]string)[2]))
30+
text := strings.ReplaceAll(cs.Story, "<攻>", gong)
31+
text = strings.ReplaceAll(text, "<受>", shou)
32+
text = strings.ReplaceAll(text, cs.Gong, gong)
33+
text = strings.ReplaceAll(text, cs.Shou, gong)
34+
ctx.SendChain(message.Text(text))
35+
})
36+
engine.OnPrefix("组cp").SetBlock(true).SetPriority(prio + 1).Handle(func(ctx *zero.Ctx) {
37+
cs := getRandomCpStory()
38+
params := strings.Split(ctx.State["args"].(string), " ")
39+
if len(params) < 2 {
40+
ctx.SendChain(message.Text(ctx.Event.MessageID), message.Text("请用空格分开两个人名"))
41+
} else {
42+
gong := params[0]
43+
shou := params[1]
44+
text := strings.ReplaceAll(cs.Story, "<攻>", gong)
45+
text = strings.ReplaceAll(text, "<受>", shou)
46+
text = strings.ReplaceAll(text, cs.Gong, gong)
47+
text = strings.ReplaceAll(text, cs.Shou, gong)
48+
ctx.SendChain(message.Text(text))
49+
}
50+
})
51+
}
52+
53+
func getCardOrNickName(ctx *zero.Ctx, userId int64) (name string) {
54+
name = ctx.GetGroupMemberInfo(ctx.Event.GroupID, userId, false).Get("card").String()
55+
if name == "" {
56+
name = ctx.GetStrangerInfo(userId, false).Get("nickname").String()
57+
}
58+
return
59+
}

plugin_cpstory/data.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cpstory
2+
3+
import (
4+
"github.com/FloatTech/ZeroBot-Plugin/utils/file"
5+
"github.com/FloatTech/ZeroBot-Plugin/utils/process"
6+
"github.com/FloatTech/ZeroBot-Plugin/utils/sql"
7+
log "github.com/sirupsen/logrus"
8+
"os"
9+
)
10+
11+
const (
12+
dbpath = "data/CpStory/"
13+
dbfile = dbpath + "cp.db"
14+
)
15+
16+
var db = &sql.Sqlite{DBPath: dbfile}
17+
18+
// 加载数据库
19+
func init() {
20+
go func() {
21+
process.SleepAbout1sTo2s()
22+
// os.RemoveAll(dbpath)
23+
_ = os.MkdirAll(dbpath, 0755)
24+
_, _ = file.GetLazyData(dbfile, false, true)
25+
err := db.Create("cp_story", &CpStory{})
26+
if err != nil {
27+
panic(err)
28+
}
29+
n, err := db.Count("cp_story")
30+
if err != nil {
31+
panic(err)
32+
}
33+
log.Printf("[cpstory]读取%d条故事", n)
34+
}()
35+
}

plugin_cpstory/model.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cpstory
2+
3+
type CpStory struct {
4+
Id int64 `db:"id"`
5+
Gong string `db:"gong"`
6+
Shou string `db:"shou"`
7+
Story string `db:"story"`
8+
}
9+
10+
func getRandomCpStory() (cs CpStory) {
11+
_ = db.Pick("cp_story", &cs)
12+
return
13+
}
File renamed without changes.

0 commit comments

Comments
 (0)