feat: domain blocker plugin
Some checks failed
ci/woodpecker/tag/release Pipeline was successful
ci/woodpecker/push/ci Pipeline failed

This commit is contained in:
Felipe M 2025-04-22 18:09:27 +02:00
parent c9edb57505
commit 7dd02c0056
Signed by: fmartingr
GPG key ID: CCFBC5637D4000A8
25 changed files with 898 additions and 63 deletions

View file

@ -20,6 +20,7 @@ import (
"git.nakama.town/fmartingr/butterrobot/internal/model"
"git.nakama.town/fmartingr/butterrobot/internal/platform"
"git.nakama.town/fmartingr/butterrobot/internal/plugin"
"git.nakama.town/fmartingr/butterrobot/internal/plugin/domainblock"
"git.nakama.town/fmartingr/butterrobot/internal/plugin/fun"
"git.nakama.town/fmartingr/butterrobot/internal/plugin/ping"
"git.nakama.town/fmartingr/butterrobot/internal/plugin/reminder"
@ -87,10 +88,8 @@ func (a *App) Run() error {
plugin.Register(fun.NewLoquito())
plugin.Register(social.NewTwitterExpander())
plugin.Register(social.NewInstagramExpander())
// Register reminder plugin
reminderPlugin := reminder.New(a.db)
plugin.Register(reminderPlugin)
plugin.Register(reminder.New(a.db))
plugin.Register(domainblock.New())
// Initialize routes
a.initializeRoutes()
@ -304,19 +303,39 @@ func (a *App) handleMessage(item queue.Item) {
continue
}
// Process message
responses := p.OnMessage(message, channelPlugin.Config)
// Process message and get actions
actions := p.OnMessage(message, channelPlugin.Config)
// Send responses
// Get platform for processing actions
platform, err := platform.Get(item.Platform)
if err != nil {
a.logger.Error("Error getting platform", "error", err)
continue
}
for _, response := range responses {
if err := platform.SendMessage(response); err != nil {
a.logger.Error("Error sending message", "error", err)
// Process each action
for _, action := range actions {
switch action.Type {
case model.ActionSendMessage:
// Send a message
if action.Message != nil {
if err := platform.SendMessage(action.Message); err != nil {
a.logger.Error("Error sending message", "error", err)
}
} else {
a.logger.Error("Send message action with nil message")
}
case model.ActionDeleteMessage:
// Delete a message using direct DeleteMessage call
if err := platform.DeleteMessage(action.Chat, action.MessageID); err != nil {
a.logger.Error("Error deleting message", "error", err, "message_id", action.MessageID)
} else {
a.logger.Info("Message deleted", "message_id", action.MessageID)
}
default:
a.logger.Error("Unknown action type", "type", action.Type)
}
}
}
@ -390,4 +409,4 @@ func (a *App) processReminder(reminder *model.Reminder) {
if err := a.db.MarkReminderAsProcessed(reminder.ID); err != nil {
a.logger.Error("Error marking reminder as processed", "error", err)
}
}
}