constatic
Version:
Constatic is a CLI for creating and managing modern TypeScript projects, providing an organized structure and features that streamline development.
35 lines (34 loc) • 1.2 kB
JavaScript
// src/menus/main/presets/tokens/actions/prompt.ts
import { uiMessage } from "#helpers";
import { withDefaults } from "../../../../../helpers/prompts.js";
import { fetchDiscordTokenData } from "#shared/tokens.js";
import { password } from "@inquirer/prompts";
import ck from "chalk";
import { Result } from "#lib/result.js";
async function promptToken(tokens) {
const token = await password(withDefaults({
message: uiMessage({
"en-US": "Insert your discord bot token",
"pt-BR": "Insira seu token de bot de discord"
}),
validate(value) {
const message = uiMessage({
"en-US": "You need to provide the token for your bot application.",
"pt-BR": "É necessário informar o token da sua aplicação de bot"
});
return !value ? message : true;
}
}));
const existing = tokens.find((t) => t.token === token);
if (existing) {
const name = `\uD83E\uDD16 ${ck.yellow.underline(existing.name)}`;
return Result.fail(uiMessage({
"en-US": `This token is already saved! ${name}`,
"pt-BR": `Este token já está salvo! ${name}`
}, ck.red));
}
return await fetchDiscordTokenData(token);
}
export {
promptToken
};