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.
upgrade modules, add botway discord c# template handler
- Loading branch information
Showing
5 changed files
with
95 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package csharp | ||
|
||
import "github.com/abdfnx/botway/templates" | ||
|
||
func DockerfileContent(botName string) string { | ||
return templates.Content("csharp.dockerfile", "dockerfiles", botName) | ||
} | ||
|
||
func Resources() string { | ||
return templates.Content("discord/csharp.md", "resources", "") | ||
} | ||
|
||
func MainCsContent() string { | ||
return templates.Content("src/Main.cs", "discord-csharp", "") | ||
} | ||
|
||
func BotCSharpProj() string { | ||
return templates.Content("discord-csharp.csproj", "discord-csharp", "") | ||
} |
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,64 @@ | ||
package csharp | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"runtime" | ||
|
||
"github.com/abdfnx/botway/constants" | ||
"github.com/abdfnx/botway/templates" | ||
"github.com/abdfnx/looker" | ||
) | ||
|
||
func DiscordCsharp(botName string) { | ||
dotnetPath, err := looker.LookPath("dotnet") | ||
|
||
if err != nil { | ||
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR")) | ||
fmt.Println(constants.FAIL_FOREGROUND.Render(" dotnet is not installed")) | ||
} else { | ||
mainFile := os.WriteFile(filepath.Join(botName, "src", "Main.cs"), []byte(MainCsContent()), 0644) | ||
csprojFile := os.WriteFile(filepath.Join(botName, botName + ".csproj"), []byte(BotCSharpProj()), 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 csprojFile != nil { | ||
log.Fatal(csprojFile) | ||
} | ||
|
||
if dockerFile != nil { | ||
log.Fatal(dockerFile) | ||
} | ||
|
||
if resourcesFile != nil { | ||
log.Fatal(resourcesFile) | ||
} | ||
|
||
dotNetRestore := dotnetPath + " restore" | ||
|
||
restoreCmd := exec.Command("bash", "-c", dotNetRestore) | ||
|
||
if runtime.GOOS == "windows" { | ||
restoreCmd = exec.Command("powershell.exe", dotNetRestore) | ||
} | ||
|
||
restoreCmd.Dir = botName | ||
restoreCmd.Stdin = os.Stdin | ||
restoreCmd.Stdout = os.Stdout | ||
restoreCmd.Stderr = os.Stderr | ||
err = restoreCmd.Run() | ||
|
||
if err != nil { | ||
log.Printf("error: %v\n", err) | ||
} | ||
|
||
templates.CheckProject(botName, "discord") | ||
} | ||
} |