The new logbot, not committed from the wrong terminal window this time.
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.

41 lines
908 B

6 years ago
  1. package main
  2. import (
  3. "context"
  4. "log"
  5. "os"
  6. "os/signal"
  7. "strings"
  8. "syscall"
  9. "git.aiterp.net/rpdata/logbot3/internal/bot"
  10. "git.aiterp.net/rpdata/logbot3/internal/config"
  11. "git.aiterp.net/rpdata/logbot3/internal/models/users"
  12. )
  13. func main() {
  14. conf := config.Get()
  15. user, err := users.CheckToken(context.Background())
  16. if user.LoggedIn() {
  17. log.Printf("Logged in: %s (%s)", user.ID, strings.Join(user.Permissions, ", "))
  18. } else {
  19. log.Println("Warning: API key did not gain us access:", err)
  20. os.Exit(1)
  21. }
  22. bot := bot.New(context.Background(), conf.Bot.Nicks[0], conf.Bot.Nicks[1:])
  23. err = bot.Connect(conf.Bot.Server, false)
  24. if err != nil {
  25. log.Println("Warning:", err)
  26. os.Exit(1)
  27. }
  28. // Listen for a quit signal.
  29. interrupt := make(chan os.Signal, 1)
  30. signal.Notify(interrupt, os.Interrupt)
  31. signal.Notify(interrupt, syscall.SIGTERM)
  32. log.Println("Interrupt received, stopping...")
  33. }