package telegram import ( "git.dragon-labs.de/alphyron/group_helper/logic" "git.dragon-labs.de/alphyron/group_helper/models" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" "log" ) type RoutineManager struct { Routine []Routine Bot *tgbotapi.BotAPI GroupHelperService logic.GroupHelperService } func (rm RoutineManager) StartUpdates() { u := tgbotapi.NewUpdate(0) u.Timeout = 60 updates, _ := rm.Bot.GetUpdatesChan(u) for update := range updates { var group *models.Group var err error if update.Message != nil { group, err = rm.GroupHelperService.GetGroupByID(update.Message.Chat.ID) if err != nil { log.Println(err) continue } } else if update.CallbackQuery != nil { group, err = rm.GroupHelperService.GetGroupByID(update.CallbackQuery.Message.Chat.ID) if err != nil { log.Println(err) continue } } for _, routine := range rm.Routine { err := routine.Update(rm.Bot, &update, group) if err != nil { log.Printf("ERROR - Routine error") log.Println(err) } } } } func (rm *RoutineManager) RegisterRoutine(routine Routine) { if rm.Routine == nil { rm.Routine = make([]Routine, 0) } rm.Routine = append(rm.Routine, routine) }