Add site restart chat command (fix #21)

This commit is contained in:
Noah 2024-03-15 19:19:19 -05:00
parent 85ab2a963b
commit e72171f1ef

View File

@ -131,6 +131,25 @@ func initMatrix() {
return text 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() { go func() {
for range time.Tick(time.Second * 6) { for range time.Tick(time.Second * 6) {
log.Printf("Scanning for queued messages...") log.Printf("Scanning for queued messages...")