Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
upgrade modules, add botway discord c# template handler
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Jul 2, 2022
1 parent 94505d6 commit dfabab0
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 3 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/spf13/viper v1.12.0
github.com/tidwall/gjson v1.14.1
github.com/tidwall/sjson v1.2.4
golang.org/x/sys v0.0.0-20220624220833-87e55d714810
golang.org/x/sys v0.0.0-20220702020025-31831981b65f
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467
gopkg.in/yaml.v3 v3.0.1
)
Expand Down Expand Up @@ -92,14 +92,14 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/stretchr/testify v1.7.5 // indirect
github.com/stretchr/testify v1.8.0 // indirect
github.com/subosito/gotenv v1.4.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4 // indirect
github.com/yuin/goldmark v1.4.12 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect
golang.org/x/net v0.0.0-20220630215102-69896b714898 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1F
github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.7.5 h1:s5PTfem8p8EbKQOctVV53k6jCJt3UX4IEJzwh+C324Q=
github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/subosito/gotenv v1.4.0 h1:yAzM1+SmVcz5R4tXGsNMu1jUl2aOJXoiWUCEwwnGrvs=
github.com/subosito/gotenv v1.4.0/go.mod h1:mZd6rFysKEcUhUHXJk0C/08wAgyDBFuwEYL7vWWGaGo=
Expand Down Expand Up @@ -678,6 +680,8 @@ golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e h1:TsQ7F31D3bUCLeqPT0u+yjp1guoArKaNKmCr22PYgTQ=
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220630215102-69896b714898 h1:K7wO6V1IrczY9QOQ2WkVpw4JQSwCd52UsxVEirZUfiw=
golang.org/x/net v0.0.0-20220630215102-69896b714898/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -764,6 +768,8 @@ golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220624220833-87e55d714810 h1:rHZQSjJdAI4Xf5Qzeh2bBc5YJIkPFVM6oDtMFYmgws0=
golang.org/x/sys v0.0.0-20220624220833-87e55d714810/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220702020025-31831981b65f h1:xdsejrW/0Wf2diT5CPp3XmKUNbr7Xvw8kYilQ+6qjRY=
golang.org/x/sys v0.0.0-20220702020025-31831981b65f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
3 changes: 3 additions & 0 deletions internal/pipes/new/discord_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package new

import (
"github.com/abdfnx/botway/templates/discord/crystal"
"github.com/abdfnx/botway/templates/discord/csharp"
"github.com/abdfnx/botway/templates/discord/deno"
"github.com/abdfnx/botway/templates/discord/go"
"github.com/abdfnx/botway/templates/discord/nodejs"
Expand Down Expand Up @@ -32,6 +33,8 @@ func DiscordHandler(m model) {
rust.DiscordRust(opts.BotName, "fleet")
} else if m.PlatformChoice == 0 && m.LangChoice == 5 {
deno.DiscordDeno(opts.BotName)
} else if m.PlatformChoice == 0 && m.LangChoice == 6 {
csharp.DiscordCsharp(opts.BotName)
} else if m.PlatformChoice == 0 && m.LangChoice == 7 {
crystal.DiscordCrystal(opts.BotName)
}
Expand Down
19 changes: 19 additions & 0 deletions templates/discord/csharp/contents.go
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", "")
}
64 changes: 64 additions & 0 deletions templates/discord/csharp/index.go
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")
}
}

0 comments on commit dfabab0

Please sign in to comment.