Skip to content

Commit

Permalink
Add server install command
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnoStrife committed Oct 10, 2024
1 parent eaae3a1 commit 9256c01
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
6 changes: 3 additions & 3 deletions commands/admin/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func modsAdd(s *discordgo.Session, mods *ModJSON, modDescriptions *[]modDescript
alreadyAdded := support.DefaultTextList("\n**Already added:**")
userErrors := support.DefaultTextList("\n**Errors:**")

factorioVersion, err := factorioVersion()
factorioVersion, err := getFactorioVersionNoPatch()
if err != nil {
return "Error checking factorio version"
}
Expand Down Expand Up @@ -350,7 +350,7 @@ func modsAdd(s *discordgo.Session, mods *ModJSON, modDescriptions *[]modDescript
return res
}

func factorioVersion() (string, error) {
func getFactorioVersionNoPatch() (string, error) {
factorioVersion, err := support.FactorioVersion()
if err != nil {
return "", err
Expand All @@ -374,7 +374,7 @@ func modsUpdate(s *discordgo.Session, mods *ModJSON, modDescriptions *[]modDescr

files := matchModsWithFiles(&mods.Mods)

factorioVersion, err := factorioVersion()
factorioVersion, err := getFactorioVersionNoPatch()
if err != nil {
return "Error checking factorio version"
}
Expand Down
25 changes: 18 additions & 7 deletions commands/admin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ var ServerCommandDoc = support.CommandDoc{
Usage: "$server update\n" +
"$server update <version>",
},
{
Name: "install",
Doc: `same as update, but does not check version of the factorio server`,
Usage: "$server install\n" +
"$server install <version>",
},
},
}

Expand All @@ -55,24 +61,29 @@ func ServerCommand(s *discordgo.Session, args string) {
case "restart":
support.Factorio.Stop(s)
support.Factorio.Start(s)
case "install":
serverUpdate(s, false, arg)
case "update":
serverUpdate(s, arg)
serverUpdate(s, true, arg)
default:
support.SendFormat(s, "Usage: "+ServerCommandDoc.Usage)
}
}

func serverUpdate(s *discordgo.Session, version string) {
func serverUpdate(s *discordgo.Session, checkVersion bool, version string) {
if support.Factorio.IsRunning() {
support.Send(s, "You should stop the server first")
return
}
var factorioVersion string = "-1"
var err error
factorioVersion, err := support.FactorioVersion()
if err != nil {
support.Panik(err, "... checking factorio version")
support.Send(s, "Error checking factorio version")
return
if checkVersion {
factorioVersion, err = support.FactorioVersion()
if err != nil {
support.Panik(err, "... checking factorio version")
support.Send(s, "Error checking factorio version")
return
}
}

if version == "" {
Expand Down

0 comments on commit 9256c01

Please sign in to comment.