-
Notifications
You must be signed in to change notification settings - Fork 735
/
Copy pathsetup.js
147 lines (132 loc) · 5.04 KB
/
setup.js
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
const readline = require("readline");
const fs = require("fs");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
function generateEnvFile () {
console.log("Welcome to the Strange Bot setup!\n");
console.log(
"Here are some tutorials to get you started:\nMongoDB connection URL: https://www.youtube.com/watch?v=nv38zCeFBHg\nBot Token: https://www.youtube.com/watch?v=aI4OmIbkJH8\nWebhook URL: https://www.youtube.com/watch?v=fKksxz2Gdnc\nBot Secret: https://support.heateor.com/discord-client-id-discord-client-secret/\nWeatherstack API Key: https://weatherstack.com/signup/free\nStrange API Key: https://strangeapi.hostz.me/dashboard\nSpotify Client ID and Secret: https://www.youtube.com/watch?v=WHugvJ0YR5I\n"
);
console.log("Please provide the following information (* means required) - right click in the console to paste:\n");
let envData = {};
function askDatabaseUrl () {
rl.question("Enter your MongoDB connection URL*: ", (dbUrl) => {
const mongoUrlRegex = /^mongodb\+srv:\/\//;
if (mongoUrlRegex.test(dbUrl)) {
envData["MONGO_CONNECTION"] = dbUrl;
askBotToken();
} else {
console.log("Invalid MongoDB URL format. Please enter a valid MongoDB URL. Tutorials are above.");
askDatabaseUrl();
}
});
}
function askBotToken () {
rl.question("Enter your bot token*: ", (botToken) => {
if (botToken.trim().length >= 40) {
envData["BOT_TOKEN"] = botToken;
askWebhookErrors();
} else {
console.log("Invalid bot token. Please enter a valid token. Tutorials are above.");
askBotToken();
}
});
}
function askWebhookErrors () {
rl.question("Enter the Webhook URL for error logs: ", (errLogs) => {
const webhookUrlRegex = /^https:\/\/discord\.com\/api\/webhooks/;
if (webhookUrlRegex.test(errLogs)) {
envData["ERROR_LOGS"] = errLogs;
askWebhookJoinLeave();
} else {
console.log("Invalid Webhook URL format. Please enter a valid Webhook URL. Tutorials are above.");
askWebhookErrors();
}
});
}
function askWebhookJoinLeave () {
rl.question("Enter the Webhook URL for join/leave logs: ", (joinLeaveLogs) => {
const webhookUrlRegex = /^https:\/\/discord\.com\/api\/webhooks/;
if (webhookUrlRegex.test(joinLeaveLogs)) {
envData["JOIN_LEAVE_LOGS"] = joinLeaveLogs;
askBotSecret();
} else {
console.log("Invalid Webhook URL format. Please enter a valid Webhook URL. Tutorials are above.");
askWebhookJoinLeave();
}
});
}
function askBotSecret () {
rl.question("Enter your bot secret - Required for dashboard: ", (botSecret) => {
if (botSecret.trim().length >= 20) {
envData["BOT_SECRET"] = botSecret;
askWeatherstackApiKey();
} else {
console.log("Bot secret is not valid. Please enter a valid secret. Tutorials are above.");
askBotSecret();
}
});
}
function askWeatherstackApiKey () {
rl.question("Enter your Weatherstack API key - Required for Weather Command: ", (weatherStackKey) => {
if (weatherStackKey.trim().length >= 20) {
envData["WEATHERSTACK_KEY"] = weatherStackKey;
askStrangeApiKey();
} else {
console.log("Weatherstack API key is not valid. Please enter a valid key. Tutorials are above.");
askWeatherstackApiKey();
}
});
}
function askStrangeApiKey () {
rl.question("Enter your Strange API key - Required for image commands: ", (strangeApiKey) => {
if (strangeApiKey.trim().length >= 30) {
envData["STRANGE_API_KEY"] = strangeApiKey;
askSpotifyClientId();
} else {
console.log("Strange API key must be valid. Please enter a valid key. Tutorials are above.");
askStrangeApiKey();
}
});
}
function askSpotifyClientId () {
rl.question("Enter your Spotify Client ID - Required for Spotify Support: ", (spotifyClientId) => {
if (spotifyClientId.trim().length >= 25) {
envData["SPOTIFY_CLIENT_ID"] = spotifyClientId;
askSpotifyClientSecret();
} else {
console.log(
"Spotify Client ID must be at least 25 characters long. Please enter a valid ID. Tutorials are above."
);
askSpotifyClientId();
}
});
}
function askSpotifyClientSecret () {
rl.question("Enter your Spotify Client Secret - Required for Spotify Support: ", (spotifyClientSecret) => {
if (spotifyClientSecret.trim().length >= 25) {
envData["SPOTIFY_CLIENT_SECRET"] = spotifyClientSecret;
writeEnvFile();
} else {
console.log("Spotify Client Secret is not valid. Please enter a valid Secret. Tutorials are above.");
askSpotifyClientSecret();
}
});
}
function writeEnvFile () {
fs.writeFileSync(
".env",
Object.entries(envData)
.map(([key, value]) => `${key}=${value}`)
.join("\n")
);
console.log("Setup success!");
rl.close();
}
askDatabaseUrl();
}
module.exports = {
generateEnvFile,
};