src/interactions/commands/roblox/banHistory.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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
import {
type ButtonInteraction,
type ChatInputCommandInteraction,
type Client,
type GuildMember,
SlashCommandBuilder,
} from "discord.js";
import config from "@/config";
import { isApiErrorV2, roblox } from "@/roblox/client";
import {
constructBansContainer,
constructBansSummaryContainer,
constructUserContainer,
} from "@/roblox/profile";
import type { RobloxUserId } from "@/roblox/types";
import { hasManagerPermissions } from "@/utils/discord/permissions";
const commandData = new SlashCommandBuilder()
.setName("ban-history")
.setDescription(
`Get a user's ban history in the selected ${config.terminology}`,
)
.addSubcommand((subcommand) =>
subcommand
.setName("discord")
.setDescription("Use Bloxlink to get Roblox info from a Discord user")
.addUserOption((option) =>
option
.setName("user")
.setDescription("The Discord user to look up")
.setRequired(true),
)
.addStringOption((option) =>
option
.setName(config.terminology)
.setDescription(`The ${config.terminology} to filter by (optional)`)
.addChoices(
...Object.values(config.projects).map((project) => ({
name: project.displayName,
value: project.name,
})),
)
.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 username to lookup - prefix with id: for IDs",
)
.setRequired(true),
)
.addStringOption((option) =>
option
.setName(config.terminology)
.setDescription(`The ${config.terminology} to filter by (optional)`)
.addChoices(
...Object.entries(config.projects).map(([projectKey, project]) => ({
name: project.displayName,
value: projectKey,
})),
)
.setRequired(true),
),
);
async function execute(
_client: Client,
interaction: ChatInputCommandInteraction,
) {
const subcommand = interaction.options.getSubcommand();
const projectKey = interaction.options.getString(
config.terminology,
true,
) as keyof typeof config.projects;
const project = config.projects[projectKey];
const universeId = project.universe;
const isModerator = await hasManagerPermissions(
interaction.member as GuildMember,
);
await interaction.deferReply();
try {
let id: RobloxUserId;
if (subcommand === "discord") {
const target = interaction.options.getUser("user", true);
const [linkedRes, linkedErr] = await roblox.getLinkedAccount(target.id);
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;
}
id = linkedRes.robloxID;
} else {
const input = interaction.options.getString("input", true);
const isId = input.startsWith("id:");
if (isId) {
id = input.slice(3);
if (!id) {
await interaction.editReply("Invalid ID provided.");
return;
}
} else {
const [usersRes] = await roblox.getUsersByUsernames([input]);
if (!usersRes || !usersRes.data || usersRes.data.length === 0) {
await interaction.editReply("User not found");
return;
}
id = usersRes.data[0].id;
}
}
await interaction.editReply(`Fetching user with ID ${id}...`);
const [user, 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;
}
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 { mainContainer } = await constructUserContainer(user, {
thumbnailUri,
});
const [bansRes] = await roblox.getUserRestrictionLogs(universeId, id);
const bans = bansRes ?? null;
const { container: bansContainer } = await constructBansContainer(bans, {
showPrivate: isModerator,
});
await interaction.editReply(user.id);
await interaction.followUp({
flags: ["IsComponentsV2"],
components: [mainContainer, bansContainer],
});
} catch (err) {
console.error(err);
await interaction.editReply(
"An unexpected error occurred while fetching the user.",
);
}
}
async function buttonExecute(_client: Client, interaction: ButtonInteraction) {
const [, action, userId] = interaction.customId.split(":");
const isModerator = await hasManagerPermissions(
interaction.member as GuildMember,
);
const { container } = await constructBansSummaryContainer(userId, {
showPrivate: isModerator,
});
await interaction.reply({
components: [container],
flags: ["IsComponentsV2"],
});
}
export default {
data: commandData,
buttonExecute,
execute,
};
|