2020-05-09 17:07:02 +00:00
|
|
|
package telegram
|
|
|
|
|
|
|
|
import (
|
2020-05-09 18:54:42 +00:00
|
|
|
"git.dragon-labs.de/alphyron/group_helper/logic"
|
2020-05-09 17:07:02 +00:00
|
|
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type RoutineManager struct {
|
2020-05-09 18:54:42 +00:00
|
|
|
Routine []Routine
|
|
|
|
Bot *tgbotapi.BotAPI
|
|
|
|
GroupHelperService logic.GroupHelperService
|
2020-05-09 17:07:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (rm RoutineManager) StartUpdates() {
|
|
|
|
u := tgbotapi.NewUpdate(0)
|
|
|
|
u.Timeout = 60
|
|
|
|
updates, _ := rm.Bot.GetUpdatesChan(u)
|
|
|
|
|
|
|
|
for update := range updates {
|
|
|
|
|
2020-05-09 18:54:42 +00:00
|
|
|
group, err := rm.GroupHelperService.GetGroupByID(update.Message.Chat.ID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-05-09 17:07:02 +00:00
|
|
|
for _, routine := range rm.Routine {
|
2020-05-09 20:44:28 +00:00
|
|
|
err := routine.Update(rm.Bot, &update, group)
|
2020-05-09 17:07:02 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|