refactor(internal): 分离runner

This commit is contained in:
mei
2026-06-19 18:47:36 +08:00
parent 7957a91609
commit 5da78f9deb
15 changed files with 209 additions and 53 deletions
+26
View File
@@ -0,0 +1,26 @@
package bilibili
import (
"encoding/json"
"fmt"
)
// BilibiliDynamicRuleValidator B站动态规则验证器
type BilibiliDynamicRuleValidator struct{}
func (v *BilibiliDynamicRuleValidator) GetType() string {
return "bilibili-dynamic"
}
func (v *BilibiliDynamicRuleValidator) Validate(configJSON string) error {
var config BiliDynamicConfig
if err := json.Unmarshal([]byte(configJSON), &config); err != nil {
return fmt.Errorf("解析B站动态规则配置失败: %v", err)
}
if config.Msg == "" {
return fmt.Errorf("B站动态规则配置中 msg 不能为空")
}
return nil
}
+22
View File
@@ -0,0 +1,22 @@
package bilibili
import (
"log"
"github.com/ssdomei232/goodBaby/model"
)
// BilibiliDynamicExecutor B站动态执行器
type BilibiliDynamicExecutor struct{}
func (e *BilibiliDynamicExecutor) GetType() string {
return "bilibili-dynamic"
}
func (e *BilibiliDynamicExecutor) Execute(rule *model.Rule) error {
log.Printf("执行B站动态规则: %s (ID: %d)", rule.Name, rule.ID)
SendBiliDynamicMsg(rule)
return nil
}
+26
View File
@@ -0,0 +1,26 @@
package dingtalk
import (
"encoding/json"
"fmt"
)
// DingTalkRuleValidator 钉钉规则验证器
type DingTalkRuleValidator struct{}
func (v *DingTalkRuleValidator) GetType() string {
return "dingtalk"
}
func (v *DingTalkRuleValidator) Validate(configJSON string) error {
var config DingTalkConfig
if err := json.Unmarshal([]byte(configJSON), &config); err != nil {
return fmt.Errorf("解析钉钉规则配置失败: %v", err)
}
if config.AccessToken == "" {
return fmt.Errorf("钉钉规则配置中 access_token 不能为空")
}
return nil
}
+42
View File
@@ -0,0 +1,42 @@
package email
import (
"encoding/json"
"fmt"
"net/mail"
)
// EmailRuleValidator 邮件规则验证器
type EmailRuleValidator struct{}
func (v *EmailRuleValidator) GetType() string {
return "email"
}
func (v *EmailRuleValidator) Validate(configJSON string) error {
var config EmailRule
if err := json.Unmarshal([]byte(configJSON), &config); err != nil {
return fmt.Errorf("解析邮件规则配置失败: %v", err)
}
if config.Title == "" {
return fmt.Errorf("邮件规则配置中 title 不能为空")
}
if config.Msg == "" {
return fmt.Errorf("邮件规则配置中 msg 不能为空")
}
if len(config.Destinations) == 0 {
return fmt.Errorf("邮件规则配置中 destinations 不能为空")
}
// 验证邮箱地址格式
for _, dest := range config.Destinations {
if _, err := mail.ParseAddress(dest); err != nil {
return fmt.Errorf("无效的邮箱地址: %s", dest)
}
}
return nil
}
+22
View File
@@ -0,0 +1,22 @@
package email
import (
"log"
"github.com/ssdomei232/goodBaby/model"
)
// EmailExecutor 邮件执行器
type EmailExecutor struct{}
func (e *EmailExecutor) GetType() string {
return "email"
}
func (e *EmailExecutor) Execute(rule *model.Rule) error {
log.Printf("执行邮件规则: %s (ID: %d)", rule.Name, rule.ID)
SendMail(rule)
return nil
}
+25
View File
@@ -0,0 +1,25 @@
package github
import (
"encoding/json"
"fmt"
)
type GithubMakeRepositoryPublicRuleValidator struct{}
func (v *GithubMakeRepositoryPublicRuleValidator) GetType() string {
return "github_make_repository_public"
}
func (v *GithubMakeRepositoryPublicRuleValidator) Validate(configJSON string) error {
var config GithubReposConfig
if err := json.Unmarshal([]byte(configJSON), &config); err != nil {
return fmt.Errorf("解析 GitHub 规则配置失败: %v", err)
}
if len(config.Repos) == 0 {
return fmt.Errorf("GitHub 规则配置错误: 至少需要指定一个仓库")
}
return nil
}
+22
View File
@@ -0,0 +1,22 @@
package github
import (
"log"
"github.com/ssdomei232/goodBaby/model"
)
// GithubMakeRepoPublicExecutor GitHub仓库公开执行器
type GithubMakeRepoPublicExecutor struct{}
func (e *GithubMakeRepoPublicExecutor) GetType() string {
return "github-make-repo-public"
}
func (e *GithubMakeRepoPublicExecutor) Execute(rule *model.Rule) error {
log.Printf("执行GitHub仓库公开规则: %s (ID: %d)", rule.Name, rule.ID)
MakeRepositoryPublic(rule)
return nil
}
+30
View File
@@ -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
}
+22
View File
@@ -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
}