fixed some ping stuff and made a cleanup
This commit is contained in:
16
main.go
16
main.go
@ -3,6 +3,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/kf5grd/keybasebot"
|
"github.com/kf5grd/keybasebot"
|
||||||
bot "github.com/kf5grd/keybasebot"
|
bot "github.com/kf5grd/keybasebot"
|
||||||
@ -39,7 +42,6 @@ func main() {
|
|||||||
bot: b,
|
bot: b,
|
||||||
}
|
}
|
||||||
b.LogWriter = w
|
b.LogWriter = w
|
||||||
|
|
||||||
// register the bot commands
|
// register the bot commands
|
||||||
b.Commands = append(b.Commands,
|
b.Commands = append(b.Commands,
|
||||||
keybasebot.BotCommand{
|
keybasebot.BotCommand{
|
||||||
@ -48,7 +50,17 @@ func main() {
|
|||||||
Run: keybasebot.Adapt(sendPong, keybasebot.MessageType("text"), keybasebot.CommandPrefix("!ping")),
|
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
|
// then run
|
||||||
b.Run()
|
b.Run()
|
||||||
}
|
}
|
||||||
|
|||||||
1
ping.go
1
ping.go
@ -13,5 +13,6 @@ var pingAd = chat1.UserBotCommandInput{
|
|||||||
|
|
||||||
func sendPong(m chat1.MsgSummary, b *keybasebot.Bot) (bool, error) {
|
func sendPong(m chat1.MsgSummary, b *keybasebot.Bot) (bool, error) {
|
||||||
b.KB.SendMessageByConvID(m.ConvID, "Pong!")
|
b.KB.SendMessageByConvID(m.ConvID, "Pong!")
|
||||||
|
b.Logger.Info("ping rx in convid %s", m.ConvID)
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user