feat: hltb plugin
This commit is contained in:
parent
c53942ac53
commit
f13598a329
24 changed files with 940 additions and 17 deletions
|
@ -15,6 +15,7 @@ import (
|
|||
"time"
|
||||
|
||||
"git.nakama.town/fmartingr/butterrobot/internal/admin"
|
||||
"git.nakama.town/fmartingr/butterrobot/internal/cache"
|
||||
"git.nakama.town/fmartingr/butterrobot/internal/config"
|
||||
"git.nakama.town/fmartingr/butterrobot/internal/db"
|
||||
"git.nakama.town/fmartingr/butterrobot/internal/model"
|
||||
|
@ -87,6 +88,7 @@ func (a *App) Run() error {
|
|||
plugin.Register(fun.NewCoin())
|
||||
plugin.Register(fun.NewDice())
|
||||
plugin.Register(fun.NewLoquito())
|
||||
plugin.Register(fun.NewHLTB())
|
||||
plugin.Register(social.NewTwitterExpander())
|
||||
plugin.Register(social.NewInstagramExpander())
|
||||
plugin.Register(reminder.New(a.db))
|
||||
|
@ -102,6 +104,9 @@ func (a *App) Run() error {
|
|||
// Start reminder scheduler
|
||||
a.queue.StartReminderScheduler(a.handleReminder)
|
||||
|
||||
// Start cache cleanup scheduler
|
||||
go a.startCacheCleanup()
|
||||
|
||||
// Create server
|
||||
addr := fmt.Sprintf(":%s", a.config.Port)
|
||||
srv := &http.Server{
|
||||
|
@ -147,6 +152,23 @@ func (a *App) Run() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// startCacheCleanup runs periodic cache cleanup
|
||||
func (a *App) startCacheCleanup() {
|
||||
ticker := time.NewTicker(time.Hour) // Clean up every hour
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
if err := a.db.CacheCleanup(); err != nil {
|
||||
a.logger.Error("Cache cleanup failed", "error", err)
|
||||
} else {
|
||||
a.logger.Debug("Cache cleanup completed")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize HTTP routes
|
||||
func (a *App) initializeRoutes() {
|
||||
// Health check endpoint
|
||||
|
@ -305,8 +327,11 @@ func (a *App) handleMessage(item queue.Item) {
|
|||
continue
|
||||
}
|
||||
|
||||
// Create cache instance for this plugin
|
||||
pluginCache := cache.New(a.db, pluginID)
|
||||
|
||||
// Process message and get actions
|
||||
actions := p.OnMessage(message, channelPlugin.Config)
|
||||
actions := p.OnMessage(message, channelPlugin.Config, pluginCache)
|
||||
|
||||
// Get platform for processing actions
|
||||
platform, err := platform.Get(item.Platform)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue