all repos — stealth-developers @ 13b0369f9ad6065bdfc782fd9e3938348c651ece

src/interactions/commands/roblox/searchUsers.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
import { roblox } from "@/roblox/client";
import { text } from "@/utils/discord/components";
import {
	type ChatInputCommandInteraction,
	type Client,
	ContainerBuilder,
	SlashCommandBuilder,
} from "discord.js";

const commandData = new SlashCommandBuilder()
	.setName("search")
	.setDescription("Search for Roblox users")
	.addStringOption((option) =>
		option
			.setName("query")
			.setDescription("The query to search for")
			.setRequired(true),
	);

async function execute(
	_client: Client,
	interaction: ChatInputCommandInteraction,
) {
	await interaction.deferReply();
	const query = interaction.options.getString("query", true);

	const [searchRes, searchErr] = await roblox.searchUsers(query, {
		limit: 10,
		cursor: "",
	});
	if (searchErr) {
		await interaction.editReply("Error searching for users.");
		console.error(searchErr);
		return;
	}

	const container = new ContainerBuilder();

	const title = text(`## ${searchRes.data.length} Results for "${query}"`);

	const resultString = searchRes.data
		.map((user) =>
			[
				"*",
				user.displayName,
				`[@${user.name}](https://www.roblox.com/users/${user.id}/profile)`,
				`(${user.id})`,
				user.previousUsernames.length
					? `(${user.previousUsernames.join(", ")})`
					: "",
			].join(" "),
		)
		.join("\n");
	const resultText = text(resultString);

	container.addTextDisplayComponents(title, resultText);

	await interaction.editReply({
		flags: ["IsComponentsV2"],
		components: [container],
	});
}

export default {
	data: commandData,
	execute,
};