all repos — stealth-developers @ a4bdd5e092079955436c1a4fb903b979730015f5

src/utils/robloxUser.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
import { isApiErrorV2, roblox } from "@/roblox/client";
import type { RobloxUserId } from "@/roblox/types";
import {
	constructBansSummaryContainer,
	constructUserContainer,
	getBans,
} from "@/utils/profile";
import type {
	ChatInputCommandInteraction,
	MessageContextMenuCommandInteraction,
} from "discord.js";

export async function processRobloxUserInteraction(
	interaction:
		| ChatInputCommandInteraction
		| MessageContextMenuCommandInteraction,
	id: RobloxUserId,
	isModerator: boolean,
) {
	try {
		await interaction.editReply(`Fetching user with ID ${id}...`);
		const [userRes, userErr] = await roblox.getUser(id);
		if (userErr) {
			if (isApiErrorV2(userErr)) {
				await interaction.editReply(
					`There was an error fetching the user: ${userErr.message}`,
				);
			} else {
				await interaction.editReply("There was an error fetching the user.");
			}
			return;
		}
		const user = userRes;

		await interaction.editReply(
			`Found user with username ${user.name}, fetching thumbnail...`,
		);
		const [thumbnailRes] = await roblox.getThumbnail(id, { shape: "SQUARE" });
		const thumbnailUri = thumbnailRes ? thumbnailRes.response.imageUri : null;

		const randomMessages = [
			"grok is this true",
			"<:swagong:1176858666452922469>",
			"awawawawawawawawawawwaawawawwa",
			"<:wawa:1158423817698430977>",
			"<:max:1476776753845370991>",
			"<:snickerdoodle:1477173429575749716>",
		];
		const message =
			randomMessages[Math.floor(Math.random() * randomMessages.length)];
		await interaction.editReply(message);

		const bans = await getBans(id);

		const { mainContainer } = await constructUserContainer(user, {
			thumbnailUri,
			bans: bans.flat(),
			showPrivate: isModerator,
			originCommand: interaction.commandName,
		});

		await interaction.editReply(user.id);
		await interaction.followUp({
			flags: ["IsComponentsV2"],
			components: [mainContainer],
		});
	} catch (err) {
		console.error(err);
		await interaction.editReply(
			"An unexpected error occurred while fetching the user.",
		);
	}
}