refactor(internal): 分离runner
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package onebot
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// OneBotRuleValidator OneBot规则验证器
|
||||
type OneBotRuleValidator struct{}
|
||||
|
||||
func (v *OneBotRuleValidator) GetType() string {
|
||||
return "onebot"
|
||||
}
|
||||
|
||||
func (v *OneBotRuleValidator) Validate(configJSON string) error {
|
||||
var config OneBotConfig
|
||||
if err := json.Unmarshal([]byte(configJSON), &config); err != nil {
|
||||
return fmt.Errorf("解析OneBot规则配置失败: %v", err)
|
||||
}
|
||||
|
||||
if config.Msg == "" {
|
||||
return fmt.Errorf("OneBot规则配置中 msg 不能为空")
|
||||
}
|
||||
|
||||
if len(config.SendGroups) == 0 {
|
||||
return fmt.Errorf("OneBot规则配置中 send_groups 不能为空")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package onebot
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/ssdomei232/goodBaby/model"
|
||||
)
|
||||
|
||||
// OneBotExecutor OneBot执行器
|
||||
type OneBotExecutor struct{}
|
||||
|
||||
func (e *OneBotExecutor) GetType() string {
|
||||
return "onebot"
|
||||
}
|
||||
|
||||
func (e *OneBotExecutor) Execute(rule *model.Rule) error {
|
||||
log.Printf("执行OneBot规则: %s (ID: %d)", rule.Name, rule.ID)
|
||||
|
||||
SendOneBotMsg(rule)
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user