summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-12-28 20:42:37 -0800
committerFuwn <[email protected]>2025-12-28 20:42:37 -0800
commit37cfc0d6407ba5a2a1ea8ec2526b1e8c241129f8 (patch)
treeaa1e21ed73159656c427729aac8f1b95480f8bc5
parentfeat(interactions:server): Support role slash command in Tracen Academy (diff)
downloadumabotdiscord-37cfc0d6407ba5a2a1ea8ec2526b1e8c241129f8.tar.xz
umabotdiscord-37cfc0d6407ba5a2a1ea8ec2526b1e8c241129f8.zip
feat(interactions:server): Add Ambassador role to role slash command
-rw-r--r--packages/interactions/server.ts69
1 files changed, 35 insertions, 34 deletions
diff --git a/packages/interactions/server.ts b/packages/interactions/server.ts
index e2794f4..0c33d95 100644
--- a/packages/interactions/server.ts
+++ b/packages/interactions/server.ts
@@ -68,6 +68,7 @@ const ALLOWED_ROLE_IDS: readonly string[] = [
"1423213971422580736", // Privileged Access
"1410333831281643630", // Art & Media NSFW
"1418391675050528879", // Roleplay NSFW
+ "1410328679392743476", // Ambassador
// Tracen Academy
"1434710765604049027", // Certified Trainer
@@ -77,7 +78,7 @@ const ALLOWED_ROLE_IDS: readonly string[] = [
const sendComplaintToChannel = async (
environment: Environment,
- embed: DiscordEmbed,
+ embed: DiscordEmbed
): Promise<boolean> => {
const url = `https://discord.com/api/v10/channels/${COMPLAINT_CHANNEL_ID}/messages`;
@@ -103,7 +104,7 @@ const sendComplaintToChannel = async (
const sendAppealToChannel = async (
environment: Environment,
- embed: DiscordEmbed,
+ embed: DiscordEmbed
): Promise<boolean> => {
const url = `https://discord.com/api/v10/channels/${APPEAL_CHANNEL_ID}/messages`;
@@ -129,7 +130,7 @@ const sendAppealToChannel = async (
const fetchRoleDistribution = async (
environment: Environment,
- guildID: string,
+ guildID: string
): Promise<Array<{ name: string; count: number }>> => {
const roleData: Array<{ name: string; count: number }> = [];
@@ -140,14 +141,14 @@ const fetchRoleDistribution = async (
headers: {
Authorization: `Bot ${environment.DISCORD_TOKEN}`,
},
- },
+ }
);
if (!guildResponse.ok) {
console.error(
"Failed to fetch guild data:",
guildResponse.status,
- guildResponse.statusText,
+ guildResponse.statusText
);
const errorText = await guildResponse.text();
@@ -184,23 +185,23 @@ const fetchRoleDistribution = async (
headers: {
Authorization: `Bot ${environment.DISCORD_TOKEN}`,
},
- },
+ }
);
if (membersResponse.status === 429) {
const retryAfter = membersResponse.headers.get("Retry-After");
const resetAfter = membersResponse.headers.get(
- "X-RateLimit-Reset-After",
+ "X-RateLimit-Reset-After"
);
const scope = membersResponse.headers.get("X-RateLimit-Scope");
console.log(
- `Rate limited! Scope: ${scope}, Retry-After: ${retryAfter}, Reset-After: ${resetAfter}`,
+ `Rate limited! Scope: ${scope}, Retry-After: ${retryAfter}, Reset-After: ${resetAfter}`
);
const delayMs = Math.max(
retryAfter ? parseFloat(retryAfter) * 1000 : 0,
- resetAfter ? parseFloat(resetAfter) * 1000 : 0,
+ resetAfter ? parseFloat(resetAfter) * 1000 : 0
);
if (delayMs > 0) {
@@ -216,7 +217,7 @@ const fetchRoleDistribution = async (
console.error(
"Failed to fetch members:",
membersResponse.status,
- membersResponse.statusText,
+ membersResponse.statusText
);
const errorText = await membersResponse.text();
@@ -233,7 +234,7 @@ const fetchRoleDistribution = async (
console.log(`Rate limit bucket empty, waiting ${resetAfter}s...`);
await new Promise((resolve) =>
- setTimeout(resolve, parseFloat(resetAfter) * 1000),
+ setTimeout(resolve, parseFloat(resetAfter) * 1000)
);
}
@@ -269,7 +270,7 @@ router.get("/", (_request: Request, environment: Environment) => {
router.post("/", async (request: Request, environment: Environment) => {
const { isValid, interaction } = await server.verifyDiscordRequest(
request,
- environment,
+ environment
);
if (!isValid || !interaction)
@@ -419,11 +420,11 @@ router.post("/", async (request: Request, environment: Environment) => {
complaintMessage,
complainant,
Date.now(),
- isDM,
+ isDM
);
const success = await sendComplaintToChannel(
environment,
- complaintEmbed,
+ complaintEmbed
);
if (success) {
@@ -485,7 +486,7 @@ router.post("/", async (request: Request, environment: Environment) => {
appealMessage,
appellant,
Date.now(),
- isDM,
+ isDM
);
const success = await sendAppealToChannel(environment, appealEmbed);
@@ -534,7 +535,7 @@ router.post("/", async (request: Request, environment: Environment) => {
const roleDistribution = await fetchRoleDistribution(
environment,
- CENTRAL_GUILD_ID,
+ CENTRAL_GUILD_ID
);
if (roleDistribution.length === 0)
@@ -605,7 +606,7 @@ router.post("/", async (request: Request, environment: Environment) => {
headers: {
Authorization: `Bot ${environment.DISCORD_TOKEN}`,
},
- },
+ }
);
if (!guild.ok)
@@ -654,7 +655,7 @@ router.post("/", async (request: Request, environment: Environment) => {
});
newRoles = newRoles.filter(
- (roleId) => roleId !== VERIFIED_ROLEPLAY_ROLE_ID,
+ (roleId) => roleId !== VERIFIED_ROLEPLAY_ROLE_ID
);
actionTaken = "removed";
@@ -663,7 +664,7 @@ router.post("/", async (request: Request, environment: Environment) => {
case "toggle":
if (hasRole) {
newRoles = newRoles.filter(
- (roleId) => roleId !== VERIFIED_ROLEPLAY_ROLE_ID,
+ (roleId) => roleId !== VERIFIED_ROLEPLAY_ROLE_ID
);
actionTaken = "removed";
} else {
@@ -696,13 +697,13 @@ router.post("/", async (request: Request, environment: Environment) => {
body: JSON.stringify({
roles: newRoles,
}),
- },
+ }
);
if (!updateResponse.ok) {
console.error(
"Failed to update user roles:",
- await updateResponse.text(),
+ await updateResponse.text()
);
return new JSONResponse({
@@ -740,7 +741,7 @@ router.post("/", async (request: Request, environment: Environment) => {
const hasAdminPermission =
member?.permissions && (parseInt(member.permissions) & 0x8) === 0x8;
const hasStaffRole = member?.roles?.some((roleId) =>
- CENTRAL_STAFF_ROLES.includes(roleId as any),
+ CENTRAL_STAFF_ROLES.includes(roleId as any)
);
if (!hasAdminPermission && !hasStaffRole)
@@ -770,7 +771,7 @@ router.post("/", async (request: Request, environment: Environment) => {
headers: {
Authorization: `Bot ${environment.DISCORD_TOKEN}`,
},
- },
+ }
);
if (!guild.ok)
@@ -786,13 +787,13 @@ router.post("/", async (request: Request, environment: Environment) => {
const targetMember = await guild.json();
const currentRoles = targetMember.roles || [];
const hasRole = currentRoles.includes(
- CENTRAL_PRIVILEGED_ACCESS_ROLE_ID,
+ CENTRAL_PRIVILEGED_ACCESS_ROLE_ID
);
let newRoles = [...currentRoles];
if (hasRole) {
newRoles = newRoles.filter(
- (roleId) => roleId !== CENTRAL_PRIVILEGED_ACCESS_ROLE_ID,
+ (roleId) => roleId !== CENTRAL_PRIVILEGED_ACCESS_ROLE_ID
);
} else {
newRoles.push(CENTRAL_PRIVILEGED_ACCESS_ROLE_ID);
@@ -809,13 +810,13 @@ router.post("/", async (request: Request, environment: Environment) => {
body: JSON.stringify({
roles: newRoles,
}),
- },
+ }
);
if (!updateResponse.ok) {
console.error(
"Failed to update user roles:",
- await updateResponse.text(),
+ await updateResponse.text()
);
return new JSONResponse({
@@ -857,8 +858,8 @@ router.post("/", async (request: Request, environment: Environment) => {
const hasOwnerRole = member?.roles?.includes(OWNER_ROLE_ID);
const hasAdministratorRole = member?.roles?.some((roleId) =>
[ADMINISTRATOR_ROLE_ID, ROLEPLAY_ADMINISTRATOR_ROLE_ID].includes(
- roleId as any,
- ),
+ roleId as any
+ )
);
if (!hasAdminPermission && !hasOwnerRole && !hasAdministratorRole)
@@ -881,10 +882,10 @@ router.post("/", async (request: Request, environment: Environment) => {
});
const targetUserID = interaction.data.options?.find(
- (option) => option.name === "user",
+ (option) => option.name === "user"
)?.value as string;
const targetRoleID = interaction.data.options?.find(
- (option) => option.name === "role",
+ (option) => option.name === "role"
)?.value as string;
if (!targetUserID || !targetRoleID)
@@ -913,7 +914,7 @@ router.post("/", async (request: Request, environment: Environment) => {
headers: {
Authorization: `Bot ${environment.DISCORD_TOKEN}`,
},
- },
+ }
);
if (!guild.ok)
@@ -944,7 +945,7 @@ router.post("/", async (request: Request, environment: Environment) => {
body: JSON.stringify({
roles: newRoles,
}),
- },
+ }
);
if (!updateResponse.ok) {
@@ -953,7 +954,7 @@ router.post("/", async (request: Request, environment: Environment) => {
console.error(
"Error updating member roles:",
updateResponse.status,
- errorText,
+ errorText
);
return new JSONResponse({