Files
goodBaby/drivers/onebot/ruleConfigChecker.go
T
mei 9b656cebee
Quality check / Web UI (push) Successful in 9m19s
feat(gateway): 优化gateway相关功能
2026-09-12 15:32:27 +08:00

52 lines
1.4 KiB
Go

package onebot
import (
"fmt"
"github.com/ssdomei232/goodBaby/internal/meta"
)
// OneBotRuleValidator OneBot规则验证器
type OneBotRuleValidator struct{}
func (v *OneBotRuleValidator) GetType() string {
return RuleType
}
func (v *OneBotRuleValidator) Validate(configJSON string) error {
config, err := ParseRuleConfig(configJSON)
if err != nil {
return err
}
if config.Msg == "" {
return fmt.Errorf("OneBot规则配置中 msg 不能为空")
}
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
}
func (v *OneBotRuleValidator) Meta() meta.RuleMeta {
return meta.RuleMeta{
Type: RuleType,
Label: "发送 QQ 消息",
Description: "触发时通过 OneBot 向指定的群或好友发送消息。",
AccountType: AccountType,
Fields: []meta.Field{
{Key: "msg", Label: "消息内容", Type: meta.FieldTextarea, Required: true, GatewayMessage: true},
{Key: "send_groups", Label: "群号", Type: meta.FieldNumberList, Placeholder: "123456789"},
{Key: "send_users", Label: "好友 QQ 号", Type: meta.FieldNumberList, Placeholder: "123456789"},
},
}
}