This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
c.go
96 lines (74 loc) · 2.36 KB
/
c.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package templates
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"github.com/abdfnx/botway/constants"
"github.com/abdfnx/looker"
)
func MainCContent() string {
return Content("src/main.c", "discord-c", "", "")
}
func BWCContent(botName string) string {
return Content("packages/bwc/main.h", "botway", botName, "")
}
func CRunPsFileContent() string {
return Content("run.ps1", "discord-c", "", "")
}
func CTemplate(botName string) {
_, err := looker.LookPath("gcc")
if err != nil {
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR"))
fmt.Println(constants.FAIL_FOREGROUND.Render(" gcc is not installed"))
} else {
mainFile := os.WriteFile(filepath.Join(botName, "src", "main.c"), []byte(MainCContent()), 0644)
botwayHeaderFile := os.WriteFile(filepath.Join(botName, "src", "botway.h"), []byte(BWCContent(botName)), 0644)
runPsFile := os.WriteFile(filepath.Join(botName, "run.ps1"), []byte(CRunPsFileContent()), 0644)
dockerFile := os.WriteFile(filepath.Join(botName, "Dockerfile"), []byte(DockerfileContent(botName, "c-discord.dockerfile", "discord")), 0644)
resourcesFile := os.WriteFile(filepath.Join(botName, "resources.md"), []byte(Resources("discord", "c.md")), 0644)
if mainFile != nil {
log.Fatal(mainFile)
}
if botwayHeaderFile != nil {
log.Fatal(botwayHeaderFile)
}
if runPsFile != nil {
log.Fatal(runPsFile)
}
if dockerFile != nil {
log.Fatal(dockerFile)
}
if resourcesFile != nil {
log.Fatal(resourcesFile)
}
installScript := "https://raw.githubusercontent.com/botwayorg/discord-c/main/scripts/install-concord."
getConcord := exec.Command("bash", "-c", "curl -sL "+installScript+".sh | bash")
if runtime.GOOS == "windows" {
getConcord = exec.Command("powershell.exe", "irm "+installScript+".ps1 | iex")
}
getConcord.Dir = botName
getConcord.Stdin = os.Stdin
getConcord.Stdout = os.Stdout
getConcord.Stderr = os.Stderr
err = getConcord.Run()
if err != nil {
log.Printf("error: %v\n", err)
}
run := exec.Command("bash", "-c", "gcc src/main.c -o bot -pthread -ldiscord -lcurl")
if runtime.GOOS == "windows" {
run = exec.Command("powershell.exe", "./run.ps1")
}
run.Dir = botName
run.Stdin = os.Stdin
run.Stdout = os.Stdout
run.Stderr = os.Stderr
err = run.Run()
if err != nil {
log.Printf("error: %v\n", err)
}
CheckProject(botName, "discord")
}
}