Files
goodBaby/drivers/onebot/ruleConfigChecker.go
T

52 lines
1.4 KiB
Go
Raw Normal View History

2026-06-19 18:47:36 +08:00
package onebot
import (
"fmt"
2026-07-26 22:19:41 +08:00
"github.com/ssdomei232/goodBaby/internal/meta"
)
// OneBotRuleValidator OneBot规则验证器
type OneBotRuleValidator struct{}
func (v *OneBotRuleValidator) GetType() string {
2026-07-26 22:19:41 +08:00
return RuleType
}
func (v *OneBotRuleValidator) Validate(configJSON string) error {
2026-09-12 15:32:27 +08:00
config, err := ParseRuleConfig(configJSON)
if err != nil {
return err
}
if config.Msg == "" {
return fmt.Errorf("OneBot规则配置中 msg 不能为空")
}
2026-07-26 22:19:41 +08:00
if len(config.SendGroups) == 0 && len(config.SendUsers) == 0 {
return fmt.Errorf("OneBot规则配置中 send_groups 与 send_users 不能同时为空")
}
for _, id := range append(append([]int64{}, config.SendGroups...), config.SendUsers...) {
if id <= 0 {
return fmt.Errorf("OneBot规则配置中存在非法的群号/QQ号: %d", id)
}
}
return nil
}
2026-07-26 22:19:41 +08:00
func (v *OneBotRuleValidator) Meta() meta.RuleMeta {
return meta.RuleMeta{
Type: RuleType,
Label: "发送 QQ 消息",
Description: "触发时通过 OneBot 向指定的群或好友发送消息。",
AccountType: AccountType,
Fields: []meta.Field{
2026-09-12 15:32:27 +08:00
{Key: "msg", Label: "消息内容", Type: meta.FieldTextarea, Required: true, GatewayMessage: true},
2026-07-26 22:19:41 +08:00
{Key: "send_groups", Label: "群号", Type: meta.FieldNumberList, Placeholder: "123456789"},
{Key: "send_users", Label: "好友 QQ 号", Type: meta.FieldNumberList, Placeholder: "123456789"},
},
}
}