From 636b5d4bb61ab499328c970f48c2e4c1978717df Mon Sep 17 00:00:00 2001 From: pocketjawa Date: Tue, 6 Aug 2019 21:45:09 -0400 Subject: [PATCH] Add bot restart/kill command --- commands.go | 16 ++++++++++++++++ pocketbot.go | 1 + 2 files changed, 17 insertions(+) diff --git a/commands.go b/commands.go index 3fae3ea..1de9ed7 100644 --- a/commands.go +++ b/commands.go @@ -5,7 +5,9 @@ import ( "github.com/bwmarrin/disgord/x/mux" "github.com/nishanths/go-xkcd" "io/ioutil" + "log" "net/http" + "os" "regexp" "strconv" ) @@ -84,3 +86,17 @@ func getXKCD(s *discordgo.Session, m *discordgo.Message, ctx *mux.Context) { resp = comic.ImageURL s.ChannelMessageSend(m.ChannelID, resp) } + +//Restart the bot +func restartBot(s *discordgo.Session, m *discordgo.Message, ctx *mux.Context) { + if !checkRole(s, m, ctx, os.Getenv("POCKETBOT_ADMIN_ROLE")) { + resp := "OwO you aren't my daddy..." + s.ChannelMessageSend(m.ChannelID, resp) + return + } + resp := "Goodnight ;-;" + s.ChannelMessageSend(m.ChannelID, resp) + Session.Close() + log.Println("brb dying at the request of ", m.Author.String()) + os.Exit(0) +} diff --git a/pocketbot.go b/pocketbot.go index c8d689c..e755ec1 100644 --- a/pocketbot.go +++ b/pocketbot.go @@ -57,6 +57,7 @@ func main() { Router.Route("monday", "It's Maki Monday my dudes!", makiMonday) Router.Route("mixes", "Post the link to my fire mixtapes!", postMixes) Router.Route("xkcd", "Post a specific, random, or the latest XKCD comic", getXKCD) + Router.Route("restart", "Restart the bot.", restartBot) //Open a connection to Discord err = Session.Open()