multi-dc 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 4
6
+ tab_width = 4
7
+ end_of_line = unset
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
@@ -0,0 +1,12 @@
1
+ * text=auto
2
+
3
+ .editorconfig text
4
+ .gitattributes text export-ignore
5
+ .gitignore text export-ignore
6
+ Dockerfile text
7
+
8
+ *.go text diff=golang
9
+ *.json text
10
+ *.md text diff=markdown
11
+ *.mod text eol=lf
12
+ *.sum text eol=lf
@@ -0,0 +1,3 @@
1
+ {
2
+ "recommendations": ["golang.go"]
3
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "name": "Launch subcommand",
6
+ "type": "go",
7
+ "request": "launch",
8
+ "mode": "debug",
9
+ "program": "${workspaceFolder}",
10
+ "debugAdapter": "dlv-dap",
11
+ "env": {},
12
+ "args": ["subcommand", "Hello, World!"],
13
+ "console": "internalConsole"
14
+ },
15
+ {
16
+ "name": "Launch subcommand with flag",
17
+ "type": "go",
18
+ "request": "launch",
19
+ "mode": "debug",
20
+ "program": "${workspaceFolder}",
21
+ "debugAdapter": "dlv-dap",
22
+ "env": {},
23
+ "args": ["subcommand", "-f", "1234567890", "Hello, World!"],
24
+ "console": "internalConsole"
25
+ }
26
+ ]
27
+ }
package/cli/Dockerfile ADDED
@@ -0,0 +1,23 @@
1
+ # Production Build Stage
2
+ FROM golang:1.22.5 AS build
3
+ WORKDIR /app
4
+
5
+ COPY . ./
6
+ RUN go mod download && go mod verify
7
+
8
+ RUN useradd -u 1001 appuser
9
+ RUN go build -ldflags="-linkmode external -extldflags -static" -o ./bin/multi-dc
10
+
11
+
12
+ # Production Release Stage
13
+ FROM scratch
14
+ WORKDIR /app
15
+
16
+ ENV GIN_MODE=release
17
+
18
+ COPY --from=build /etc/passwd /etc/passwd
19
+ COPY --from=build /app/bin/multi-dc ./multi-dc
20
+
21
+ USER appuser
22
+
23
+ ENTRYPOINT ["./multi-dc"]
package/cli/LICENSE.md ADDED
@@ -0,0 +1,119 @@
1
+ CC0 1.0 Universal
2
+
3
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
4
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
5
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
6
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
7
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
8
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
9
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
10
+ HEREUNDER.
11
+
12
+ Statement of Purpose
13
+
14
+ The laws of most jurisdictions throughout the world automatically confer
15
+ exclusive Copyright and Related Rights (defined below) upon the creator
16
+ and subsequent owner(s) (each and all, an "owner") of an original work of
17
+ authorship and/or a database (each, a "Work").
18
+
19
+ Certain owners wish to permanently relinquish those rights to a Work for
20
+ the purpose of contributing to a commons of creative, cultural and
21
+ scientific works ("Commons") that the public can reliably and without fear
22
+ of later claims of infringement build upon, modify, incorporate in other
23
+ works, reuse and redistribute as freely as possible in any form whatsoever
24
+ and for any purposes, including without limitation commercial purposes.
25
+ These owners may contribute to the Commons to promote the ideal of a free
26
+ culture and the further production of creative, cultural and scientific
27
+ works, or to gain reputation or greater distribution for their Work in
28
+ part through the use and efforts of others.
29
+
30
+ For these and/or other purposes and motivations, and without any
31
+ expectation of additional consideration or compensation, the person
32
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or she
33
+ is an owner of Copyright and Related Rights in the Work, voluntarily
34
+ elects to apply CC0 to the Work and publicly distribute the Work under its
35
+ terms, with knowledge of his or her Copyright and Related Rights in the
36
+ Work and the meaning and intended legal effect of CC0 on those rights.
37
+
38
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
39
+ protected by copyright and related or neighboring rights ("Copyright and
40
+ Related Rights"). Copyright and Related Rights include, but are not
41
+ limited to, the following:
42
+
43
+ i. the right to reproduce, adapt, distribute, perform, display,
44
+ communicate, and translate a Work;
45
+ ii. moral rights retained by the original author(s) and/or performer(s);
46
+ iii. publicity and privacy rights pertaining to a person's image or
47
+ likeness depicted in a Work;
48
+ iv. rights protecting against unfair competition in regards to a Work,
49
+ subject to the limitations in paragraph 4(a), below;
50
+ v. rights protecting the extraction, dissemination, use and reuse of data
51
+ in a Work;
52
+ vi. database rights (such as those arising under Directive 96/9/EC of the
53
+ European Parliament and of the Council of 11 March 1996 on the legal
54
+ protection of databases, and under any national implementation
55
+ thereof, including any amended or successor version of such
56
+ directive); and
57
+ vii. other similar, equivalent or corresponding rights throughout the
58
+ world based on applicable law or treaty, and any national
59
+ implementations thereof.
60
+
61
+ 2. Waiver. To the greatest extent permitted by, but not in contravention
62
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
63
+ irrevocably and unconditionally waives, abandons, and surrenders all of
64
+ Affirmer's Copyright and Related Rights and associated claims and causes
65
+ of action, whether now known or unknown (including existing as well as
66
+ future claims and causes of action), in the Work (i) in all territories
67
+ worldwide, (ii) for the maximum duration provided by applicable law or
68
+ treaty (including future time extensions), (iii) in any current or future
69
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
70
+ including without limitation commercial, advertising or promotional
71
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
72
+ member of the public at large and to the detriment of Affirmer's heirs and
73
+ successors, fully intending that such Waiver shall not be subject to
74
+ revocation, rescission, cancellation, termination, or any other legal or
75
+ equitable action to disrupt the quiet enjoyment of the Work by the public
76
+ as contemplated by Affirmer's express Statement of Purpose.
77
+
78
+ 3. Public License Fallback. Should any part of the Waiver for any reason
79
+ be judged legally invalid or ineffective under applicable law, then the
80
+ Waiver shall be preserved to the maximum extent permitted taking into
81
+ account Affirmer's express Statement of Purpose. In addition, to the
82
+ extent the Waiver is so judged Affirmer hereby grants to each affected
83
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
84
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
85
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
86
+ maximum duration provided by applicable law or treaty (including future
87
+ time extensions), (iii) in any current or future medium and for any number
88
+ of copies, and (iv) for any purpose whatsoever, including without
89
+ limitation commercial, advertising or promotional purposes (the
90
+ "License"). The License shall be deemed effective as of the date CC0 was
91
+ applied by Affirmer to the Work. Should any part of the License for any
92
+ reason be judged legally invalid or ineffective under applicable law, such
93
+ partial invalidity or ineffectiveness shall not invalidate the remainder
94
+ of the License, and in such case Affirmer hereby affirms that he or she
95
+ will not (i) exercise any of his or her remaining Copyright and Related
96
+ Rights in the Work or (ii) assert any associated claims and causes of
97
+ action with respect to the Work, in either case contrary to Affirmer's
98
+ express Statement of Purpose.
99
+
100
+ 4. Limitations and Disclaimers.
101
+
102
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
103
+ surrendered, licensed or otherwise affected by this document.
104
+ b. Affirmer offers the Work as-is and makes no representations or
105
+ warranties of any kind concerning the Work, express, implied,
106
+ statutory or otherwise, including without limitation warranties of
107
+ title, merchantability, fitness for a particular purpose, non
108
+ infringement, or the absence of latent or other defects, accuracy, or
109
+ the present or absence of errors, whether or not discoverable, all to
110
+ the greatest extent permissible under applicable law.
111
+ c. Affirmer disclaims responsibility for clearing rights of other persons
112
+ that may apply to the Work or any use thereof, including without
113
+ limitation any person's Copyright and Related Rights in the Work.
114
+ Further, Affirmer disclaims responsibility for obtaining any necessary
115
+ consents, permissions or other rights required for any use of the
116
+ Work.
117
+ d. Affirmer understands and acknowledges that Creative Commons is not a
118
+ party to this document and has no duty or obligation with respect to
119
+ this CC0 or use of the Work.
package/cli/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # multi-dc
2
+
3
+ A CLI tool for running multiple discord.js bots from separate folders in one Node.js process.
4
+
5
+ ### Built With
6
+
7
+ - [![Golang][golang-shield]][golang-url]
8
+
9
+ ## Usage
10
+
11
+ Execute `multi-dc help` for more detailed information.
12
+
13
+ | Command | Arguments | Description |
14
+ | ------- | --------- | ---------------------------------- |
15
+ | run | `[flags]` | Run the multi-bot configuration |
16
+ | init | `[flags]` | Initialize a new multi-bot project |
17
+
18
+ ### Flags
19
+
20
+ #### run
21
+
22
+ - `-c, --config <file>` - Path to config file
23
+
24
+ #### init
25
+
26
+ - `-d, --dir <folder>` - Directory to create the project in (default: "./multi-bot-project")
27
+ - `-l, --lang <ts|js>` - Language to use (default: "ts")
28
+
29
+ ## Examples
30
+
31
+ ```sh
32
+ multi-dc run
33
+ multi-dc run --config ./multi-discord.config.ts
34
+ multi-dc init --dir ./my-bots --lang ts
35
+ ```
36
+
37
+ ## Development
38
+
39
+ ### Build
40
+
41
+ ```sh
42
+ go build
43
+ ```
44
+
45
+ ### Debugging
46
+
47
+ Using the [Delve][delve-url] debugger with CLI applications is a little tricky. See the [Delve documentation][delve-debug-url] for recommended procedures on how to do this.
48
+
49
+ ### Release
50
+
51
+ While the produced binary is a CLI application and is intended to be executed by directly, a containerized installation is also provided. This container utilizes a dedicated build stage along with the [scratch][scratch-url] Docker image to ensure the final image contains only the necessary resources and nothing else.
52
+
53
+ #### Build
54
+
55
+ ```sh
56
+ docker build . -t multi-dc
57
+ docker run multi-dc run
58
+ ```
59
+
60
+ ## License
61
+
62
+ This example code is provided to the public domain via the CC0 1.0 Universal License. See [LICENSE.md](./LICENSE.md) for more information.
63
+
64
+ <!-- Reference Links -->
65
+
66
+ [golang-url]: https://go.dev
67
+ [golang-shield]: https://img.shields.io/badge/golang-09657c?style=for-the-badge&logo=go&logoColor=79d2fa
68
+ [delve-url]: https://github.com/go-delve/delve
69
+ [delve-debug-url]: https://github.com/go-delve/delve/blob/master/Documentation/faq.md#-how-can-i-use-delve-to-debug-a-cli-application
70
+ [scratch-url]: https://hub.docker.com/_/scratch/
@@ -0,0 +1,69 @@
1
+ package cmd
2
+
3
+ import (
4
+ "fmt"
5
+ "os"
6
+ "os/exec"
7
+ "path/filepath"
8
+
9
+ "github.com/spf13/cobra"
10
+ )
11
+
12
+ var (
13
+ initDir string
14
+ initLanguage string
15
+ )
16
+
17
+ var initCmd = &cobra.Command{
18
+ Use: "init",
19
+ Short: "Initialize a new multi-bot project",
20
+ Long: "Creates a new multi-bot project with the specified directory and language.",
21
+ RunE: func(cmd *cobra.Command, args []string) error {
22
+ cliDir, err := os.Getwd()
23
+ if err != nil {
24
+ return err
25
+ }
26
+
27
+ runnerPath := filepath.Join(cliDir, "src", "init.js")
28
+
29
+ if _, err := os.Stat(runnerPath); os.IsNotExist(err) {
30
+ runnerPath = filepath.Join(cliDir, "dist", "init.js")
31
+ }
32
+
33
+ child := exec.Command(
34
+ "node",
35
+ "--import", "tsx",
36
+ runnerPath,
37
+ "--dir", initDir,
38
+ "--lang", initLanguage,
39
+ )
40
+ child.Stdout = os.Stdout
41
+ child.Stderr = os.Stderr
42
+ child.Stdin = os.Stdin
43
+
44
+ err = child.Run()
45
+ if err != nil {
46
+ return err
47
+ }
48
+
49
+ invocationDir := os.Getenv("INIT_CWD")
50
+ if invocationDir == "" {
51
+ invocationDir, _ = os.Getwd()
52
+ }
53
+
54
+ relativePath, _ := filepath.Rel(invocationDir, initDir)
55
+ if relativePath == "" {
56
+ relativePath = "."
57
+ }
58
+
59
+ fmt.Printf("[multi-dc] next: cd %s && npm install && npm run dev\n", relativePath)
60
+
61
+ return nil
62
+ },
63
+ }
64
+
65
+ func init() {
66
+ rootCmd.AddCommand(initCmd)
67
+ initCmd.Flags().StringVarP(&initDir, "dir", "d", "./multi-bot-project", "Directory to create the project in")
68
+ initCmd.Flags().StringVarP(&initLanguage, "lang", "l", "ts", "Language to use (ts or js)")
69
+ }
@@ -0,0 +1,30 @@
1
+ package cmd
2
+
3
+ import (
4
+ "log"
5
+
6
+ "github.com/spf13/cobra"
7
+ )
8
+
9
+ var rootCmd = &cobra.Command{
10
+ Use: "multi-dc",
11
+ Short: "Run multiple discord.js bots from separate folders in one Node.js process.",
12
+ Long: `multi-dc is a CLI tool for running multiple discord.js bots from
13
+ separate folders in a single Node.js process.
14
+
15
+ Usage:
16
+ multi-dc run [--config <file>]
17
+ multi-dc init [--dir <folder>] [--lang ts|js]
18
+
19
+ Examples:
20
+ multi-dc run
21
+ multi-dc run --config ./multi-discord.config.ts
22
+ multi-dc init --dir ./my-bots --lang ts`,
23
+ }
24
+
25
+ func Execute() {
26
+ err := rootCmd.Execute()
27
+ if err != nil {
28
+ log.Fatal(err)
29
+ }
30
+ }
package/cli/cmd/run.go ADDED
@@ -0,0 +1,86 @@
1
+ package cmd
2
+
3
+ import (
4
+ "os"
5
+ "os/exec"
6
+ "path/filepath"
7
+
8
+ "github.com/spf13/cobra"
9
+ )
10
+
11
+ var runCmd = &cobra.Command{
12
+ Use: "run",
13
+ Short: "Run the multi-bot configuration",
14
+ Long: "Runs the configured bots from the multi-discord.config file.",
15
+ RunE: func(cmd *cobra.Command, args []string) error {
16
+ configPath, err := cmd.Flags().GetString("config")
17
+ if err != nil {
18
+ return err
19
+ }
20
+
21
+ if configPath == "" {
22
+ configPath, err = resolveDefaultConfigPath()
23
+ if err != nil {
24
+ return err
25
+ }
26
+ if configPath == "" {
27
+ os.Stderr.WriteString("No config file found. Expected one of:\n- multi-discord.config.ts\n- multi-discord.config.js\n")
28
+ os.Exit(1)
29
+ }
30
+ }
31
+
32
+ cliDir, err := os.Getwd()
33
+ if err != nil {
34
+ return err
35
+ }
36
+
37
+ runnerPath := filepath.Join(cliDir, "src", "internal-runner.js")
38
+
39
+ child := exec.Command(
40
+ "node",
41
+ "--import", "tsx",
42
+ runnerPath,
43
+ "--config", configPath,
44
+ )
45
+ child.Stdout = os.Stdout
46
+ child.Stderr = os.Stderr
47
+ child.Stdin = os.Stdin
48
+
49
+ sigChan := make(chan os.Signal, 1)
50
+ go func() {
51
+ <-sigChan
52
+ if child.Process != nil {
53
+ child.Process.Kill()
54
+ }
55
+ }()
56
+
57
+ err = child.Run()
58
+ if err != nil {
59
+ return err
60
+ }
61
+
62
+ return nil
63
+ },
64
+ }
65
+
66
+ func resolveDefaultConfigPath() (string, error) {
67
+ configFiles := []string{
68
+ "multi-discord.config.ts",
69
+ "multi-discord.config.js",
70
+ "multi-discord.config.mts",
71
+ "multi-discord.config.mjs",
72
+ }
73
+
74
+ for _, configFile := range configFiles {
75
+ if _, err := os.Stat(configFile); err == nil {
76
+ return configFile, nil
77
+ }
78
+ }
79
+
80
+ return "", nil
81
+ }
82
+
83
+ func init() {
84
+ rootCmd.AddCommand(runCmd)
85
+ runCmd.Flags().StringP("config", "c", "", "Path to config file")
86
+ }
package/cli/go.mod ADDED
@@ -0,0 +1,10 @@
1
+ module github.com/multidc/cli
2
+
3
+ go 1.22.5
4
+
5
+ require github.com/spf13/cobra v1.8.0
6
+
7
+ require (
8
+ github.com/inconshreveable/mousetrap v1.1.0 // indirect
9
+ github.com/spf13/pflag v1.0.5 // indirect
10
+ )
package/cli/go.sum ADDED
@@ -0,0 +1,10 @@
1
+ github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
2
+ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
3
+ github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
4
+ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
5
+ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
6
+ github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
7
+ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
8
+ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
9
+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
10
+ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
package/cli/main.go ADDED
@@ -0,0 +1,9 @@
1
+ package main
2
+
3
+ import (
4
+ "github.com/multidc/cli/cmd"
5
+ )
6
+
7
+ func main() {
8
+ cmd.Execute()
9
+ }
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+ const path = require("path");
3
+ const fs = require("fs");
4
+
5
+ const platform = process.platform;
6
+ let binaryName = "multi-dc";
7
+
8
+ if (platform === "win32") {
9
+ binaryName = "multi-dc.exe";
10
+ }
11
+
12
+ const binaryPath = path.join(__dirname, "cli", binaryName);
13
+
14
+ if (!fs.existsSync(binaryPath)) {
15
+ console.error(`Error: CLI binary not found at ${binaryPath}`);
16
+ console.error("Please run: npm run build:cli");
17
+ process.exit(1);
18
+ }
19
+
20
+ const { spawn } = require("child_process");
21
+ const args = process.argv.slice(2);
22
+ const child = spawn(binaryPath, args, {
23
+ stdio: "inherit",
24
+ shell: platform === "win32",
25
+ });
26
+
27
+ child.on("exit", (code) => {
28
+ process.exit(code);
29
+ });
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "multi-dc",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Run multiple discord.js bots from separate folders in one Node.js process.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "bin": {
8
- "multi-dc": "./cli/multi-dc"
8
+ "multi-dc": "./cli-wrapper.cjs"
9
9
  },
10
10
  "files": [
11
11
  "dist",
12
- "cli/multi-dc"
12
+ "cli",
13
+ "cli-wrapper.cjs"
13
14
  ],
14
15
  "engines": {
15
16
  "node": ">=18.20.0"
@@ -33,7 +34,6 @@
33
34
  "type": "module",
34
35
  "dependencies": {
35
36
  "discord.js": "^14.19.3",
36
- "multi-dc": "^0.1.0",
37
37
  "tsx": "^4.20.3"
38
38
  },
39
39
  "devDependencies": {