about summary refs log tree commit diff
path: root/cmd/bot/main.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-04-04 01:53:41 +0200
committerMel <einebeere@gmail.com>2022-04-04 01:53:41 +0200
commitfdd0ea7911b2c98f95ef99f6d1518ee4eb4dfd7a (patch)
tree702f893e5ef2ec4196cd37393014b3ca59e5c0dc /cmd/bot/main.go
parentb80bda2da026086523f1de8f460637a376c53bf2 (diff)
downloadjinx-fdd0ea7911b2c98f95ef99f6d1518ee4eb4dfd7a.tar.zst
jinx-fdd0ea7911b2c98f95ef99f6d1518ee4eb4dfd7a.zip
Listen to incoming messages and respond to pings
Diffstat (limited to 'cmd/bot/main.go')
-rw-r--r--cmd/bot/main.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/cmd/bot/main.go b/cmd/bot/main.go
index 51661e8..0f241c9 100644
--- a/cmd/bot/main.go
+++ b/cmd/bot/main.go
@@ -4,6 +4,8 @@ import (
 	"jinx/pkg/bot"
 	"log"
 	"os"
+	"os/signal"
+	"syscall"
 )
 
 func main() {
@@ -12,7 +14,18 @@ func main() {
 		log.Fatal("`BOT_TOKEN` is not set.")
 	}
 
-	if err := bot.Start(token); err != nil {
+	b, err := bot.Start(token)
+	if err != nil {
+		panic(err)
+	}
+
+	c := make(chan os.Signal, 2)
+	signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
+
+	s := <-c
+	log.Printf("received signal: %s! stopping...", s)
+
+	if err := b.Stop(); err != nil {
 		panic(err)
 	}
 }