diff --git a/main.go b/main.go index 6083160..19832ec 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,8 @@ import ( "git.dragon-labs.de/alphyron/group_helper/config" "git.dragon-labs.de/alphyron/group_helper/logic" "git.dragon-labs.de/alphyron/group_helper/repository" + "git.dragon-labs.de/alphyron/group_helper/telegram" + "git.dragon-labs.de/alphyron/group_helper/telegram/routines" "log" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" @@ -54,19 +56,19 @@ func main() { service := logic.NewGroupHelperService(groupHelperRepo) cm := InitialCommandManager(bot, service) + rm := InitialRoutineManager(bot, cm) - u := tgbotapi.NewUpdate(0) - u.Timeout = 60 - updates, _ := bot.GetUpdatesChan(u) + rm.StartUpdates() +} - for update := range updates { - _, err := cm.ExecuteUpdate(&update) - - if err != nil { - log.Printf("ERROR - Command error") - log.Println(err) - } +func InitialRoutineManager(bot *tgbotapi.BotAPI, commandManager *cli.CommandManager) *telegram.RoutineManager { + rm := &telegram.RoutineManager{ + Bot: bot, } + + rm.RegisterRoutine(routines.NewCommandRoutine(commandManager)) + + return rm } func InitialCommandManager(bot *tgbotapi.BotAPI, service logic.GroupHelperService) *cli.CommandManager { diff --git a/telegram/routines/command.go b/telegram/routines/command.go new file mode 100644 index 0000000..0d517c0 --- /dev/null +++ b/telegram/routines/command.go @@ -0,0 +1,21 @@ +package routines + +import ( + "git.dragon-labs.de/alphyron/group_helper/cli" + "git.dragon-labs.de/alphyron/group_helper/telegram" + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" +) + +type commandRoutine struct { + CommandManager *cli.CommandManager +} + +func NewCommandRoutine(commandManager *cli.CommandManager) telegram.Routine { + return &commandRoutine{CommandManager: commandManager} +} + +func (cr commandRoutine) Update(update *tgbotapi.Update) error { + _, err := cr.CommandManager.ExecuteUpdate(update) + + return err +}