From e72171f1ef9060cb7f92eaf64226fd355cb1570e Mon Sep 17 00:00:00 2001 From: Noah Date: Fri, 15 Mar 2024 19:19:19 -0500 Subject: [PATCH] Add site restart chat command (fix #21) --- matrix.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/matrix.go b/matrix.go index ab08f3d..b5aedd9 100644 --- a/matrix.go +++ b/matrix.go @@ -131,6 +131,25 @@ func initMatrix() { return text }) + registerChatCommand("restart", "Restart a site.", func(ctx context.Context, evt *event.Event, args []string) string { + if len(args) < 2 { + return "šŸ”“ Invalid site." + } + site, found, err := getSite(args[1]) + if err != nil { + return "šŸ”“ Failed to get site " + args[2] + "!" + } else if !found { + return "šŸ”“ Invalid site." + } + text := "āšŖļø Restarting server..." + derr := site.Restart() + if derr.code != 0 { + derr.SendOverMatrix() + return text + "\nšŸ”“ Failed to restart site!" + } + return text + "\nšŸŸ¢ Successfully restarted site." + }) + go func() { for range time.Tick(time.Second * 6) { log.Printf("Scanning for queued messages...")