From 4aa96b02db8cacfc0465272dc29401870724bcd5 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Tue, 26 Mar 2024 23:48:18 +0100 Subject: [PATCH] remove dumb intro to stop and add a propper ctrl+c --- bot.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bot.go b/bot.go index 19b6a50..8d2d471 100644 --- 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) { -- 2.30.2