import { SlashCommandBuilder } from "discord.js"; import type { BotCommand } from "./index"; import { botConfig } from "@/bot/config"; import { createDiscordUser, SignupError, validateSignup } from "@/bot/services/signup"; const DM_ONLY_MESSAGE = "This command only works in direct messages."; export const signupCommand: BotCommand = { builder: new SlashCommandBuilder() .setName("signup") .setDescription("Create a Polaris Task Force account linked to your Discord account") .addStringOption((option) => option.setName("displayname").setDescription("Your in-game name").setRequired(true), ) .addStringOption((option) => option .setName("steamid") .setDescription("Your Steam64 ID (17-digit numeric)") .setRequired(true), ) as SlashCommandBuilder, execute: async (interaction, payload) => { if (interaction.inGuild()) { await interaction.reply({ content: DM_ONLY_MESSAGE, ephemeral: true }); return; } const username = interaction.user.username; const discordId = interaction.user.id; const displayName = interaction.options.getString("displayname", true); const steamId = interaction.options.getString("steamid", true); try { await validateSignup(payload, { username, discordId, steamId, displayName }); } catch (error) { if (error instanceof SignupError) { await interaction.reply({ content: error.message, ephemeral: true }); return; } throw error; } const { user, tempPassword } = await createDiscordUser(payload, { username, discordId, displayName, steamId, }); const passwordMessage = [ "Your Polaris Task Force account has been created.", "", `Username: ${user.username}`, `Temporary password: ${tempPassword}`, "", `Log in at ${botConfig.appUrl} and change your password in Account settings.`, ].join("\n"); await interaction.user.send(passwordMessage); await interaction.reply({ content: `Account created for ${user.username}. Your temporary password was sent to this DM.`, ephemeral: true, }); }, };