Small Telegram bot, which rules «Night Zoo»
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1KB

  1. // Fantasy World Zookeeper Bot
  2. // Copyright (c) 2018 Vladimir "fat0troll" Hodakov
  3. package main
  4. import (
  5. "source.hodakov.me/fat0troll/fwzookeeper/context"
  6. "source.hodakov.me/fat0troll/fwzookeeper/domains/battles/v1"
  7. "source.hodakov.me/fat0troll/fwzookeeper/domains/commands/v1"
  8. "source.hodakov.me/fat0troll/fwzookeeper/internal/router"
  9. "source.hodakov.me/fat0troll/fwzookeeper/internal/telegram"
  10. "os"
  11. "os/signal"
  12. "runtime"
  13. "syscall"
  14. )
  15. func main() {
  16. // Before any real work - lock to OS thread. We shouldn't leave it until
  17. // shutdown
  18. runtime.LockOSThread()
  19. // Initializing context
  20. c := context.NewContext()
  21. c.Init()
  22. c.InitConfiguration()
  23. router.New(c)
  24. commandsv1.New(c)
  25. battlesv1.New(c)
  26. telegram.New(c)
  27. // CTRL+C handler.
  28. interrupt := make(chan os.Signal, 1)
  29. signal.Notify(interrupt)
  30. shutdownDone := make(chan bool, 1)
  31. go func() {
  32. signalThing := <-interrupt
  33. if signalThing == syscall.SIGTERM || signalThing == syscall.SIGINT {
  34. c.Logger.Info().Msg("Got " + signalThing.String() + " signal, shutting down...")
  35. shutdownDone <- true
  36. }
  37. }()
  38. <-shutdownDone
  39. os.Exit(0)
  40. }