all repos — stealth-developers @ 103b51d2a555d6d158d8806791b6ec07ac30c3d1

src/interactions/menus/getUser.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
import { roblox } from "@/roblox/client";
import { processRobloxUserInteraction } from "@/roblox/robloxUser";
import type { RobloxUserId } from "@/roblox/types";
import { hasManagerPermissions } from "@/utils/discord/permissions";
import {
	ApplicationCommandType,
	type Client,
	ContextMenuCommandBuilder,
	type GuildMember,
	type MessageContextMenuCommandInteraction,
} from "discord.js";

const commandData = new ContextMenuCommandBuilder()
	.setName("Get Roblox Account")
	.setType(ApplicationCommandType.User);

async function execute(
	_client: Client,
	interaction: MessageContextMenuCommandInteraction,
) {
	const isModerator = await hasManagerPermissions(
		interaction.member as GuildMember,
	);
	await interaction.deferReply();

	const target = interaction.targetId;
	const [linkedRes, linkedErr] = await roblox.getLinkedAccount(target);

	if (linkedErr) {
		const message = linkedErr.error;
		if (message === "User not found") {
			await interaction.editReply(
				"No linked Roblox account found for that user.",
			);
			return;
		}
		await interaction.editReply(
			`There was an error fetching the linked account: ${linkedErr.error}`,
		);
		return;
	}

	const id: RobloxUserId = linkedRes.robloxID;
	await processRobloxUserInteraction(interaction, id, isModerator);
}

export default {
	data: commandData,
	execute,
};