From e45f055493926198210b2df54115d137e5f0bf8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sun, 21 Jan 2024 18:43:07 -0600 Subject: [PATCH] feat: permissions command --- docs/guide/permissions.md | 7 ----- src/commands/about.ts | 2 -- src/commands/permissions.ts | 42 +++++++++++++++++++++++++++ src/events/interactionCreate/index.ts | 2 ++ 4 files changed, 44 insertions(+), 9 deletions(-) delete mode 100644 docs/guide/permissions.md create mode 100644 src/commands/permissions.ts diff --git a/docs/guide/permissions.md b/docs/guide/permissions.md deleted file mode 100644 index 5a21542e3..000000000 --- a/docs/guide/permissions.md +++ /dev/null @@ -1,7 +0,0 @@ -# Permissions - -The following Discord permissions are required by the bot to ensure full functionality: - -- Manage nicknames -- Read messages / view channels -- Attach files diff --git a/src/commands/about.ts b/src/commands/about.ts index 94b60fbf0..fd97d6ed7 100644 --- a/src/commands/about.ts +++ b/src/commands/about.ts @@ -6,7 +6,6 @@ import { COMMANDS_RAW, CommandRegistry } from '../events/interactionCreate'; const RAW_PATH = `https://raw.githubusercontent.com/tresabhi/blitzkrieg/main/docs/`; const DOCS = { - permissions: 'guide/permissions', embeds: 'guide/embeds', introduction: 'guide/introduction', invite: 'guide/invite', @@ -14,7 +13,6 @@ const DOCS = { creators: 'guide/creators', }; const DOC_DESCRIPTIONS: Record = { - permissions: 'The permissions needed for the bot to function', embeds: 'How embeds work', introduction: 'About the bot', invite: 'How to invite the bot', diff --git a/src/commands/permissions.ts b/src/commands/permissions.ts new file mode 100644 index 000000000..b8f29f563 --- /dev/null +++ b/src/commands/permissions.ts @@ -0,0 +1,42 @@ +import { SlashCommandBuilder } from 'discord.js'; +import { CommandRegistry } from '../events/interactionCreate'; + +export const permissionsCommand: CommandRegistry = { + inProduction: true, + inPublic: true, + + command: new SlashCommandBuilder() + .setName('permissions') + .setDescription('Checks wether the bot has the required permissions'), + + async handler(interaction) { + // friday the 13th permissions easter egg + const isFridayThe13th = + new Date().getDay() === 5 && new Date().getDate() === 13; + const permissions = [ + [ + interaction.appPermissions?.has('ViewChannel'), + 'View channels: needed for the refresh button to work', + ], + [ + interaction.appPermissions?.has('ReadMessageHistory'), + 'Read message history: also needed for the refresh button to work', + ], + [ + interaction.appPermissions?.has('AttachFiles'), + 'Attach files: needed for image-based commands to work', + ], + ]; + const body = permissions + .map(([hasPermission, description]) => { + if (hasPermission) { + return `${isFridayThe13th ? '😇' : '✅'} ${description}`; + } else { + return `${isFridayThe13th ? '💀' : '❌'} ${description}`; + } + }) + .join('\n'); + + return `# Permissions\n${body}`; + }, +}; diff --git a/src/events/interactionCreate/index.ts b/src/events/interactionCreate/index.ts index 3e7393199..390055141 100644 --- a/src/events/interactionCreate/index.ts +++ b/src/events/interactionCreate/index.ts @@ -23,6 +23,7 @@ import { fullStatsCommand } from '../../commands/fullStats'; import { inactiveCommand } from '../../commands/inactive'; import { verifyCommand } from '../../commands/link'; import { ownedTanksCommand } from '../../commands/ownedTanks'; +import { permissionsCommand } from '../../commands/permissions'; import { pingCommand } from '../../commands/ping'; import { playerAchievementsCommand } from '../../commands/playerAchievements'; import { playerInfoCommand } from '../../commands/playerInfo'; @@ -90,6 +91,7 @@ export type CommandRegistry = const rest = new REST().setToken(secrets.DISCORD_TOKEN); export const COMMANDS_RAW: CommandRegistry[] = [ + permissionsCommand, debugCommand, eligibleCommand, aboutCommand,