TravBot-v3/src/modules/setup.ts

74 lines
2.2 KiB
TypeScript
Raw Normal View History

import {existsSync as exists} from "fs";
2020-12-15 01:44:28 +00:00
import inquirer from "inquirer";
import Storage from "./storage";
import {Config} from "../structures";
// 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
];
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() {
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
}
};