forked from SokoraDesu/Sokora
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Chiissu/setup
Add setup command
- Loading branch information
Showing
4 changed files
with
54 additions
and
5 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
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); |
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 |
---|---|---|
@@ -1 +1 @@ | ||
TOKEN="YOURTOKEN" # The bot token found in the Discord Developer portal | ||
TOKEN="YOURTOKEN" |
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