From 545f9fd75a5a3b2935ab3893f641ba46466f309e Mon Sep 17 00:00:00 2001 From: Behzad Rabiei Date: Sat, 25 May 2024 17:36:17 +0400 Subject: [PATCH 1/4] add script to delete commands --- package.json | 5 +++-- src/scripts/deleteRnDAOGuildCommands.ts | 30 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/scripts/deleteRnDAOGuildCommands.ts diff --git a/package.json b/package.json index d3e2b1f2..b4a85bc5 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "migrate:create": "migrate create --template-file ./src/migrations/utils/template.ts --migrations-dir=\"./src/migrations/db\"", "migrate:up": "migrate --migrations-dir=\"./lib/migrations/db\" up", "migrate:down": "migrate --migrations-dir=\"./lib/migrations/db\" down", - "cleanupCompletedJobs": "node ./lib/scripts/cleanupCompletedJobs.js" + "cleanupCompletedJobs": "node ./lib/scripts/cleanupCompletedJobs.js", + "deleteRnDAOGuildCommands": "node ./lib/scripts/deleteRnDAOGuildCommands.js" }, "repository": { "type": "git", @@ -80,4 +81,4 @@ "files": [ "lib/**/*" ] -} +} \ No newline at end of file diff --git a/src/scripts/deleteRnDAOGuildCommands.ts b/src/scripts/deleteRnDAOGuildCommands.ts new file mode 100644 index 00000000..f4b86342 --- /dev/null +++ b/src/scripts/deleteRnDAOGuildCommands.ts @@ -0,0 +1,30 @@ +import 'dotenv/config'; +import { REST, Routes } from 'discord.js'; +import parentLogger from '../config/logger'; +import config from '../config'; +const logger = parentLogger.child({ module: `deleteRnDAOGuildCommands` }); + +/** + * Delete RnDAO guild commands + */ +async function deleteRnDAOGuildCommands(): Promise { + try { + const rest = new REST().setToken(config.discord.botToken); + const guildCommands: any = await rest.get( + // RnDAO:915914985140531240 + Routes.applicationGuildCommands(config.discord.clientId, '915914985140531240') + ); + guildCommands.forEach(async (command: any) => { + await rest.delete( + Routes.applicationGuildCommand(config.discord.clientId, '915914985140531240', command.id) + ); + }); + } catch (error) { + console.log(error) + logger.error('Failed to delete RnDAO guild commands', error); + } +} + +deleteRnDAOGuildCommands().catch((error) => { + logger.error('Unhandled exception in deleting RnDAO guild commands', error); +}); From cf58d09587efacc1fd898252f1808a3fcf9921d8 Mon Sep 17 00:00:00 2001 From: Behzad Rabiei Date: Sat, 25 May 2024 17:36:32 +0400 Subject: [PATCH 2/4] remove no needed code --- src/services/command.service.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/services/command.service.ts b/src/services/command.service.ts index 24807dbe..92195cc4 100644 --- a/src/services/command.service.ts +++ b/src/services/command.service.ts @@ -34,8 +34,6 @@ async function registerCommand(): Promise { const rest = new REST().setToken(config.discord.botToken); const commandData = [...client.commands.values()].map((command) => command.data.toJSON()); await rest.put( - // RnDAO: 915914985140531240 - // Routes.applicationGuildCommands(config.discord.clientId, '915914985140531240'), Routes.applicationCommands(config.discord.clientId), { body: commandData }, ); From 9bfd3387ffd1defbc0336abf0d88c0f82ce2b133 Mon Sep 17 00:00:00 2001 From: Behzad Rabiei Date: Sat, 25 May 2024 17:37:47 +0400 Subject: [PATCH 3/4] make question command public in RnDAO --- src/commands/info/question.ts | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/commands/info/question.ts b/src/commands/info/question.ts index 5564439a..14ba4503 100644 --- a/src/commands/info/question.ts +++ b/src/commands/info/question.ts @@ -41,22 +41,6 @@ export default { }, }); } - // RnDAO:915914985140531240 TogetherCrew-Leads: 983364577096003604 TogetherCrew-Contributors: 983364691692748832 - if ( - interaction.guildId === '915914985140531240' && - !( - interaction.member?.roles.cache.has('983364577096003604') || - interaction.member?.roles.cache.has('983364691692748832') - ) - ) { - return await interactionService.createInteractionResponse(interaction, { - type: 4, - data: { - content: 'You do not have the required role to use this command!', - flags: 64, - }, - }); - } const serializedInteraction = interactionService.constructSerializableInteraction(interaction); const processedInteraction = handleBigInts(serializedInteraction); const cleanInteraction = removeCircularReferences(processedInteraction); // Pass processedInteraction here From 3607e6c324a5f1f37a69cbfc6ceb147d87e178cd Mon Sep 17 00:00:00 2001 From: Behzad Rabiei Date: Sat, 25 May 2024 17:38:02 +0400 Subject: [PATCH 4/4] format the code --- src/scripts/deleteRnDAOGuildCommands.ts | 30 ++++++++++++------------- src/services/command.service.ts | 5 +---- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/scripts/deleteRnDAOGuildCommands.ts b/src/scripts/deleteRnDAOGuildCommands.ts index f4b86342..a0c5ce73 100644 --- a/src/scripts/deleteRnDAOGuildCommands.ts +++ b/src/scripts/deleteRnDAOGuildCommands.ts @@ -8,23 +8,21 @@ const logger = parentLogger.child({ module: `deleteRnDAOGuildCommands` }); * Delete RnDAO guild commands */ async function deleteRnDAOGuildCommands(): Promise { - try { - const rest = new REST().setToken(config.discord.botToken); - const guildCommands: any = await rest.get( - // RnDAO:915914985140531240 - Routes.applicationGuildCommands(config.discord.clientId, '915914985140531240') - ); - guildCommands.forEach(async (command: any) => { - await rest.delete( - Routes.applicationGuildCommand(config.discord.clientId, '915914985140531240', command.id) - ); - }); - } catch (error) { - console.log(error) - logger.error('Failed to delete RnDAO guild commands', error); - } + try { + const rest = new REST().setToken(config.discord.botToken); + const guildCommands: any = await rest.get( + // RnDAO:915914985140531240 + Routes.applicationGuildCommands(config.discord.clientId, '915914985140531240'), + ); + guildCommands.forEach(async (command: any) => { + await rest.delete(Routes.applicationGuildCommand(config.discord.clientId, '915914985140531240', command.id)); + }); + } catch (error) { + console.log(error); + logger.error('Failed to delete RnDAO guild commands', error); + } } deleteRnDAOGuildCommands().catch((error) => { - logger.error('Unhandled exception in deleting RnDAO guild commands', error); + logger.error('Unhandled exception in deleting RnDAO guild commands', error); }); diff --git a/src/services/command.service.ts b/src/services/command.service.ts index 92195cc4..d717fb5e 100644 --- a/src/services/command.service.ts +++ b/src/services/command.service.ts @@ -33,10 +33,7 @@ async function registerCommand(): Promise { const client = await coreService.DiscordBotManager.getClient(); const rest = new REST().setToken(config.discord.botToken); const commandData = [...client.commands.values()].map((command) => command.data.toJSON()); - await rest.put( - Routes.applicationCommands(config.discord.clientId), - { body: commandData }, - ); + await rest.put(Routes.applicationCommands(config.discord.clientId), { body: commandData }); logger.info('Commands Registerd'); } catch (err) { logger.error({ err }, 'Failed to register the slash command');