Add site start chat command (fix #23)

This commit is contained in:
Noah 2024-03-27 12:03:12 -05:00
parent 852874a12a
commit 7ccd29bfb1

View File

@ -150,6 +150,25 @@ func initMatrix() {
return text + "\n🟢 Successfully restarted site." return text + "\n🟢 Successfully restarted site."
}) })
registerChatCommand("start", "Start 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 := "⚪️ Starting server..."
if derr := site.Start(); derr.code != 0 {
derr.SendOverMatrix()
return text + "\n🔴 Failed to stop site!"
}
return text + "\n🟢 Successfully started site."
})
registerChatCommand("stop", "Stop a site.", func(ctx context.Context, evt *event.Event, args []string) string { registerChatCommand("stop", "Stop a site.", func(ctx context.Context, evt *event.Event, args []string) string {
if len(args) < 2 { if len(args) < 2 {
return "🔴 Invalid site." return "🔴 Invalid site."
@ -166,7 +185,6 @@ func initMatrix() {
return text + "\n🔴 Failed to stop site!" return text + "\n🔴 Failed to stop site!"
} }
return text + "\n🟢 Successfully stopped site." return text + "\n🟢 Successfully stopped site."
}) })
go func() { go func() {