Skip to content

Commit

Permalink
fix: poke action
Browse files Browse the repository at this point in the history
  • Loading branch information
RicheyJang committed Jul 5, 2022
1 parent 5896685 commit 478d424
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
_ "github.com/RicheyJang/PaimengBot/plugins/pixiv"
_ "github.com/RicheyJang/PaimengBot/plugins/pixiv_query"
_ "github.com/RicheyJang/PaimengBot/plugins/pixiv_rank"
_ "github.com/RicheyJang/PaimengBot/plugins/poke"
_ "github.com/RicheyJang/PaimengBot/plugins/random"
_ "github.com/RicheyJang/PaimengBot/plugins/short_url"
_ "github.com/RicheyJang/PaimengBot/plugins/statistic"
Expand Down
16 changes: 12 additions & 4 deletions plugins/poke/poke.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var info = manager.PluginInfo{
SuperUsage: `需要把go-cqhttp的设备类型修改为非手表
config-plugin配置项:
poke.replies: 回复内容列表,会从中随机选取,支持CQ码
另外,回复内容里还可以配置上某种动作,例如:
另外,回复内容里还可以附带上某种动作,例如:
不准戳我![mute] :这将回复一句"不准戳我",并将其禁言2分钟
目前支持的动作:
[mute]:禁言两分钟,前提是将Bot设为群管理员
Expand All @@ -44,7 +44,7 @@ func init() {
return ctx.Event.NoticeType == "notify" && ctx.Event.SubType == "poke" && ctx.Event.TargetID == ctx.Event.SelfID
}).SetBlock(true).ThirdPriority().Handle(pokeHandler)
proxy.AddConfig(consts.PluginConfigCDKey, "3s")
proxy.AddConfig("replies", []string{"?", "hentai!", "( >﹏<。)", "好气喔,我要给你起个难听的绰号", "那...那里...那里不能戳...", "[pixiv]", "不准戳我啦[mute 0.1]", "[poke]"})
proxy.AddConfig("replies", []string{"?", "hentai!", "( >﹏<。)", "好气喔,我要给你起个难听的绰号", "那...那里...那里不能戳...", "[pixiv]", "不准戳我啦[mute 0.1]", "[poke]"})
}

var actionRegex = regexp.MustCompile(`\[([a-z]{2,10})\s*([01]\.\d+)?]`)
Expand All @@ -63,18 +63,25 @@ func pokeHandler(ctx *zero.Ctx) {
log.Info("即将回复:", reply)
// 发送回复内容
str := strings.TrimSpace(actionRegex.ReplaceAllString(reply, ""))
if len(str) > 0 { // 内容非空
index := 0
if loc := actionRegex.FindStringIndex(reply); len(loc) > 0 {
index = loc[0]
}
if len(str) > 0 && index > 0 { // 内容非空 且 先回复再动作
ctx.Send(str)
}
// 解析、执行动作字符串
actions := actionRegex.FindAllStringSubmatch(reply, -1)
for _, action := range actions {
if len(actions) <= 2 {
if len(action) <= 2 {
continue
}
rate, _ := strconv.ParseFloat(action[2], 32)
dealActions(ctx, action[1], rate)
}
if len(str) > 0 && index == 0 { // 内容非空 且 (先动作再回复 或 无动作)
ctx.Send(str)
}
}

// 处理动作
Expand All @@ -85,6 +92,7 @@ func dealActions(ctx *zero.Ctx, action string, rate float64) {
if ctx.Event.UserID == 0 {
return
}
log.Infof("do %v to %v", action, ctx.Event.UserID)
// 执行各类动作
switch action {
case "mute": // 禁言
Expand Down

0 comments on commit 478d424

Please sign in to comment.