remove dumb intro to stop and add a propper ctrl+c
authorEduardo <[email protected]>
Tue, 26 Mar 2024 22:48:18 +0000 (23:48 +0100)
committerEduardo <[email protected]>
Tue, 26 Mar 2024 22:48:18 +0000 (23:48 +0100)
bot.go

diff --git a/bot.go b/bot.go
index 19b6a509347d4df8c717c9b46a8875ce1538653b..8d2d471d2ea59b0e7b8736bc32bb9e69b65cd3b8 100644 (file)
--- a/bot.go
+++ b/bot.go
@@ -1,14 +1,15 @@
 package main
 
 import (
-       "bufio"
        "context"
        "log"
        "os"
+       "os/signal"
        "regexp"
        "sort"
        "strconv"
        "strings"
+       "syscall"
 
        "github.com/bwmarrin/discordgo"
        tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
@@ -93,11 +94,12 @@ func main() {
        // Tell the user the bot is online
        log.Println("Discord Bot ready.")
 
-       log.Println("Press enter to stop")
-       // Wait for a newline symbol, then cancel handling updates
-       bufio.NewReader(os.Stdin).ReadBytes('\n')
+       done := make(chan os.Signal, 1)
+       signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)
+       log.Println("Blocking, press ctrl+c to continue...")
+       // Wait for a ctrl+c, then cancel handling updates
+       <-done
        cancel()
-
 }
 
 func receiveUpdates(ctx context.Context, updates tgbotapi.UpdatesChannel) {