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
-23
View File
@@ -1,23 +0,0 @@
package runner
import (
"log"
"github.com/ssdomei232/goodBaby/drivers/bilibili"
"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)
bilibili.SendBiliDynamicMsg(rule)
return nil
}
-23
View File
@@ -1,23 +0,0 @@
package runner
import (
"log"
"github.com/ssdomei232/goodBaby/drivers/email"
"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)
email.SendMail(rule)
return nil
}
-23
View File
@@ -1,23 +0,0 @@
package runner
import (
"log"
"github.com/ssdomei232/goodBaby/drivers/github"
"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)
github.MakeRepositoryPublic(rule)
return nil
}
+8 -4
View File
@@ -3,6 +3,10 @@ package runner
import (
"fmt"
"github.com/ssdomei232/goodBaby/drivers/bilibili"
"github.com/ssdomei232/goodBaby/drivers/email"
"github.com/ssdomei232/goodBaby/drivers/github"
"github.com/ssdomei232/goodBaby/drivers/onebot"
"github.com/ssdomei232/goodBaby/model"
)
@@ -57,10 +61,10 @@ func InitExecutorRegistry() *ExecutorRegistry {
registry := NewExecutorRegistry()
// 注册所有规则执行器
registry.Register(&BilibiliDynamicExecutor{})
registry.Register(&EmailExecutor{})
registry.Register(&GithubMakeRepoPublicExecutor{})
registry.Register(&OneBotExecutor{})
registry.Register(&bilibili.BilibiliDynamicExecutor{})
registry.Register(&email.EmailExecutor{})
registry.Register(&github.GithubMakeRepoPublicExecutor{})
registry.Register(&onebot.OneBotExecutor{})
// 未来添加新规则类型时,在这里注册即可
globalExecutorRegistry = registry
-23
View File
@@ -1,23 +0,0 @@
package runner
import (
"log"
"github.com/ssdomei232/goodBaby/drivers/onebot"
"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)
onebot.SendOneBotMsg(rule)
return nil
}