✨ Create Constructor and implement the command routine
This commit is contained in:
parent
a69b46f714
commit
755d704d5a
22
main.go
22
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)
|
||||
|
||||
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 {
|
||||
|
21
telegram/routines/command.go
Normal file
21
telegram/routines/command.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user