all repos — stealth-developers @ f848a995c217b0c37ef4591eb802988a808c0e4d

src/interactions/commands/user.ts (view raw)

 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
import {
	type ChatInputCommandInteraction,
	type Client,
	SlashCommandBuilder,
} from "discord.js";

import config from "@/config";
import { buildBansContainer } from "@/utils/bans";
import { hasManagerPermissions } from "@/utils/permissions";
import {
	getUserInfoFromDiscord,
	getUserInfoFromRoblox,
	getUserInfoFromRobloxUsername,
} from "@/utils/userInfo";

const commandData = new SlashCommandBuilder()
	.setName("user")
	.setDescription("get roblox user information")
	.addSubcommand((subcommand) =>
		subcommand
			.setName("discord")
			.setDescription("get roblox info from a discord user")
			.addUserOption((option) =>
				option
					.setName("user")
					.setDescription("the discord user to look up")
					.setRequired(true),
			),
	)
	.addSubcommand((subcommand) =>
		subcommand
			.setName("roblox")
			.setDescription("get roblox info from a user id or username")
			.addStringOption((option) =>
				option
					.setName("input")
					.setDescription("the roblox user id or username to look up")
					.setRequired(true),
			),
	);

async function execute(
	_client: Client,
	interaction: ChatInputCommandInteraction,
) {
	const subcommand = interaction.options.getSubcommand();

	await interaction.deferReply();

	let result: Awaited<ReturnType<typeof getUserInfoFromDiscord>>;
	if (!interaction.member) {
		await interaction.editReply({
			content: "❌ you must be in a server to use this command.",
		});
		return;
	}

	if (subcommand === "discord") {
		const discordUser = interaction.options.getUser("user", true);
		result = await getUserInfoFromDiscord(discordUser.id, interaction.member);
	} else if (subcommand === "roblox") {
		const input = interaction.options.getString("input", true);

		if (/^\d+$/.test(input)) {
			result = await getUserInfoFromRoblox(input, interaction.member);
		} else {
			result = await getUserInfoFromRobloxUsername(input, interaction.member);
		}
	} else {
		await interaction.editReply({
			content: "❌ unknown subcommand.",
		});
		return;
	}

	if ("error" in result) {
		await interaction.editReply({
			content: `❌ ${result.error}`,
		});
		return;
	}

	await interaction.editReply({
		flags: ["IsComponentsV2"],
		components: [...result.containers, ...result.actionRows],
	});
	await interaction.followUp({
		content: result.user.id,
	});
}

export default {
	enabled: config.data.roblox?.apiKey && (config.data.bloxlink?.token || true),
	data: commandData,
	execute,
};