From 65044525803b2b7f413a57394206fa3671b1b02f Mon Sep 17 00:00:00 2001 From: David Haukeness Date: Thu, 14 Jan 2021 10:56:58 -0700 Subject: [PATCH] fixed some ping stuff and made a cleanup --- main.go | 16 ++++++++++++++-- ping.go | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 92422cc..fab24c6 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,9 @@ package main import ( "fmt" "os" + "os/signal" + "syscall" + "time" "github.com/kf5grd/keybasebot" bot "github.com/kf5grd/keybasebot" @@ -39,7 +42,6 @@ func main() { bot: b, } b.LogWriter = w - // register the bot commands b.Commands = append(b.Commands, keybasebot.BotCommand{ @@ -48,7 +50,17 @@ func main() { Run: keybasebot.Adapt(sendPong, keybasebot.MessageType("text"), keybasebot.CommandPrefix("!ping")), }, ) - + // catch ctrl-c so we can clean up + c := make(chan os.Signal) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) + go func() { + <-c + b.Logger.Info("Caught SIGINT, cleaning up.") + b.KB.ClearCommands() + b.Logger.Info("Cleared command adverts. Bye.") + time.Sleep(time.Second * 2) + os.Exit(0) + }() // then run b.Run() } diff --git a/ping.go b/ping.go index 4b2bfcc..9c4fa3f 100644 --- a/ping.go +++ b/ping.go @@ -13,5 +13,6 @@ var pingAd = chat1.UserBotCommandInput{ func sendPong(m chat1.MsgSummary, b *keybasebot.Bot) (bool, error) { b.KB.SendMessageByConvID(m.ConvID, "Pong!") + b.Logger.Info("ping rx in convid %s", m.ConvID) return true, nil }