snapshot rollout phase 1

This commit is contained in:
DeSqBlocki
2026-08-27 18:52:56 +02:00
parent 6a519f3a2d
commit c2ac7737c0
8 changed files with 595 additions and 171 deletions
+38 -151
View File
@@ -1,118 +1,46 @@
const {
PermissionFlagsBits,
MessageFlags
} = require(
"discord.js"
);
} = require("discord.js");
/*
* ============================================================
* CONFIG
* ============================================================
*
* .env:
*
* BOT_AUTHOR_ID=123456789012345678
*
* Do not hard-code the author ID into commands.
*/
function getBotAuthorId() {
return (
process.env.BOT_AUTHOR_ID
??
null
);
return process.env.BOT_AUTHOR_ID ?? null;
}
/*
* ============================================================
* BOT AUTHOR
* ============================================================
*/
function isBotAuthor(
userId
) {
const authorId =
getBotAuthorId();
if (
!authorId
||
!userId
) {
return false;
}
return (
String(
userId
)
===
String(
authorId
)
return Boolean(
authorId &&
userId &&
String(userId) === String(authorId)
);
}
/*
* ============================================================
* GUILD ADMINISTRATOR
* ============================================================
*/
function isAdministrator(
interaction
) {
if (
!interaction
return (
interaction
?.memberPermissions
) {
return false;
}
return interaction
.memberPermissions
.has(
PermissionFlagsBits.Administrator
);
?.has(
PermissionFlagsBits.Administrator
)
??
false
);
}
/*
* ============================================================
* ADMIN COMMAND ACCESS
* ============================================================
*
* Access is granted when:
*
* - the user is the configured bot author
* OR
* - the user has Discord Administrator
*
* Bot author is checked first so the owner can use admin
* utilities even without Discord Administrator in the guild.
*/
function canUseAdminCommands(
interaction
) {
if (
!interaction
?.user
?.id
) {
return false;
}
return (
isBotAuthor(
interaction.user.id
@@ -125,57 +53,6 @@ function canUseAdminCommands(
}
/*
* ============================================================
* STANDARD ACCESS DENIAL
* ============================================================
*
* Administrative access failures are intentionally ephemeral.
*/
async function denyAdminAccess(
interaction,
message =
"You don't have permission to use this command."
) {
const payload = {
content:
message,
flags:
MessageFlags.Ephemeral
};
if (
interaction.replied
||
interaction.deferred
) {
return interaction.followUp(
payload
);
}
return interaction.reply(
payload
);
}
/*
* ============================================================
* REQUIRE ADMIN ACCESS
* ============================================================
*
* Convenience helper:
*
* if (!await requireAdminAccess(interaction)) {
* return;
* }
*/
async function requireAdminAccess(
interaction
) {
@@ -188,29 +65,39 @@ async function requireAdminAccess(
}
await denyAdminAccess(
interaction
);
const payload = {
content:
"You don't have permission to use this command.",
flags:
MessageFlags.Ephemeral
};
if (
interaction.replied ||
interaction.deferred
) {
await interaction.followUp(
payload
);
}
else {
await interaction.reply(
payload
);
}
return false;
}
/*
* ============================================================
* EXPORTS
* ============================================================
*/
module.exports = {
getBotAuthorId,
isBotAuthor,
isAdministrator,
canUseAdminCommands,
requireAdminAccess,
denyAdminAccess
requireAdminAccess
};