Skip to content

Commit

Permalink
Merge pull request #6 from Chiissu/setup
Browse files Browse the repository at this point in the history
Add setup command
  • Loading branch information
MrSerge01 authored Nov 3, 2024
2 parents 190b53c + a121ff4 commit 2661b56
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
6 changes: 2 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Get started with contributing
### Getting the code
- Make a fork of this repository.
- Make a fork of this repository.
- Clone your fork.

### Creating your bot
Expand All @@ -15,11 +15,9 @@
- Reset and then copy your bot's token.

### Setting up .env
- Copy the `example.env` file.
- Paste it into a `.env` file and replace the token with your own.
- Run `bun run setup` and our cli tool will install dependencies and write .env for you

### Running
- Run `bun i` to install all the dependencies needed by the bot.
- Run `bun start`.

Be sure to open a pull request when you're ready to push your changes. Be descriptive of the changes you've made.
Expand Down
50 changes: 50 additions & 0 deletions cli/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as fs from "fs";
import { createInterface } from "readline";

const readHiddenInput = async (prompt: string): Promise<string> => {
console.log(prompt);

return new Promise(resolve => {
const rl = createInterface({
input: process.stdin,
output: process.stdout
});

const stdin = process.stdin;
if (stdin.isTTY) stdin.setRawMode(true);

stdin.on("data", data => {
if (data.toString() === "\n" || data.toString() === "\r") {
if (stdin.isTTY) stdin.setRawMode(false);
process.stdout.moveCursor(0, -1);
process.stdout.clearLine(1);
rl.close();
}
});

rl.question("", input => {
resolve(input);
});
});
};

const replaceTokenInEnv = (token: string) => {
try {
const envContent = fs.readFileSync(".env", "utf-8");
const updatedContent = envContent.replace("YOURTOKEN", token);
fs.writeFileSync(".env", updatedContent, "utf-8");
console.log("You're good to go, happy coding!");
} catch (error) {
console.error("Error updating .env file:", error);
}
};

const main = async () => {
fs.copyFileSync("example.env", ".env");
const token = await readHiddenInput(
"Paste your token below: (you can get one from https://discord.com/developers/applications)"
);
replaceTokenInEnv(token);
};

main().catch(console.error);
2 changes: 1 addition & 1 deletion example.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
TOKEN="YOURTOKEN" # The bot token found in the Discord Developer portal
TOKEN="YOURTOKEN"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"main": "./src/index.ts",
"type": "module",
"scripts": {
"setup": "bun i && bun run cli/setup.ts",
"start": "bun ./src/index.ts"
},
"dependencies": {
Expand Down

0 comments on commit 2661b56

Please sign in to comment.