This repository has been archived by the owner on Jul 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
138 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package php | ||
|
||
import "github.com/abdfnx/botway/templates" | ||
|
||
func DockerfileContent(botName string) string { | ||
return templates.Content("php.dockerfile", "dockerfiles", botName) | ||
} | ||
|
||
func MainPHPContent() string { | ||
return templates.Content("src/main.php", "discord-php", "") | ||
} | ||
|
||
func BotwayPHPContent() string { | ||
return templates.Content("src/botway.php", "discord-php", "") | ||
} | ||
|
||
func Resources() string { | ||
return templates.Content("discord/php.md", "resources", "") | ||
} | ||
|
||
func ComposerFileContent(botName string) string { | ||
return templates.Content("composer.json", "discord-php", botName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package php | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"runtime" | ||
|
||
"github.com/abdfnx/botway/constants" | ||
"github.com/abdfnx/botway/templates" | ||
"github.com/abdfnx/looker" | ||
) | ||
|
||
func DiscordPHP(botName string) { | ||
_, err := looker.LookPath("php") | ||
composerPath, serr := looker.LookPath("composer") | ||
|
||
if err != nil { | ||
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR")) | ||
fmt.Println(constants.FAIL_FOREGROUND.Render(" php is not installed")) | ||
} else if serr != nil { | ||
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR")) | ||
fmt.Println(constants.FAIL_FOREGROUND.Render(" composer is not installed")) | ||
} else { | ||
mainFile := os.WriteFile(filepath.Join(botName, "src", "main.php"), []byte(MainPHPContent()), 0644) | ||
botwayFile := os.WriteFile(filepath.Join(botName, "src", "botway.php"), []byte(BotwayPHPContent()), 0644) | ||
composerFile := os.WriteFile(filepath.Join(botName, "composer.json"), []byte(ComposerFileContent(botName)), 0644) | ||
dockerFile := os.WriteFile(filepath.Join(botName, "Dockerfile"), []byte(DockerfileContent(botName)), 0644) | ||
resourcesFile := os.WriteFile(filepath.Join(botName, "resources.md"), []byte(Resources()), 0644) | ||
|
||
if mainFile != nil { | ||
log.Fatal(mainFile) | ||
} | ||
|
||
if botwayFile != nil { | ||
log.Fatal(botwayFile) | ||
} | ||
|
||
if composerFile != nil { | ||
log.Fatal(composerFile) | ||
} | ||
|
||
if dockerFile != nil { | ||
log.Fatal(dockerFile) | ||
} | ||
|
||
if resourcesFile != nil { | ||
log.Fatal(resourcesFile) | ||
} | ||
|
||
composerInstall := composerPath + " install" | ||
|
||
installCmd := exec.Command("bash", "-c", composerInstall) | ||
|
||
if runtime.GOOS == "windows" { | ||
installCmd = exec.Command("powershell.exe", composerInstall) | ||
} | ||
|
||
installCmd.Dir = botName | ||
installCmd.Stdin = os.Stdin | ||
installCmd.Stdout = os.Stdout | ||
installCmd.Stderr = os.Stderr | ||
err = installCmd.Run() | ||
|
||
if err != nil { | ||
log.Printf("error: %v\n", err) | ||
} | ||
|
||
templates.CheckProject(botName, "discord") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters