2021-04-13 12:38:52 +00:00
|
|
|
import {existsSync as exists} from "fs";
|
2020-12-15 01:44:28 +00:00
|
|
|
import inquirer from "inquirer";
|
2021-04-13 12:38:52 +00:00
|
|
|
import Storage from "./storage";
|
2021-04-05 04:35:12 +00:00
|
|
|
import {Config} from "../structures";
|
2020-07-25 08:15:26 +00:00
|
|
|
|
|
|
|
// This file is called (or at least should be called) automatically as long as a config file doesn't exist yet.
|
|
|
|
// And that file won't be written until the data is successfully initialized.
|
2020-10-15 09:23:24 +00:00
|
|
|
const prompts = [
|
2020-12-15 01:44:28 +00:00
|
|
|
{
|
|
|
|
type: "password",
|
|
|
|
name: "token",
|
|
|
|
message: "What's your bot's token?",
|
|
|
|
mask: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "input",
|
|
|
|
name: "prefix",
|
|
|
|
message: "What do you want your bot's prefix to be?",
|
|
|
|
default: "$"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "input",
|
|
|
|
name: "owner",
|
|
|
|
message: "Enter the owner's user ID here."
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "input",
|
|
|
|
name: "admins",
|
2020-12-15 07:56:09 +00:00
|
|
|
message: "Enter a list of bot admins (by their IDs) separated by spaces."
|
2020-12-15 01:44:28 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "input",
|
|
|
|
name: "support",
|
2020-12-15 07:56:09 +00:00
|
|
|
message: "Enter a list of bot troubleshooters (by their IDs) separated by spaces."
|
2020-12-15 01:44:28 +00:00
|
|
|
}
|
2020-10-15 09:23:24 +00:00
|
|
|
];
|
2020-07-25 08:15:26 +00:00
|
|
|
|
|
|
|
export default {
|
2020-12-15 01:44:28 +00:00
|
|
|
async init() {
|
|
|
|
while (!exists("data/config.json")) {
|
|
|
|
const answers = await inquirer.prompt(prompts);
|
|
|
|
Storage.open("data");
|
|
|
|
Config.token = answers.token as string;
|
|
|
|
Config.prefix = answers.prefix as string;
|
|
|
|
Config.owner = answers.owner as string;
|
|
|
|
const admins = answers.admins as string;
|
|
|
|
Config.admins = admins !== "" ? admins.split(" ") : [];
|
|
|
|
const support = answers.support as string;
|
|
|
|
Config.support = support !== "" ? support.split(" ") : [];
|
|
|
|
Config.save(false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/** Prompt the user to set their token again. */
|
|
|
|
async again() {
|
2021-03-30 08:58:21 +00:00
|
|
|
console.error("It seems that the token you provided is invalid.");
|
|
|
|
|
|
|
|
// Deactivate the console //
|
|
|
|
const oldConsole = console;
|
|
|
|
console = {
|
|
|
|
...oldConsole,
|
|
|
|
log() {},
|
|
|
|
warn() {},
|
|
|
|
error() {},
|
|
|
|
debug() {},
|
|
|
|
ready() {}
|
|
|
|
};
|
|
|
|
|
2020-12-15 01:44:28 +00:00
|
|
|
const answers = await inquirer.prompt(prompts.slice(0, 1));
|
|
|
|
Config.token = answers.token as string;
|
|
|
|
Config.save(false);
|
|
|
|
process.exit();
|
2020-10-15 09:23:24 +00:00
|
|
|
}
|
|
|
|
};
|