all repos — stealth-developers @ d816a1cab318fbc6d5205897c2902c49574710fa

src/interactions/menus/getInfo.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
import {
	type ActionRow,
	ApplicationCommandType,
	ButtonBuilder,
	type ButtonComponent,
	ButtonStyle,
	type Client,
	ContextMenuCommandBuilder,
	EmbedBuilder,
	type UserContextMenuCommandInteraction,
} from "discord.js";

import config from "@/config";
import type { GetUserResponse } from "@/types/roblox";
import { getConnectedRobloxUser, getRobloxUser } from "@/utils/roblox";
import { ActionRowBuilder } from "discord.js";

const commandData = new ContextMenuCommandBuilder()
	.setName("get account")
	.setType(ApplicationCommandType.User);

async function execute(
	_client: Client,
	interaction: UserContextMenuCommandInteraction,
) {
	const connectedAccount = await getConnectedRobloxUser(interaction.user.id);
	if ("error" in connectedAccount)
		return interaction.reply({
			content: `error: ${connectedAccount.error}`,
		});

	const { user, thumbnail } = await getRobloxUser(connectedAccount.robloxID);
	const createdAt = new Date(user.createTime);
	const timestamp = Math.floor(createdAt.getTime() / 1000);

	const embed = new EmbedBuilder()
		.setAuthor({
			name: user.displayName,
			url: `https://www.roblox.com/users/${user.id}/profile`,
		})
		.setThumbnail(thumbnail.done ? thumbnail.response.imageUri : "")
		.setDescription(user.about || null)
		.addFields(
			{
				name: "id",
				value: user.id,
			},
			{
				name: "username",
				value: user.name,
			},
			{
				name: "created",
				value: `<t:${timestamp}> (<t:${timestamp}:R>)`,
			},
		)
		.setColor(0x00aaff);

	const buttonRow = new ActionRowBuilder().addComponents(
		new ButtonBuilder()
			.setURL(`https://www.roblox.com/users/${user.id}/profile`)
			.setLabel("view profile")
			.setStyle(ButtonStyle.Link),
	) as unknown as ActionRow<ButtonComponent>;

	await interaction.reply({
		embeds: [embed],
		components: [buttonRow],
	});
}

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