Create Constructor and implement the command routine

This commit is contained in:
Alphyron 2020-05-09 19:36:15 +02:00
parent a69b46f714
commit 755d704d5a
2 changed files with 33 additions and 10 deletions

22
main.go
View File

@ -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)
for update := range updates {
_, err := cm.ExecuteUpdate(&update)
if err != nil {
log.Printf("ERROR - Command error")
log.Println(err)
rm.StartUpdates()
}
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 {

View File

@ -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
}