Skip to content
This repository was archived by the owner on Nov 26, 2023. It is now read-only.

Commit

Permalink
feat: Implement reloading all plugins when logging in to the robot ac…
Browse files Browse the repository at this point in the history
…count
  • Loading branch information
PBK-B committed Jan 25, 2022
1 parent 996ed60 commit bd981e8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions controllers/apis/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func (c *BotController) ApiLoginBot() {
// 初始化 Bot
bot.InitBot(b_account, b_password)

// 加载全部插件
models.ReLoadAllPlugin()

// 初始化 Modules
bot.StartService()

Expand Down
18 changes: 16 additions & 2 deletions models/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ func DeletePlugin(id int) (err error) {
}

// 获取全部插件
func AllPlugin(limit int, page int) (plugin []Plugin, err error) {
func AllPlugin(limit int, page int) (plugins []Plugin, err error) {
o := orm.NewOrm()
qs := o.QueryTable(&Plugin{})
_, err = qs.Filter("id__isnull", false).Limit(limit, page).All(&plugin)
_, err = qs.Filter("id__isnull", false).Limit(limit, page).All(&plugins)
return
}

Expand Down Expand Up @@ -368,3 +368,17 @@ func GetPluginByPackage(pack string) (c *Plugin, err error) {
}
return nil, err
}

// 重新加载全部插件
func ReLoadAllPlugin() error {
plugins, err := AllPlugin(99, 1)
if err != nil {
return err
}

for _, plugin := range plugins {
plugin.LoadRegisterModule()
}

return nil
}

0 comments on commit bd981e8

Please sign in to comment.